Optimizers: gradient, momentum, Adam
Three optimizers start from the same point on a two-variable surface. Compare their trajectories over the level curves: zigzag, momentum, adaptive step.
English interface, partly translated: navigation, lab, projects, series, about and contact are; the home page sections, the site search and the content itself (articles, tutorials, research) are still in French.
Pick a function, a starting point and a learning rate, then watch the point walk downhill: convergence, oscillations, divergence, local minima.
Computation of the iteration k = 0
| k | xk | f(xk) | f′(xk) |
|---|---|---|---|
| 0 | 2.5 | 6.25 | 5 |
| 1 | 2 | 4 | 4 |
| 2 | 1.6 | 2.56 | 3.2 |
| 3 | 1.28 | 1.6384 | 2.56 |
| 4 | 1.024 | 1.048576 | 2.048 |
| 5 | 0.8192 | 0.671089 | 1.6384 |
| 6 | 0.65536 | 0.429497 | 1.31072 |
| 7 | 0.524288 | 0.274878 | 1.048576 |
| 8 | 0.41943 | 0.175922 | 0.838861 |
| 9 | 0.335544 | 0.11259 | 0.671089 |
| 10 | 0.268435 | 0.072058 | 0.536871 |
| 11 | 0.214748 | 0.046117 | 0.429497 |
| 12 | 0.171799 | 0.029515 | 0.343597 |
| 13 | 0.137439 | 0.018889 | 0.274878 |
| 14 | 0.109951 | 0.012089 | 0.219902 |
| 15 | 0.087961 | 0.007737 | 0.175922 |
| 16 | 0.070369 | 0.004952 | 0.140737 |
| 17 | 0.056295 | 0.003169 | 0.11259 |
| 18 | 0.045036 | 0.002028 | 0.090072 |
| 19 | 0.036029 | 0.001298 | 0.072058 |
| 20 | 0.028823 | 0.000831 | 0.057646 |
| 21 | 0.023058 | 0.000532 | 0.046117 |
| 22 | 0.018447 | 0.00034 | 0.036893 |
| 23 | 0.014757 | 0.000218 | 0.029515 |
| 24 | 0.011806 | 0.000139 | 0.023612 |
| 25 | 0.009445 | 8.92·10^−5 | 0.018889 |
| 26 | 0.007556 | 5.71·10^−5 | 0.015112 |
| 27 | 0.006045 | 3.65·10^−5 | 0.012089 |
| 28 | 0.004836 | 2.34·10^−5 | 0.009671 |
| 29 | 0.003869 | 1.5·10^−5 | 0.007737 |
| 30 | 0.003095 | 9.58·10^−6 | 0.00619 |
| 31 | 0.002476 | 6.13·10^−6 | 0.004952 |
| 32 | 0.001981 | 3.92·10^−6 | 0.003961 |
| 33 | 0.001585 | 2.51·10^−6 | 0.003169 |
| 34 | 0.001268 | 1.61·10^−6 | 0.002535 |
| 35 | 0.001014 | 1.03·10^−6 | 0.002028 |
| 36 | 0.000811 | 6.58·10^−7 | 0.001623 |
| 37 | 0.000649 | 4.21·10^−7 | 0.001298 |
| 38 | 0.000519 | 2.7·10^−7 | 0.001038 |
| 39 | 0.000415 | 1.73·10^−7 | 0.000831 |
| 40 | 0.000332 | 1.1·10^−7 | 0.000665 |
Gradient descent looks for a minimum of a function by repeating one simple move: measure the slope, then take a step in the downhill direction.
In a neural network, becomes the vector of all weights and the loss function, but the rule is the same, applied to every coordinate.
Take , whose derivative is . The update becomes:
At each iteration, is multiplied by the same factor . The whole behaviour can be read from that factor:
| Rate | Factor | Behaviour |
|---|---|---|
| steady convergence, from one side | ||
| minimum reached in a single step | ||
| damped oscillations around the minimum | ||
| perpetual oscillation, no progress | ||
| divergence: each step moves away |
More generally, for a function of curvature (here ), descent is stable as long as . That is why the same rate can suit one function and make another diverge.
"Plain" descent is sensitive to curvature: in a narrow valley, it zigzags. Variants with momentum and Adam fix this by remembering past slopes; they are compared in the optimizers demo.
Three optimizers start from the same point on a two-variable surface. Compare their trajectories over the level curves: zigzag, momentum, adaptive step.
Assign, update, assign… Follow the centroids until convergence, and discover where K-Means goes wrong: bad start, stretched clusters, rings.
Move the points and watch the least squares line follow. Then learn the same line by gradient descent and compare.