← All Labs
IDEA #25 · MACHINE LEARNING / OPTIMISATION

Gradient Descent — Skiing a Loss Landscape

Training a model is a ball rolling downhill. The loss is a surface over the parameters; the gradient is the direction of steepest ascent, so we step the opposite way. Pick a landscape — a gentle bowl, a rugged field of local minima, or the notorious Rosenbrock banana — then drop a skier and tune its learning rate and momentum. Too timid and it crawls; too greedy and it rockets uphill and diverges. Watch it stall on saddles, get trapped in the wrong valley, or find the floor.

01

Drive it

A real gradient computed each step — the skier only ever knows the local slope.
DRIVE IT
position (x,y)
loss f(x,y)
‖gradient‖
iteration 0
Drag to orbit. Shift-click the surface to drop the skier somewhere new, then press Run.
Bowl
Rugged
Rosenbrock
LEARNING RATE η0.080
MOMENTUM β0.00
status
idle
loss
‖∇f‖
step length
nearest min
02

Walkthrough

Five things to try.
WALKTHROUGH
1
Start on the Bowl with a small η. The skier glides smoothly to the single minimum and the ‖∇f‖ readout falls to zero — that is convergence.
2
Now crank η up. Past a critical value the steps overshoot the valley, the skier bounces higher each time, and the status flips to diverging. Bigger is not better.
3
Switch to Rugged and drop the skier (shift-click) in different spots. Plain descent falls into whatever local minimum is nearest — the answer depends on where you started.
4
Add momentum (β ≈ 0.9). The skier now carries velocity, coasts through shallow dips and saddles, and can escape a poor local minimum a plain step would have been trapped in.
5
Try Rosenbrock. Getting into the curved valley is easy; crawling along its nearly-flat floor to the true minimum at (1,1) is agony — turn on ghost racers to compare learning rates side by side.
03

Aha

The one sentence to keep.
AHA
THE INSIGHT
Training a model is nothing more than a ball rolling downhill on a surface you never get to see whole — and the size of each step is the difference between reaching the bottom, stalling forever, or flying off into the sky.
04

Explanation

What the skier is actually solving.
EXPLANATION

A model has parameters $\theta$ and a loss $L(\theta)$ measuring how wrong it is. Plotting $L$ over two parameters gives the surface you see — the loss landscape. Learning means finding the $\theta$ where $L$ is smallest.

The gradient $\nabla L$ is the vector of partial derivatives; it points in the direction of steepest ascent. To go down, step against it. That is the entire algorithm — gradient descent: $$\theta_{t+1} = \theta_t - \eta\,\nabla L(\theta_t).$$

The learning rate $\eta$ scales each step. For a quadratic bowl with curvature (Hessian eigenvalues) up to $\lambda_{\max}$, descent converges only if $$0 < \eta < \tfrac{2}{\lambda_{\max}}.$$ Below that it homes in; above it, each step overshoots and the loss explodes. The skier here diverges for exactly this reason.

Momentum gives the skier inertia. Instead of stepping straight along the gradient, it accumulates a velocity: $$v_{t+1}=\beta v_t-\eta\nabla L,\quad \theta_{t+1}=\theta_t+v_{t+1}.$$ With $\beta\approx0.9$ it coasts across flat spots and saddle points (where $\nabla L=0$ but it is not a minimum) that would freeze plain descent, and it damps the zig-zag in narrow, ill-conditioned valleys like Rosenbrock.

Local minima and saddles. A non-convex landscape has many valleys. Descent is greedy — it finds the nearest one, not the deepest. This is why the starting point matters, why momentum helps, and why in practice we use stochastic, noisy gradients that can rattle a skier out of a shallow trap.

Real networks live in millions of dimensions, but the picture is the same: read the local slope, take a step, repeat. Everything else — Adam, learning-rate schedules, batch noise — is a smarter way to choose that step.

05

Research note

Provenance — what is genuinely computed.
RESEARCH NOTE
The three landscapes and their exact gradients (used every step — nothing is faked):
Bowl (ill-conditioned): $f=\tfrac12(0.35x^2+1.7y^2)$
Rugged: $f=0.10(x^2+y^2)-\cos(1.6x)\cos(1.6y)$
Rosenbrock: $f=(1-x)^2+5\,(y-x^2)^2$
The mesh height, the vertex colours (a contour ramp), the ball's position and the gradient arrow are all evaluated from these formulae and their analytic derivatives at ~6400 grid points. The convergence bound $\eta<2/\lambda_{\max}$ is verified numerically in verify.js.
Read further. Cauchy (1847) first proposed the method. Polyak (1964) added the momentum ("heavy ball") term. Nesterov's accelerated gradient (1983) and Adam (Kingma & Ba, 2015) refine step selection. Rosenbrock's function (1960) is the standard torture test for optimisers.
Convergence for a quadratic $\tfrac12\theta^\top H\theta$ needs $\eta<2/\lambda_{\max}(H)$; the optimal rate depends on the condition number $\kappa=\lambda_{\max}/\lambda_{\min}$ — the anisotropic bowl and Rosenbrock make $\kappa$ large on purpose, which is exactly what momentum is designed to fight.
Single self-contained page · Three.js + KaTeX · idea #25 from the repo's visual-maths teaching list.