gradMTTm#
Purpose#
Computes numerical gradient with mask using threads.
Format#
- g = gradMTTm(&fct, par1, data1, mask)#
- 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 evaluateddata1 (struct) – structure of type
DS
containing any data needed by fctmask (Kx1 matrix) – elements in g corresponding to elements of mask set to zero are not computed otherwise are computed.
- 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;
mask = { 0, 1 };
// Find gradient
g = gradMTTm(&fct, p1, d0, mask);
Remarks#
par1 must be created using the pvPack()
procedures
Source#
gradmtt.src