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.
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.