gradMTT

Purpose

Computes numerical gradient using available threads.

Format

g = gradMTT(&fct, par1, data1)
Parameters:
  • &fct (scalar) – pointer to procedure returning either Nx1 vector or 1x1 scalar.
  • par1 (struct) – structure of type PV containing parameter vector at which gradient is to be evaluated
  • data1 (struct) – structure of type DS containing any data needed by fct
Returns:

g (NxK or 1xK) – Jacobian or gradient.

Examples

// Declare PV structure to store parameters
struct PV p1;
p1 = pvCreate;
p1 = pvPack(p1, 0.1|0.2, "P");

// Declare DS structure to store data
struct DS d0;
d0 = dsCreate;
d0.dataMatrix = seqa(1, 1, 15);

// Write function
proc fct(struct PV p0, struct DS d0);

   local p,y;
   p = pvUnpack(p0, "P");
   y = p[1] * exp(-p[2] * d0.dataMatrix);

   retp(y);
endp;

g = gradMT(&fct, p1, d0);

Remarks

par1 must be created using the pvPack() procedures

Source

gradmtt.src