Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

7. Nonlinear Least Squares

A least-squares problem minimizes half the squared residual norm:

$$ f(x)=\tfrac12\|r(x)\|_2^2,\qquad r:\mathbb R^n\to\mathbb R^m. $$

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

$$ J^\top J\,d=-J^\top r. $$

Levenberg–Marquardt adds damping:

$$ \bigl(J^\top J+\mu I\bigr)d=-J^\top r. $$

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

$$ \mu=\max(\|r\|_2,10^{-12}), $$

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

$$ \min_z\left\| \begin{bmatrix}JD^{-1}\\ \sqrt{\mu}\,I\end{bmatrix}z- \begin{bmatrix}-r\\ 0\end{bmatrix} \right\|_2, \qquad d=D^{-1}z. $$

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

$$ \mu\leftarrow \mu\cdot\max\!\left(\tfrac13,\ 1-(2\rho-1)^3\right), $$

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

$$ \|D^{-1}J^\top r\|_2 $$

in Solution::gradient_norm, with the test

$$ \|D^{-1}J^\top r\|_2\le\tau_g. $$

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.objective and evaluations.residuals;
  • each Jacobian call counts in evaluations.jacobian and evaluations.gradient;
  • the objective budget max_evaluations covers 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

$$ y=b_1\bigl(1-e^{-b_2 x}\bigr). $$

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

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.