CalculusLesson 3 of 6
Use slopes to find minima
Stationary points and gradient descent
The prediction describes the change for a small step to the right:
- : goes up. Rising.
- : goes down. Falling.
- : nothing happens, to first order. Flat.
The size says how fast. A slope of 6 turns a step of into a rise of about .
Candidates for maxima and minima
Section titled “Candidates for maxima and minima”Suppose has a smooth peak at , and suppose the slope there were positive. Then a tiny step right would go higher. So it wasn’t a peak. Suppose the slope were negative. A tiny step left would go higher. Same problem. At an interior differentiable peak, the slope must be zero. The same reasoning applies to an interior valley.
For a differentiable function, an interior maximum or minimum must satisfy . These points are candidates: you must also check boundaries and any points where the derivative does not exist. For example, find the lowest point of .
Completing the square proves the global minimum: , with equality at . Checking two nearby points alone would not prove a minimum.
A zero derivative does not guarantee a maximum or minimum: has derivative 0 at the origin but keeps increasing through it. A local minimum also need not be the lowest point across the whole domain.
The slope of the slope
Section titled “The slope of the slope”If is differentiable, its derivative , “f double prime”, measures how quickly the slope changes. If is position, is velocity and is acceleration.
At a flat spot, tells hill from valley:
- : the slope is increasing, from negative through zero to positive. Falling, then rising. A valley.
- : rising, then falling. A hilltop.
- : no verdict.
For , everywhere. One bowl, and is its bottom.
Walk downhill
Section titled “Walk downhill”Solving gives the minimum directly. For a neural network, solving all the corresponding equations is usually impractical. We can instead use the current derivative to choose a direction: a positive slope points downhill to the left, and a negative slope points downhill to the right.
(“eta”) is the learning rate: it scales the derivative to determine the step. The approximation predicts a decrease when the derivative is nonzero and the step is sufficiently small. Repeating this can approach a local minimum; the result depends on the function, starting point, and learning rate. Here are the first steps from on , using :
| step | next | ||
|---|---|---|---|
| 0 | 5 | 6 | 4.4 |
| 1 | 4.4 | 4.8 | 3.92 |
| 2 | 3.92 | 3.84 | 3.536 |
| 3 | 3.536 | 3.072 | 3.229 |
Heading to 2, in shrinking steps. This is gradient descent in one dimension.
Go deeper: how big a step?
A downhill direction does not make every step downhill. On from , lands at , at the same height as the starting point; lands higher. For a quadratic with constant curvature , fixed steps converge to its minimum when . Other functions need their own checks: curvature may change along the step. This is why the learning rate matters.
A position function gives velocity when differentiated. The next lesson uses a rate over an interval to calculate an accumulated change.