This site is version 0.0.1. Most of the code on this site is drafted by an agent and needs review. I apologize for the AI-speak, we are working on rewriting it!
viv-lang.org

Notebooks · lib/minpack/lmder

MINPACK's lmder, Levenberg-Marquardt least squares with a trust region

A port of lmder.f and lmder1.f from netlib MINPACK (lib/minpack/ref), with the Fortran's arithmetic in the Fortran's order, so that the iterates match a gfortran build of the original to the last bit where the problem's own functions do. The explanation is in lib/minpack/lmder.intent; the checks are in lib/minpack/mgh_check.viv and lib/minpack/check.sh.

The function. fcn(data, x, fvec, fjac, iflag) is a def: for iflag 1 it writes the m residuals at x into fvec, for 2 the m x n Jacobian into fjac, for 0 it may print; it returns iflag, or a negative number to stop lmder. data is any array the function needs (a problem number, measurements).

Differences from the Fortran, none of which changes an operation:

  • indices count from 0, and ipvt holds 0-based column numbers;
  • fjac is an m x n array instead of a leading-dimension array;
  • the work arrays wa1 ... wa4 are allocated here instead of passed in;
  • info is returned, and nfev and njev are written into counts[0] and counts[1];
  • every trial step writes one row into hist (the Fortran has no such record; it is what lets a test compare iterates, and a plot draw them). The columns are the H_ constants below. A hist with fewer rows than trial steps keeps the first rows; pass zeros(1, H_X + n) to keep none worth reading.

Used with import minpack.lmder.

Look inside this program

  • Atlas

    The program’s map: every function and which calls which.

  • There’s no recorded run of this program yet.

Shift+Enter in a cell runs it and moves to the next. Running a cell runs every cell above it too, as one program.

[1]lines 32–534