TMultiDeriveProc Event

MulticastDelegateTMultiDeriveProc

type TMultiDeriveProc = procedure(const RegressFun: TMultiRegressFun; const X: TVecList; const Y: TVec; const Pars: TVec;const Grad: TVecList);

Defines derivatives of a function.

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.

Examples

delphi
// 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;