| Description | The input data X, Y (and InvVar) are used to evaluate the parameters ai of a general linear function,
y = a0f0(x) + a1f1(x) + a2f2(x)...
The parameters ai are returned in the vector A.
Arguments:
| A | vector of size npars; returns the coefficients |
| Covar | matrix of dimensions [npars, npars]; returns the covariances of the coefficients |
| AStatus | vector of size npars; decides which parameters are treated as free or as fixed |
| npars | total number of parameters |
| X, Y, InvVar | vectors of size sizex, holding the input data |
| funcs | user-defined model function |
Your model function may actually contain more parameters than you wish to treat as adjustable. This is why you have to provide the vector AStatus, which contains the necessary information about which parameters are to be held fixed at their input values (AStatus[i] = 0) and which are free (AStatus[i] = 1). Any fixed parameters must be initialized in A prior to calling VF_linfit. npars denotes the total number of parameters in A (not only the free parameters!).
The model function funcs must calculate the individual fi(x) for any argument x and store the fi(x) in a vector BasFuncs of size npars. In C/C++, it has to be defined as
void MyFunc( fVector BasFuncs, float x, unsigned nfuncs)
{
BasFuncs[0] = f0( x );
BasFuncs[1] = f1( x);
. . .
}
and shall be passed to VF_linfit by calling
VF_linfit( A, AStatus, npars, X, Y, sizex, MyFunc );
In Pascal/Delphi, the model function has to be defined as
procedure MyFunc( BasFuncs:fVector; x:Single; nfuncs:UInt );
begin
VF_Pelement( BasFuncs, 0 )^ := f0( x );
VF_Pelement( BasFuncs, 1 )^ := f1( x );
. . .
end;
and shall be passed to VF_linfit by calling
VF_linfit( A, AStatus, npars, X, Y, sizex, @MyFunc );
Note the address-of operator in front of "MyFunc.". In Turbo Pascal, the model function must be compiled with the Force-Far-Calls option {$F+}.
The functions f0( x ) etc. must not contain the parameters ai.
In the weighted variant, VF_linfitwW, the vector InvVar has to contain the inverse of the variances of the individual X-Y data points, and the matrix Covar will be filled with the covariances of the parameters ai on output: MCovari,j = covariance( ai, aj ). Internally, VF_linfit employs a Singular Value Decomposition algorithm to obtain a solution even for (near-)singular linear systems. Thereby, coefficients ai whose significance is lower than a threshold, Thresh, are
set to 0 instead of infinity. This threshold can be modified by calling VF_setLinfitNeglect. The current threshold can be retrieved by VF_getLinfitNeglect.
|