Forcing Coefficient Values


Sometimes the value of a fit coefficient is known ahead of the fit or you want to assign it a value to see how the other coefficients are affected. To assign a value, you would "force" the coefficient to a specific value. This action removes it from consideration by the fit. This is not the same as defining a basis function that ignores the coefficient altogether but is more like defining the basis function and "hard-wiring" the value of the coefficient. In the jargon of least squares estimation, forcing a coefficient removes it from being a "free parameter" of the fit.

As an example of forcing a coefficient, consider finding the slope of a sample of (x,y) pairs for determining the coefficient of correlation between them. Since a scatter plot of correlated variables would show a line, it might be assumed that the slope can be determined by fitting a line to the data. Actually, this is the wrong thing to do because you know a-priori that the correlation must go through the origin at (0,0). If you fit the line y = a[1] + a[2] x to the correlation data, then the a[1] coefficient (the constant, or intercept of the line) will be a free parameter of the fit and will generally have a nonzero value. Remember that the least squares method estimates coefficient values that minimize the scatter of the observed data about the target function, but it does not concern itself with whether the solution is logically correct or sensible. Therefore, allowing the freedom to dump some of the variance into the a[1] coefficient gives an incorrect value for the slope a[2]. To get the right solution, you have 2 options: 1) create a basis function that fits only 1 coefficient, which is the slope, or 2) fit a line having 2 coefficients and force the a[1] coefficient to a value of 0.

The CLsqFit class provides 4 methods to help with forcing coefficients:

ForceCoef

Forces a coefficient to a specified value and does not estimate it in the fit.

UnforceCoef

Restores a coefficient for being fit.

IsCoefForced

Returns the state of a coefficient (estimated or forced).

ResetForcedCoefs

Resets all forced coefficients so they all will be estimated by the fit.

Forcing a coefficient value simply involves using the ForceCoef method to set a value for the n-th coefficient. For example, in the above example involving correlation, the line intercept uses coefficient index 1, so you would force it to the value 0 by calling ForceCoef(1,0). Since the CLsqFit class can handle multi-channel data as from RGB images, you also may force coefficients only for specific channels. This is done by adding a 3rd parameter to ForceCoef. For example, to set coefficient index 3 to value 4.5 only for channel 2, use ForceCoef(3,4.5,2). As typical for the CLsqFit class, when fitting multi-channel data you can set the same value to all channels by omitting the 3rd parameter that specifies the channel.

Related Topics

CLsqFit class, ForceCoef, Basis Functions


Mira Pro x64 Script User's Guide, Copyright Ⓒ 2024 Mirametrics, Inc. All Rights Reserved.