CLsqFit:SetNumCoefs
The SetNumCoefs method specifies the number of coefficients and independent variables used in the fit.
CLsqFit:SetNumCoefs( nCoefs ) CLsqFit:SetNumCoefs( tblCoefs ) LsqFit:SetNumCoefs( nCoefs, nDimensions ) |
nCoefs is the number of coefficients in a 1-dimensional fit or the number of terms in a hyperplane fit. For the hyperplane, this equals the number of dimensions plus 1 for the constant term.
tblCoefs is a 1-dimensional array containing the number of coefficients in each dimension. The number of table elements determines the dimension of the fit.
nDimensions is used only for the case of a user-defined basis function. In this case, the number of coefficients can be allocated over any number of dimensions.
This method set the number of coefficients and dimensions (independent variables) in the fit. ThenCoefs and tableCoefs parameters specify both the number of dimensions and the number of coefficients in each dimension. If some of the coefficients are forced to a fixed value (see the ForceCoef method), this function includes those forced coefficients. For example, the fit may start out with nCoefs = 10 but 3 would be forced, leaving 7 coefficients actually fit.
the basis function fits a line to (x,y) data, then the function uses 2 coefficients and you would useSetNumCoefs( 2 ). If you were to force the slope coefficient to 1.0 and fit only the intercept then, since the basis function still is defined to use 2 coefficients, you still would useSetNumCoefs( 2 ). Alternatively, you could modify the basis function to fit only the intercept coefficient and then you would use SetNumCoefs( 1 ).
This method configures the CLsqFit object to work with the number of dimensions and coefficients used by the basis function. Three types of basis function are provided: n-dimensional polynomial, hyperplane, and user-supplied function. THe interpretation of the nChan of tblChan parameter depends on the basis function being fit:
If nCoefs is a number, then a 1-dimensional polyomial is assumed. The value of nCoefs gives the number of coefficients. If the polynomial has more than 1 dimension, pass the number of coefficients for each dimension as a table using thetblCoefs argument. For example, SetNumCoefs({2,3}) passes a 2 element table which fits 2 coefficients in x and 3 coefficients in y, and determines that the fit involves 2 dimensions.
The value of nCoefs determines the number of dimensions in the fit. The value of nCoefs is 1 greater than the fit dimension to allow for the constant term. For example, to fit 3 variables, such as x, y, z, use SetNumCoefs( 4 ).
The coefficients can be allocated over any number of dimensions. For example, 7 coefficients could be fit to 3 dimensions. The basis vector determines how the coefficients are assigned. See the topic Basis Functions.
The following script calls SetNumCoefs with nCoefs = 3 to fit a 1-dimensional polynomial of 3 terms. A polynomial is the default unless SetBasisFunc is called to change it.
|
-- create a CLsqFit object |
|
-- set 3 coef for a 2nd order polynomial fit |
|
-- add a point for x = 3.5, y = 5 |
|
-- add a point |
|
-- add a point |
|
-- Fit the 2nd order curve |
The following script fits a 2-dimensional polynomial with 5 coefficients in dimension 1 and 3 coefficients in dimension 2. The total number of coefficients is 15. This uses the tblCoefs parameter to specify the number of coefficnets in each dimension.
|
-- create a CLsqFit object |
|
-- set 5 coefs in dimension 1 and 3 coefs in dimension 2 |
|
-- add a point for x = 3.5, y = 5.15, value = 15 |
-- add more points to the fit |
|
|
-- Fit the 5x3 polynomial |
The following script fits a hyperplane of 4 variables. Here, SetNumCoefs passesnCoefs=5 to fit 4 dimensions plus the constant term.
|
-- create a CLsqFit object |
|
-- specify basis function number 2, the Hyperplane. |
|
-- set 5 coefficients to fit 4 dimensions + constant |
|
-- add a point with 4 dimensions and value 12.5 |
-- add more points to the fit |
|
|
-- Fit the basis function |
The script below fits 5 coefficients to 3 dimensions using a user-defined basis function declared in your script. This uses SetNumCoefs(5,3). Assuming these 3 dimensions are x, y, and z, then the function being fit is f = a[1] + a[2] x + a[3] xy + a[4] z + a[5] z^2. This example is also used in the Basis Functions topic:
|
-- create a CLsqFit object |
|
-- specify the basis function "MyBasisFunc" |
|
-- fit 5 coefficients in 3 dimensions |
|
|
-- add some data points |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- define the basis function |
|
|
-- receives n=5 and V[] with 3 elements |
|
-- declare b as local inside the function |
|
-- the constant term a[1] |
|
-- the x term for a[2] |
|
-- the xy term for a[3] |
|
-- the z term for a[4] |
|
-- the z^2 term for a[5] |
|
-- return the basis vector |
|
|
|
|
|
-- fit the basis function |
CLsqFit class, GetNumCoefs , Using Multiple Independent Variables, Basis Functions, SetBasisFunc , GetBasisDim
Mira Pro x64 Script User's Guide, Copyright Ⓒ 2023 Mirametrics,
Inc. All Rights Reserved.