Gradient descent
You will learn
How gradient descent walks down a loss, what momentum adds, and why too large a rate never settles.
Training is walking downhill on the loss. Gradient descent moves a weight by -lr times its gradient each step; in the spec the loss is (x - 3)^2 from x = 0, and lr 0.1 reaches 2.99996 in 50 steps. Momentum adds a share of the last move, which speeds up a long slope and overshoots a sharp bottom: at 0.9 the weight shoots past 3 to about 5.13 and rings down to 3.09 after 50 steps. Nesterov takes the gradient one step ahead and swings less, to about 4.25. Too large a rate never settles: at lr 1 the weight bounces between 0 and 6 for good. The spec sgd.t27 computes every step.