Gradient Descent on a Loss Surface

Training a model means rolling downhill on a loss surface — repeatedly stepping against the gradient toward lower error. Drag the start point, tune the learning rate and momentum, and watch the optimizer either settle into a basin or shake itself apart.

iter 0 loss — ‖∇‖ — paused
drag the marker • or focus the canvas and use arrow keys
0.063

Step size, log scale 0.001 → 1.0. Push it high to make descent overshoot and diverge.

0.00

Fraction of the previous step carried forward (0 → 0.99). Builds velocity through flat regions and shallow ridges.

What's happening

The colored field is a loss surface L(x, y) — here a mix of Gaussian wells and a ridge, so it is decidedly non-convex: there are several basins, and where you start decides which one you fall into. Dark valleys are low loss; bright ridges are high.

At every iteration we compute the gradient ∇L analytically — the direction of steepest increase — and move the opposite way: v ← μ·v − η·∇L, then p ← p + v. The learning rate η scales the step; momentum μ lets velocity accumulate, smoothing the path and powering it over small bumps.

Set η sensibly and the marker glides into the nearest valley and stops. Set it too large and each step overshoots the minimum, so the path oscillates and explodes outward — the optimizer diverges. Adding momentum reshapes the trajectory: it overshoots and corrects like a ball with inertia rather than tracing the gradient exactly.