jacobian method
Calculate a numeric jacobian of the parameters. Jt•J is the approximation of the hessian
Implementation
List<List<double>> jacobian(List<double> params) {
int ncols = params.length;
List<List<double>> fjac = numeric.createMatrix(xvals.length, ncols, 0);
List<double> modParamsHigh, modParamsLow;
double h,
// fjac = [],
left,
right;
for (int i = 0; i < ncols; i++) {
modParamsLow = params.sublist(0);
modParamsHigh = params.sublist(0);
// modParamsLow = params.slice(0);
// modParamsHigh = params.slice(0);
//Scale the step to the magnitude of the paramter
h = (params[i] * epsilon).abs();
if (h < 1.0e-25) h = epsilon;
modParamsLow[i] = params[i] - h;
modParamsHigh[i] = params[i] + h;
for (int j = 0; j < xvals.length; j++) {
left = model(xvals[j], modParamsHigh);
right = model(xvals[j], modParamsLow);
fjac[j][i] = ((left - right) / (2 * h)) / weights[j];
}
}
//update the number of times jac has been calculated
numJac++;
return fjac;
}