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-2025 by Dew Research. All rights reserved.
|