7. Nonlinear Least Squares
A least-squares problem minimizes half the squared residual norm:
Each row of the Jacobian \(J(x)\in\mathbb R^{m\times n}\) corresponds to one residual. nlopt4r provides two Levenberg–Marquardt implementations: the legacy normal-equation method (levenberg_marquardt) and the adaptive QR method (levenberg_marquardt_with_options).
7.1 Gauss–Newton and LM damping
The Gauss–Newton step solves the normal equations
Levenberg–Marquardt adds damping:
Figure 7-1 Three directions from \(x_0=(2,1)\) on \(f(x)=\tfrac12(x_1^2+4x_2^2)\): the GN step reaches the unconstrained minimizer directly, while the LM steps for \(\mu=0.5\) and \(\mu=2\) shorten and rotate toward the negative gradient. Section 7.2 of the textbook tunes step length and direction with the damping parameter, and section 7.3 lists the lmm.m program.
The legacy implementation takes
solves the linear system with a dense factorization, and runs Armijo backtracking. This method targets medium-sized residual systems with moderate conditioning.
7.2 Adaptive column-scaled QR method
The adaptive method solves an augmented rectangular system in scaled coordinates. With \(D\) the diagonal of Jacobian column norms (unit entries for zero-norm columns) and \(z=Dd\), each step solves
Properties:
- Householder QR and triangular back-substitution solve the augmented matrix \(((m+n)\times n)\) directly;
- positive damping gives the augmented system full column rank, which yields steps for underdetermined and rank-deficient residual systems;
- each step computes \(D\) from all nonzero column norms, with unit entries for zero columns.
Damping follows Nielsen’s cubic rule. With \(\rho\) the ratio of actual to predicted decrease, an accepted step updates
bounded below by minimum_damping. A rejected step grows damping by \(2,4,8,\dots\), with at most max_damping_trials attempts per accepted point (default 40). Acceptance requires \(\rho>\tau_a\) together with a trial objective below the current value, default \(\tau_a=10^{-4}\).
7.3 Convergence test
The adaptive method reports the column-scaled stationarity quantity
in Solution::gradient_norm, with the test
This quantity is invariant under independent rescaling of variable units. A converged residual system satisfies \(J^\top r=0\); with a positive residual norm the objective equals the corresponding constant, and the fit rests at the smallest residual level.
7.4 Counts and recovery
- each residual call, including rejected trials and failed callbacks, counts in
evaluations.objectiveandevaluations.residuals; - each Jacobian call counts in
evaluations.jacobianandevaluations.gradient; - the objective budget
max_evaluationscovers residual calls; - the accepted residual is cached and reused in the convergence test.
7.5 NIST certified data
tests/nist.rs uses the 14 observations of NIST StRD Misra1a with the model
The published reference parameters are \(b_1=238.94212918\) and \(b_2=0.00055015643181\), with certified residual sum of squares \(0.12455138894\). The solver objective is half the residual sum of squares. The test uses two published starts \((500,0.0001)\) and \((250,0.0005)\); all data ship with the repository.
Software interface
- The
LeastSquarestrait, both LM entry points andLmOptions: see chapter 18. - Tuple adapters for residuals and Jacobians: see chapter 15.
- NIST test command: see chapter 22.
- API reference (docs.rs):
least_squares.
References
- 马昌凤, 最优化方法及其 Matlab 程序设计 (in Chinese), 2010, chapter 7.
- K. Levenberg, “A method for the solution of certain non-linear problems in least squares,” Quart. Appl. Math. 2 (1944), 164–168.
- D. W. Marquardt, “An algorithm for least-squares estimation of nonlinear parameters,” SIAM J. Appl. Math. 11 (1963), 431–441.
- K. Madsen, H. B. Nielsen, O. Tingleff, Methods for Non-Linear Least Squares Problems, 2nd ed., DTU, 2004.