CLsqFit:ForceCoef
The ForceCoef method specifies the value of a specific coefficient. This removes the coefficient from the fit and adjusts the results accordingly. Use this, for example, if fitting a line and you want the slope to have a specific value such as 1.0. To remove a term from the fit, like the xy cross-term in a multidimensional polynomial fit, set its value to 0.0. Note that the forced coefficient is still included in the fit results but uses its assigned value and shows an uncertainty of zero.
CLsqFit:ForceCoef( nIndex, nValue ) CLsqFit:ForceCoef( nIndex, nValue, nChannel ) |
nIndex is the index of the coefficient in the set of coefficients of the fit. This is a 1-based number.
nValue is the target value of the coefficient.
nChannel is an optional parameter that specifies the target channel when fitting multi-channel data.
This method forced a coefficient to a specified value. The forced coefficient still is included in the total count of fit coefficients set using the SetNumCoefs method. For example, if you use SetNumCoefs( 3 ) fo a 1-dimensional fit, then call ForceCoef( 2, 1.0 ), the result will be that coefficient [2] is set to the value 1.0 and removed from the set of "free parameters" being fit. The fit still uses 3 parameters but parameter index 2 is discarded from those being fit. The basis function remains unchanged when you force coefficients.
If you are doing a complex fitting procedure and do not remember which coefficients were forced, use the IsCoefForced method to determine if a particular coefficient was forced. To remove dorcing and return a coefficient to being a free parameter of the fit, use UnforceCoef. To fit all coefficients after some were forced, you can remove all forced coeffieicnts in one step using ResetForcedCoefs.
The example below illustrates forcing a coefficient in a 2x2 coefficient polynomial fit. After computing the fit, the xy cross term between x and y is removed by setting it to 0, leaving a fit to an inclined plane rather than a warped plane.
|
-- create the least squares fitting object |
|
|
-- fit a polynomial with 2 coefs each in 2 dimensions |
|
|
-- add an (x,y) point |
|
|
-- add more points... |
|
|
|
|
|
|
|
|
|
|
|
-- do a 2x2 fit to 4 coefficients |
|
-- save the results for comparison |
|
|
|
-- find the coef index in the 2x2 polynomial fit matrix |
|
|
-- force the cross term at 2,2 to 0. |
|
|
-- re-do the fit with no cross term. |
|
CLsqFit class, UnforceCoef, IsCoefForced, ResetForcedCoefs, GetPolyCoefIndex
Mira Pro x64 Script User's Guide, Copyright Ⓒ 2023 Mirametrics,
Inc. All Rights Reserved.