Nugget: gradient descent
Captured ahead of reading. This is a nugget — an application sketched before reaching the chapter, the kind of thing a student scribbles down on hearing about it. It has not been checked against §7.1 yet, and the numbers come from
scripts/explore_nugget_gradient_descent.py, not from the book. Treat it as a pointer, not as verified notes.
The nugget
When you cannot solve for the answer in one algebraic move, you can still walk towards it. Stand somewhere on the loss surface, look at the slope under your feet, take a step downhill, and repeat. That is gradient descent.
The reason this matters for machine learning is not that it is elegant — it is that it is the only thing that scales. A linear system can be solved directly, but a model with millions of parameters and noisy data has no closed form, and the “answer” does not exist anyway: there is no exact intersection to find, only a valley to descend into.
The whole idea fits in one update rule:
where is the learning rate — how big a step to take.
In practice
Every practical training loop is this rule wearing different clothes. What changes is how the step size is chosen, because a fixed is fragile:
- Too small — correct but agonisingly slow; you run out of patience or budget before you arrive.
- Too large — the iterates overshoot and diverge; the loss grows instead of falls.
- Just right (but only locally) — fast near the start, then it stalls in flat regions or rattles around a narrow valley.
That is why real systems use learning-rate schedules, momentum, and adaptive methods (AdaGrad, RMSProp, Adam) rather than one number. It is also why the loss surface’s shape matters more than its minimum: an elongated valley forces a small step size in the steep direction while the shallow direction would allow a large one.
The same machinery answers the question the book asks later about local minima: a ball rolling downhill stops in the first dip it reaches, which need not be the lowest point in the landscape.
Worked example
Take a 2-D quadratic with a known minimum, so the iterates can be compared against ground truth:
The exact minimum is with . The curvature (eigenvalues of ) is and , so stability requires
Starting from :
| after 25 steps, distance to | outcome | |
|---|---|---|
| correct but still en route — far too slow | ||
| converged | ||
| (8 steps) | diverged |
At the residual falls from to essentially zero in 25 steps. At the loss rises from to in eight steps. The rule never changes; only the step size does.
All numbers above are produced by scripts/explore_nugget_gradient_descent.py.
References
- Deisenroth, Faisal & Ong, Mathematics for Machine Learning, §7.1 “Optimization Using Gradient Descent” (material to read; not yet checked). See References for the full citation and link.
- Reproducibility script:
scripts/explore_nugget_gradient_descent.py. - Related notes: 2.3 Solving Systems of Linear Equations for the exact case this replaces.