📐Least Squares and Data Fitting
Nonlinear Least Squares
Gauss–Newton, the damped step, Levenberg–Marquardt, GNSS point positioning and residual analysis
Philadelphia 1944, Wilmington 1963
Frankford Arsenal, Philadelphia, in the middle of the war. Kenneth Levenberg, a mathematician at the Army's arsenal, faces models whose parameters enter nonlinearly. The standard method — linearise, solve the linear least-squares problem, repeat — often wanders off or diverges from a poor starting guess. In a five-page note in the Quarterly of Applied Mathematics, A Method for the Solution of Certain Non-Linear Problems in Least Squares, he suggests damping each step: penalise long steps, so that far from the answer the method creeps cautiously downhill and near the answer it takes full linearised steps.
The note is little read. Nineteen years later, Donald Marquardt, a statistician at the DuPont Company in Wilmington fitting kinetic models to chemical data, arrives at the same idea, adds a scaling that makes it work for parameters of very different sizes, and publishes it in the SIAM Journal in 1963. He distributes a FORTRAN program. It spreads through every laboratory that fits data.
Today the Levenberg–Marquardt algorithm is inside
scipy.optimize.curve_fit, inside camera calibration, bundle adjustment, orbit determination and the navigation filter in your phone.A model with parameters is fitted to data by minimising
When is nonlinear in — an unknown decay rate , an unknown frequency, a position inside a distance — is no longer a quadratic bowl. There is no formula; we iterate, and every iteration is a linear least-squares problem from the earlier lessons.
💡Gauss–Newton
Linearise the residuals about the current with the Jacobian :
Choose to minimise — a linear least-squares problem, solved by QR — and set . It is Newton's method (lesson 2-4) applied to the gradient of , with the second-derivative terms dropped. When the residuals at the solution are small, those terms are small too, and Gauss–Newton converges almost quadratically.
Derivation
Gauss–Newton is Newton with one term dropped
Newton's method for a minimum (lesson 2-4, applied to ) needs the gradient and the second-derivative matrix of . Since , its derivatives are minus those of , so . By the chain rule:
Newton's step solves :
The second-derivative sum is the expensive part, and it is multiplied by the residuals. Drop it, and what remains, , is exactly the normal equations of the linear problem — the Gauss–Newton step. When the model fits well the residuals are small, the dropped term is small, and the step is nearly Newton's. Only first derivatives are ever needed.
📐A cooling casting
A casting cools in air: , with ambient temperature , initial temperature and rate all unknown. Twelve noisy readings over 50 minutes. From a rough guess ( °C, °C, /min), Gauss–Newton's step sizes go , landing on °C, °C, /min — a time constant of 14.3 minutes — in agreement with
scipy.optimize.curve_fit.💡Levenberg–Marquardt
Far from the answer the linearisation is poor and a full Gauss–Newton step can overshoot or diverge. Levenberg's fix adds a damping term:
Large : a short step along the steepest-descent direction — slow but safe. Small : the Gauss–Newton step — fast near the answer. The algorithm adapts automatically: if a step reduces , accept it and decrease ; if not, reject it and increase . It is a trust-region method in disguise: controls how far we trust the linear model.
Derivation
Where the damped equations come from
Penalise long steps: minimise the linearised misfit plus a cost on the step itself,
Setting the gradient with respect to to zero (as in lesson 5-1) gives , which is
The two limits explain the behaviour. As it is the Gauss–Newton step. For large (with ) the term dominates and : a short step straight downhill. Marquardt's scales the penalty to each parameter's own sensitivity, so a decay rate of 0.07 per minute and a temperature of 380 °C are damped equally fairly.
📐A damped vibration
An accelerometer records a decaying oscillation ; fit , , , . Start with the frequency guessed 12% low. Plain Gauss–Newton fails at its second iteration: its step drives the damping ratio negative. Levenberg–Marquardt (
scipy.optimize.least_squares(method='lm')) converges in 10 function evaluations to , , Hz, . The residuals have mean and standard deviation — matching the 0.05 noise that was added, which is what a correct model should leave behind.the theory of probabilities is basically just common sense reduced to calculus
💡GNSS point positioning
A receiver measures pseudoranges to satellites at known positions :
with unknown position and receiver clock error (the cheap quartz clock in a receiver is off by milliseconds — hundreds of kilometres of range). Four unknowns, nonlinear in . The Jacobian rows are , where is the unit vector from the receiver to satellite : the geometry matrix .
Started at the centre of the Earth with zero clock error, Gauss–Newton on six satellites moves the estimate 7,674 km, then 1,253 km, 42 km, 48 m, then nothing: five iterations to a position 4.4 m from the truth with 3 m range noise. gives the dilution of precision: GDOP 2.8, PDOP 2.4 for this sky. Satellites bunched in one part of the sky make ill-conditioned and the DOP — the error amplification of lesson 3-2 — large.
Derivation
The geometry matrix and dilution of precision
The Jacobian row. The predicted pseudorange is . Differentiate the distance with respect to the receiver position: , so
Moving the receiver towards a satellite shortens that range one-for-one along the line of sight; the clock adds to every range equally. Row of the Jacobian is .
Dilution of precision. Near the solution each Gauss–Newton step is a linear least-squares problem with matrix . If every range has independent errors of standard deviation , lesson 5-1's covariance formula with gives
The diagonal holds the variances of the four estimates. Their total, divided by , is a pure number fixed by the geometry alone: , and PDOP is the same over the three position entries. A 3 m range error with PDOP 2.4 means about m of position uncertainty.
⚠Local minima and starting values
Nonlinear least-squares problems can have several local minima; LM finds one near where it starts. A frequency guessed 50% wrong may lock onto a harmonic. Use physics for starting values (here: count zero crossings for , read off the first peak), fit in stages (linear parameters first), or try several starts. For GNSS the problem is benign — almost any start converges — which is why receivers can start from the Earth's centre.
💡Where you will use this
GNSS Navigation: single-point positioning exactly as above; precise point positioning and RTK add carrier phases and more unknowns. Orbital Mechanics: orbit determination from range, Doppler and angle measurements — Gauss's Ceres problem, solved by batch Gauss–Newton. Attitude Determination and Camera calibration: star-tracker and camera models fitted by LM. Materials and Geotechnics: fitting creep laws, consolidation curves and constitutive models to laboratory tests.
📚Further reading
- Jorge Nocedal and Stephen Wright, Numerical Optimization (2nd ed., Springer, 2006), chapter 10, 'Least-Squares Problems' — Gauss–Newton and Levenberg–Marquardt as trust-region methods.
- Donald Marquardt, 'An algorithm for least-squares estimation of nonlinear parameters', Journal of the Society for Industrial and Applied Mathematics 11(2), 431–441 (1963).
- Pratap Misra and Per Enge, Global Positioning System: Signals, Measurements, and Performance (2nd ed., Ganga-Jamuna Press, 2006) — the pseudorange fix and dilution of precision as GNSS engineers use them.
↓But there is a problem
This unit was about solving for . Along the way we kept meeting special directions: the singular vectors, the columns of , the axes of the energy ellipse.
Some matrices have directions they do not rotate at all — they only stretch them. On 7 November 1940, the main span of the Tacoma Narrows Bridge, less than five months old, began to twist in a 64 km/h wind. Within an hour the deck had torn itself apart. The motion that destroyed it was one particular shape of vibration, at one particular frequency — an eigenvector and an eigenvalue of the bridge.