LensForge icon

Merit function

Optimization of lenses is usually done by defining a function called the merit function or defect function. The value of this function is a measure of how bad the lens is. The smaller the value, the better the lens.

The merit function is a function of the set of construction parameters x, so we write it M(x). It is calculated as half the sum of squares of quantities Ri(x), called residuals, as follows:

The values of the construction parameters that minimize the merit function are those that make the residuals as close to zero as possible, in the least-squares sense. This allows us to use the powerful Levenberg-Marquardt algorithm to efficiently minimize the merit function from a given starting point.

The object that calculates an individual residual we call a meritoid. The sum above is the sum over the residuals computed by the meritoids associated with the merit function. The residual Ri(x) of meritoid i is defined as the deviation of the meritoid's calculated value Vi(x) from its target value Ti, divided by its tolerance Δi:

The purpose of the tolerance parameter is to allow different meritoids to be weighted differently by giving them different tolerances. Also, using the equation above, the residual is always dimensionless because the value, target, and tolerance all have the same units.

For example, if we use a focal length meritoid with target T=50mm and tolerance Δ=0.1mm then if the focal length evaluates to V(x)=49mm then the deviation is -1mm and the residual is R(x)=-10.

Some meritoids generate a set of residuals. For example, when minimizing the spot size using the RMS Spot Size meritoid, the meritoid generates a residual (the ray deviation divided by the tolerance) for each traced ray. Having this set of residuals instead of a single spot size measurement allows the Levenberg-Marquardt algorithm to converge rapidly to the minimum spot size.

Inverting meritoids

Some quantities, like energy collection efficiency, one would generally want to maximize. Meritoids that handle these are "inverting meritoids". They contribute residuals of the form:

If the specified target is zero the second term is omitted, as if the target value was infinity. In this case the residual decreases as the value increases, so the effect of minimization will be to maximize the value.

See also