Phase II — Unconstrained Optimization | Week 4 | 2.5 hours From GD’s zigzag to Nesterov’s optimal rate — the physics of convergence acceleration.
The AMR estimator’s Kalman filter is itself a form of momentum-based update — the state prediction carries forward information from previous steps. Understanding momentum methods explains why the estimator can track fast-moving robots without overshooting, and why tuning the process noise covariance $Q$ (which controls how much the estimator “trusts” its momentum) is critical for navigation stability.
Gradient descent on ill-conditioned problems zigzags:
With $\kappa = 100$: the gradient points “mostly sideways” relative to the optimal direction. GD takes ~230 steps for $10^{-2}$ reduction.
Add momentum from previous step:
Optimal parameters for quadratic $f(x) = \frac{1}{2}x^TAx$:
Rate: $O\left(\left(\frac{\sqrt{\kappa}-1}{\sqrt{\kappa}+1}\right)^k\right)$ vs GD’s $O\left(\left(\frac{\kappa-1}{\kappa+1}\right)^k\right)$.
For $\kappa = 100$: heavy ball factor = $0.818$ vs GD’s factor = $0.98$. Dramatically faster!
“Look ahead” before computing the gradient:
Rate for convex: $O(1/k^2)$ vs GD’s $O(1/k)$ — optimal for first-order methods.
Rate for strongly convex: $O\left(\left(\frac{\sqrt{\kappa}-1}{\sqrt{\kappa}+1}\right)^k\right)$ — matches lower bound.
The heavy ball method is a PD controller for optimization:
This is the same trade-off as PID tuning in robot control: - Too much P (too large $\alpha$): oscillations - Too much D (too large $\beta$): overshooting, instability - Optimal balance: critical damping
| Method | Strengths | Weaknesses |
|---|---|---|
| Heavy ball | Simple, fast on quadratics | Requires eigenvalue bounds, can oscillate |
| Nesterov | Optimal rate, adaptive | Slightly more complex, can overshoot on nonconvex |
| BFGS | Adapts to curvature | $O(n^2)$ memory |
When to use momentum: Problems with high $\kappa$ where second-order methods are too expensive ($n > 10^4$).
# See: code/week04/momentum_methods.py
Implement heavy ball with optimal parameters for quadratic.
Implement Nesterov with adaptive momentum parameter $\frac{k-1}{k+2}$.
Compare all three on an ill-conditioned quadratic ($\kappa = 1000$). Plot convergence.
Show heavy ball with $\beta$ too large causes oscillation/divergence.
Apply Nesterov to the nonconvex Rosenbrock function. Compare convergence curves with GD and heavy ball.
Problem: Implement the “optimal” method of Nesterov for strongly convex functions with known $\mu$ and $L$:
Compare its convergence to standard Nesterov on quadratics with $\kappa \in \{100, 1000, 10000\}$.
Solution: The strongly convex version uses a fixed momentum parameter $\frac{\sqrt{\kappa}-1}{\sqrt{\kappa}+1}$ instead of the adaptive $\frac{k-1}{k+2}$. This gives exponential convergence matching the lower bound. On $\kappa=10000$: ~200 iterations instead of GD’s ~10000.
Problem: For the 2D quadratic $f(x,y) = 50x^2 + y^2$ ($\kappa=100$), plot the full trajectory of GD, heavy ball, and Nesterov starting from $(1, 1)$. Annotate the zigzag pattern of GD and the spiral/damped pattern of momentum methods.
Solution: GD zigzags along the steep $x$-direction. Heavy ball with optimal $\beta$ spirals inward smoothly. With $\beta$ too large, heavy ball overshoots and spirals outward before recovering. Nesterov shows the characteristic “overshoot then correct” pattern — it briefly goes past the minimum then pulls back, which is actually optimal.
Problem: Nesterov can overshoot on nonconvex functions. Implement the “function restart” heuristic: if $f(x_{k+1}) > f(x_k)$, reset momentum to zero. Show this prevents oscillation on Rosenbrock while preserving acceleration on well-conditioned regions.
Solution: The restart heuristic detects when momentum causes the function value to increase. By resetting $x_{k-1} = x_k$ (zero momentum), the method falls back to GD for one step. On Rosenbrock’s narrow valley, this prevents the momentum from shooting across the valley. The restarted method typically converges in 2-3× fewer iterations than vanilla Nesterov on Rosenbrock.