1. A method of generating a weighting function for an optical sensor, the method comprising: inputting a first weighting function, which is based on a transformation of a reflectance perturbation from a reflectance space into a color space of the sensor; calculating the first weighting function with a plurality of predetermined stimuli to obtain a corresponding plurality of resulting functions; and averaging the resulting functions to obtain the weighting function for the sensor, wherein the reflectance perturbation is a perturbation of a reflectance vector of a stimulus in the reflectance space, and the first weighting function is based on (i) transforming the perturbation into the color space of the sensor, the transformed perturbation corresponding to a color difference between an unperturbed reflectance vector transformed into the color space and a perturbed reflectance vector transformed into the color space, and (ii) taking the limit of the transformed perturbation as the perturbation approaches zero.