Levenberg-Marquardt

Levenberg-Marquardt (LM) is the workhorse solver for nonlinear least-squares problems in SLAM. It is a damped version of Gauss-Newton that interpolates between Gauss-Newton (fast near the minimum) and gradient descent (safe far from it), making it much more robust to poor initialization.

From Gauss-Newton to LM

For a cost F(x)=12e(x)2F(\mathbf{x}) = \tfrac{1}{2}\|\mathbf{e}(\mathbf{x})\|^2, Gauss-Newton linearizes the residual e(xk+Δx)e(xk)+JkΔx\mathbf{e}(\mathbf{x}_k + \Delta\mathbf{x}) \approx \mathbf{e}(\mathbf{x}_k) + J_k \Delta\mathbf{x} and solves the normal equations

(JkTJk)Δx=JkTe(xk)(J_k^T J_k)\,\Delta\mathbf{x} = -J_k^T \mathbf{e}(\mathbf{x}_k)

This can diverge when the linearization is a bad approximation, or when JkTJkJ_k^T J_k is (nearly) singular. LM adds a damping term λI\lambda I:

(JkTJk+λI)Δx=JkTe(xk)(J_k^T J_k + \lambda I)\,\Delta\mathbf{x} = -J_k^T \mathbf{e}(\mathbf{x}_k)

where:

The two limits explain the behavior:

Marquardt’s refinement scales the damping by the curvature of each coordinate, replacing λI\lambda I with λdiag(JkTJk)\lambda\,\mathrm{diag}(J_k^T J_k), so that weakly constrained directions get damped more and the method becomes invariant to per-parameter rescaling.

Adapting the damping

λ\lambda is adjusted every iteration based on whether the step actually helped:

  1. Solve for Δx\Delta\mathbf{x} with the current λ\lambda.
  2. Evaluate the true cost at xk+Δx\mathbf{x}_k + \Delta\mathbf{x}.
  3. If the cost decreased: accept the step and decrease λ\lambda (trust the linearization more).
  4. If the cost increased: reject the step and increase λ\lambda (take a smaller, more gradient-like step), then re-solve.

A common refinement compares the actual cost reduction against the reduction predicted by the linearized model (the gain ratio): a ratio near 1 means the local quadratic model is trustworthy and λ\lambda can shrink aggressively; a small or negative ratio means the model is poor and λ\lambda must grow. This is exactly the logic of a trust-region method — LM can be read as implicitly maintaining a region around xk\mathbf{x}_k within which the linearization is trusted, with λ\lambda inversely related to the region’s radius.

Practical notes for SLAM problems

Why it matters for SLAM

Nearly every optimization in a modern SLAM pipeline — bundle adjustment, pose graph optimization, PnP refinement, camera calibration — is solved with LM. SLAM problems are highly nonlinear (projection, rotation manifolds) and initializations are often mediocre (motion-model predictions, noisy triangulations), so the pure Gauss-Newton step frequently overshoots. LM’s automatic damping is what makes these solvers converge reliably frame after frame without hand-tuning, which is why it has been the default in SLAM back-ends for decades.