Contents
02Gradient descent: walk downhill
2.1The update rule
Picture standing on a foggy hillside: you cannot see the valley, but you can feel which way the ground slopes under your feet. The sensible plan is to take a small step in the steepest downhill direction, feel the slope again, and repeat. Gradient descent does exactly this on the loss surface J(\theta):
The gradient \nabla J(\theta_t) points in the direction in which the loss rises fastest, so we step the opposite way. The learning rate \eta sets how far. Each step needs only the gradient at the current point, which backpropagation computes for any neural network at about the cost of one forward pass.
2.2Why the gradient is the steepest direction
Theorem 1 (Steepest descent). Among all small steps \Delta of a fixed length \epsilon, the one that decreases J the most, to first order, is \Delta^*=-\epsilon\,\nabla J(\theta)/\|\nabla J(\theta)\|.
By Taylor’s theorem, for a small step J(\theta+\Delta)\approx J(\theta)+\nabla J(\theta)^{\top}\Delta, so the change in loss is the dot product \nabla J(\theta)^{\top}\Delta. By the Cauchy–Schwarz inequality, \nabla J(\theta)^{\top}\Delta\ge-\|\nabla J(\theta)\|\,\|\Delta\|=-\epsilon\|\nabla J(\theta)\|, with equality exactly when \Delta points opposite to \nabla J(\theta).
“Steepest” is local: the gradient points straight downhill here, not toward the minimum. In a long, narrow valley it points mostly across the valley, which is why gradient descent zigzags (Section 7). And the first-order argument needs small steps; how small is the subject of the next section.
2.3The running example
All three methods will be compared on one problem, the same one as in the video: a linear regression with n=1{,}000 points, x_i uniform on [1,5], and y_i=2x_i+1+\varepsilon_i with noise \varepsilon_i\sim\mathcal N(0,0.5^2). The model is \hat y=wx+b, so \theta=(w,b), and the loss on one example is \ell_i=\frac12(wx_i+b-y_i)^2. Its gradient is
the residual times the input. The least-squares solution is \theta^*=(2.003,\,1.005) with J^*=0.1261; every run starts at \theta_0=(-0.5,\,5.5), where J=8.75, with learning rate \eta=0.05. All numbers in this tutorial were computed for this tutorial with the same data and seeds as the companion video.
Pause and think. In (3), what does the gradient of one example do when that example is predicted perfectly?
Show the answer
It is zero: r_i=0, so a correctly predicted example asks for no change. Examples with large residuals pull hardest, in the direction of their input (x_i,1).