Why momentum helps gradient descent
Sample Distill-style article: prose and maths around an explorable figure built with Distill's figure element and d3.
Gradient descent is the workhorse of machine learning, and it has a well-known weakness. On a long, narrow valley it bounces from wall to wall while creeping along the floor. Adding momentum, a running memory of past gradients, is a one-line change that often makes it several times faster. This article shows why, on the simplest valley there is.
A quadratic valley #
Take a bowl stretched along one axis,
Its gradient is
A step large enough to make progress along the shallow direction overshoots in
the steep one, and a step small enough for the steep one crawls along the
shallow one. The best fixed step,
Adding momentum #
Momentum keeps a velocity
Oscillations across the valley point in alternating directions and cancel in
What to try #
- Set
and raise until the path zig-zags, then diverges past . - Keep that
and raise : the zig-zag damps, and the path reaches the centre sooner. - Push
towards : too much memory and the path overshoots and circles.
Further reading #
This sample follows the style of Distill articles and borrows its example from Gabriel Goh’s Why Momentum Really Works, which analyses the same valley in far more depth.