Defines derivatives of a function.
TMultiDeriveProc = procedure (const RegressFun: TMultiRegressFun; const X: TVecList; const Y: TVec; const Pars: TVec;const Grad: TVecList);
The type describes the procedure for calculating the derivatives of a regression function TMultiRegressFun with respect to the regression parameters (B array), evaluated at (X,Y). The function accepts all pairs of (x,y) values at which the function is to be evaluted allowing for vectorized (up to 20x faster) computation. Each independent variable X is stored as a separate vector in the list x. The result is returned in to the parameter Grad. The "const" modifier of "Grad" applies to the pointer and not to the contents of object.
An example of regression function and it's derivatives with respect to regression parameters:
// y=b0*x*x + b1*x + b2 function SimpleParabola(const B: TVec; const X: TVecList; const y: TVec): double; begin // SimpleParabola := b[0]*Sqr(x) + b[1]*x + b[2]; y.Sqr(x[0]); y.Scale(b[0]); //y = b[0]*sqr(x) y.AddScaled(x[0], b[1]); //y = y + x*b[1]; y.Add(b[2]); end; // grad _b function procedure SimpleParabolaDeriv(RegressFun: TMultiRegressFun; const X: TVecList; const Y: TVec; const Pars: TVec; const Grad: TVecList); begin Grad[0].Sqr(x[0]); // Grad[0] := Sqr(x); Grad[1].Copy(x[0]); // Grad[1] := x; Grad[2].Size(x[0]); Grad[2].SetVal(1); //Grad[2] := 1; end;
void __fastcall SimplexParabolaDeriv(TMultiRegresFun* RegressFun, TVecList * const x, TVec * const y, TVec* const Pars, TVecList* const Grad); { Grad[0]->Sqr(x[0]); // Grad->Values[0] = x*x; Grad[1]->Copy(x[0]); // Grad->Values[1] = x; Grad[2]->Size(x[0]); Grad[2]->SetVal(1); // Grad->Values[2] = 1.0; }
Copyright (c) 1999-2024 by Dew Research. All rights reserved.
|
What do you think about this topic? Send feedback!
|