Phase I — Mathematical Foundations | Week 1 | 2.5 hours The Hessian is the curvature map. Newton’s method uses it to jump straight to the bottom of the bowl.
Every Gauss-Newton and Levenberg-Marquardt step in SLAM approximates the Hessian via $J^T J$. The quality of this approximation determines convergence speed. Taylor expansion is how we linearize nonlinear sensor models.
For $f: \mathbb{R}^n \to \mathbb{R}$:
Symmetry: If second derivatives are continuous (Schwarz’s theorem), $H = H^T$.
This is a quadratic model of $f$ around $x$. It’s exact for quadratic functions, and a good approximation nearby for smooth functions.
Minimizing the quadratic model with respect to $\delta$:
This is Newton’s step — the theoretical foundation of most second-order optimization methods.
| Function | Hessian |
|---|---|
| $f(x) = a^T x + c$ | $H = 0$ |
| $f(x) = x^T A x$ | $H = A + A^T$ (= $2A$ if symmetric) |
| $f(x) = \|Ax - b\|^2$ | $H = 2A^T A$ (always PSD!) |
Key insight for NLS: The Hessian of a least-squares cost $\sum r_i(x)^2$ has the form $H \approx 2J^T J$ (Gauss-Newton approximation), which ignores second-order residual terms. This works well when residuals are small.
Compute analytically, then verify numerically.
Implement via finite differences of the gradient.
Evaluate Hessian at critical points — PD means minimum, indefinite means saddle.
Plot actual function vs quadratic approximation at several points.
Show the Newton step jumping toward the minimum on a contour plot.
# See: code/week01/hessians_taylor.py
Compute Hessians by hand and classify the critical point:
Problem: For $f(x) = \sum_i r_i(x)^2$, show that $H = 2(J^T J + \sum_i r_i \nabla^2 r_i)$ where $J$ is the Jacobian of residuals. Why is $H \approx 2J^T J$ a good approximation?
Solution: Differentiating: $\nabla f = 2J^T r$, $H = 2(J^T J + \sum_i r_i H_i)$. The Gauss-Newton approximation drops $\sum_i r_i H_i$ because: (1) at the solution, residuals $r_i$ are small (good fit), so these terms are small; (2) $J^T J$ is always PSD, so the approximate Hessian is always PSD, ensuring descent. This is why GN is so effective for well-fitting models.
Problem: Apply Newton’s method to $f(x) = x^4$ starting at $x_0 = 1$. What happens?
Solution: $f'(x) = 4x^3$, $f''(x) = 12x^2$. Newton step: $\delta = -f'/f'' = -4x^3/(12x^2) = -x/3$. So $x_{k+1} = x_k - x_k/3 = 2x_k/3$. The method converges, but only linearly (rate 2/3), not quadratically! This is because the Hessian vanishes at the minimum ($f''(0) = 0$), so the quadratic model becomes degenerate. Newton converges quadratically only when the Hessian at the minimum is nonsingular.
Problem: Derive the optimal step size $h$ for computing the Hessian via finite differences of the gradient, considering both truncation and rounding error.
Solution: The Hessian approximation $H_{ij} \approx [\nabla_j f(x + h e_i) - \nabla_j f(x - h e_i)] / 2h$ has truncation error $O(h^2)$ and rounding error $O(\epsilon/h^2)$ (where $\epsilon \sim 10^{-16}$). Balancing: $h^2 \sim \epsilon/h^2$ gives $h \sim \epsilon^{1/4} \approx 10^{-4}$ for float64.