1.6 Optimization
1. Learn
Section titled “1. Learn”- Mathematics for Machine Learning (Deisenroth, Faisal, Ong)§7.1 Optimization Using Gradient Descent (pp. 227–233), §7.3 Convex Optimization (pp. 236–246)
- Understanding Deep Learning (Prince)§6.1 Gradient descent and §6.3 Momentum (pp. 77–88)
- Gabriel Goh, Why Momentum Really Works (Distill)the first section, up to "First Steps: Gradient Descent" and its interactive figure
2. Bridge
Section titled “2. Bridge”Training a model means minimising a loss lossThe scalar we minimise; lower is better. Often an average over training examples.Introduced in 1.6 Optimization. over the parameters parametersAll learnable parameters of a model, collected into one vector.Introduced in 1.6 Optimization. UDL uses φ (phi) for model parameters; CS229 and most papers use θ.. Gradient descent repeats one step: , with learning rate learning rateStep size in gradient descent: θ ← θ − η ∇L(θ).Introduced in 1.6 Optimization. UDL and CS229 write α for the learning rate; MML calls it the step-size γ (§7.1). (MML §7.1; UDL §6.1). Everything interesting is in the choice of .
Near a minimum, almost every smooth loss looks like a quadratic bowl, and on a quadratic you can solve gradient descent exactly. The derivation below shows each eigen-direction of the curvature shrinking by per step. So gradient descent converges if and only if : the steepest direction sets the speed limit. The flattest direction then crawls at rate . The ratio , the condition number, decides how slow that is (Goh, Why Momentum Really Works). The step-size explorer lets you see each regime: creep, oscillate, bounce, diverge.
A convex function has no local minima other than global ones, so gradient descent with a small enough step finds the best answer (MML §7.3). Neural network losses are not convex: where you start and how big your steps are decide which valley you end in. Try the quartic in the widget.
Two fixes you implement here. Momentum keeps a running sum of past gradients, , and steps along . In a long narrow valley, the zig-zags cancel and progress along the valley adds up (UDL §6.3; Goh). Backtracking line search starts with a big step and shrinks it until the loss drops “enough” (the Armijo condition), so no single has to work everywhere (backtracking line search; MML §7.1.1 motivates adapting the step size). Module 3.3 adds Adam, which also scales each coordinate separately.
3. Explore
Section titled “3. Explore”Implement gradient descent and momentum (returning whole trajectories), the stability limit on the learning rate for a quadratic, backtracking line search, and the Rosenbrock gradient derived by hand. The last test runs your line search all the way down the Rosenbrock valley.
stubs/m1_6_optimization.pyLoading starter file…
Prefer your own editor? Edit exercises/stubs/m1_6_optimization.py and run mlc check 1.6. The tests are identical; import the results on the progress page.
Locally: mlc check 1.6.
5. Check
Section titled “5. Check”- not yet: All tests pass (0/?)
- not yet: Checkpoint quiz ≥ 80%
Learner log: time spent and points of confusion
Every confusion you note becomes a fix before the module is marked stable. Export it from the progress page and attach it to an issue.