Finding the minimum of a function when no formula gives it: golden-section search in one variable, gradient descent and the learning rate, Newton's method with curvature, and Gauss–Newton for nonlinear least squares. This is how machine-learning models are trained.
Ten students: hours of study and result (1 = pass, 0 = fail). Predict the probability of passing with a model , where .
| hours | result |
|---|---|
| 0.5, 1.0, 1.5 | 0, 0, 0 |
| 2.0, 2.5 | 1, 0 |
| 3.0, 3.5 | 1, 0 |
| 4.0, 4.5, 5.0 | 1, 1, 1 |
| , = ? | boundary = ? |
Root finding (bisection, Newton, Lectures 6–10); iteration and convergence (Lecture 14); Euler stability (Lectures 21–22); least squares (Lectures 23–24).
Minimise any smooth function by iteration: bracket it, walk downhill, or use curvature.
input f, a, b, tol
g ← (√5 − 1)/2
c ← b − g(b − a); d ← a + g(b − a)
while b − a > tol:
if f(c) < f(d):
b ← d; d ← c
c ← b − g(b − a)
else:
a ← c; c ← d
d ← a + g(b − a)
return (a + b)/2Store and so that each step costs one evaluation.
input ∇f, x0, η, tol, kmax
x ← x0; v ← 0
for k = 1 … kmax:
g ← ∇f(x)
if ‖g‖ < tol: stop
v ← β·v − η·g # β = 0: plain GD
x ← x + v
return xMachine learning: from a random mini-batch of data = stochastic gradient descent.
| step | loss | ||
|---|---|---|---|
| 0 | 0 | 0 | 0.6931 |
| 1 | 0.2375 | 0 | 0.6458 |
| 10 | 0.3493 | −0.5260 | 0.5802 |
| 100 | 1.0211 | −2.6795 | 0.4450 |
| 1000 | 1.3533 | −3.7214 | 0.4335 |
Gradient descent: cheap steps, many of them. Newton: 5 expensive steps.
is a huge system of nonlinear equations with many solutions; nobody writes it down. Stochastic gradient descent (with momentum: Adam) takes millions of small steps, each using the gradient of a small batch of data computed by backpropagation.
Rule of thumb: few variables and smooth: Newton or quasi-Newton; many variables or huge data: (stochastic) gradient descent with a tuned learning rate.
| Method | Uses | Convergence | Cost per step ( variables) | Problem 1/2 result |
|---|---|---|---|---|
| Golden section | only | linear, ×0.618 | 1 evaluation | 22 steps to |
| Newton (1-D) | , | quadratic | 2 derivative values | 4 steps to |
| Gradient descent | linear, set by condition number | 153 steps (bowl, ) | ||
| GD + momentum | faster linear | 41 steps | ||
| Newton (-D) | , | quadratic | solve | 1 step (quadratic ) |
| Gauss–Newton | residuals, | near quadratic (small residuals) | 2–5 steps (bacteria) |
The trade-off is the same as in root finding (Lecture 10): cheap, slow, robust steps against expensive, fast, fragile ones.
Training in 16-bit precision; loss of significance in softmax; why log-sum-exp is used
Newton and quasi-Newton optimisers; solving
Least squares, Cholesky in Gaussian processes, conditioning of features
Splines for features and learning-rate schedules; Runge = overfitting
Gradient checking with finite differences; expectations by quadrature
Gradient descent = Euler; learning-rate limit = stability; neural ODEs
Every method in this course has a bigger sibling. These are the natural next steps.
Click a card to see optimisation at work.
Where exactly: every deep-learning framework (PyTorch, TensorFlow). The loss surface is like the contour map below, in millions of dimensions; optimisers walk downhill along gradients computed by backpropagation.
Momentum () on Rosenbrock's valley. Adam, the default optimiser, adds a per-parameter learning rate.
Where exactly: model selection. The validation error as a function of the ridge parameter usually has one dip; golden-section search finds it with few (expensive) training runs.
Each evaluation of is one full training run, so needing only one new value per step matters.
Where exactly: email filters, credit scoring, medical risk scores. The probability of "spam" is , where counts words; is trained exactly as in Problem 3, with thousands of features.
The same model forms the last layer of most neural-network classifiers.
Where exactly: phone panoramas, AR apps, photogrammetry. Unknown camera positions and 3-D points are adjusted so that predicted image positions match the observed ones ("bundle adjustment").
Least squares + Newton + linear systems: three modules of this course in one algorithm.
Gradient descent finds , : . A student needs about 2.75 hours of study for a 50% chance of passing, and 73% after 3.5 hours.
Machine learning, optimisation, numerical PDEs and numerical linear algebra all build on these 25 lectures. Keep the labs: every method here is a few lines of code you can now read, check and trust.