The Mathematics of Gradient Descent
Why the Steepest Direction Is the Negative Gradient
The claim that the gradient points the way downhill is a theorem with a proof and a hidden assumption. Both are worth having in full.
Every course on training says the gradient points uphill, so go the other way.
It is true, and it is one of the few claims in the subject with a two-line
proof. The proof is worth doing, not for rigour but because it exposes an
assumption that later optimisers spend their whole existence attacking.
What a direction is worth
Start with a function from to , a point , and
a direction with . Step a small distance along
and ask what happens to .
- the gradient, a vector of the n partial derivatives at x
- the direction of travel, a vector of length one
- how far to go, small enough that the discarded term is negligible
Divide by and let it shrink. What is left is the rate of change
of per unit distance travelled along , and it equals
and nothing else. This number has a name, the directional derivative, but the
name is less useful than the observation: a question about a curved surface in
dimensions has become a dot product between two vectors.
That reduction is the entire content of first-order optimisation. The gradient
is fixed once you have chosen where you are standing. The only thing left to
choose is , and the only thing affects is one dot product.
The two-line proof
Write the dot product with the angle in it. For any two vectors,
, and since is a unit
vector this is just .
So the rate of change along is the gradient's length times the cosine of the
angle between and the gradient. The gradient's length is not something you
control; it is whatever the function is doing at . The cosine is entirely
yours.
The cosine is smallest at , where it equals . That is the
direction exactly opposite the gradient. So the largest possible decrease per
unit step is , achieved by
, and by no other direction.
The same statement without the angle, which is the version that generalises:
- how much a unit step in the direction u can change the function
- the ceiling on that change. The second factor is one for a unit direction, so the ceiling is set by the gradient alone, and it is unreachable by any direction that is not parallel to it
Two lines, and the claim is settled. No direction beats the gradient's length,
and only one direction attains it.
The assumption nobody mentions
Read the derivation again and look for where it says what means.
It does not say. The proof assumed the ordinary Euclidean length,
, because that is what the dot product's angle formula
refers to. That was a choice, and it is a strange one to make without comment,
because the coordinates of are parameters of a model, and they are not
comparable quantities. One coordinate might be a weight in the first layer and
another a bias in the last. Declaring that a step of 0.01 in one is the same
size as a step of 0.01 in the other is a statement about units, not about the
function.
Suppose instead that length is measured by a positive definite matrix , so
that a unit step means . Running the same argument gives a
different answer: the steepest direction becomes proportional to
. The gradient is still what carries the information about
the function, but the matrix decides what counts as far.
This single loophole accounts for most of what comes later. Choose to be
the Hessian and you get Newton's method. Choose diagonal, built from a
running average of squared gradients, and you get something very close to Adam.
Neither is a different idea from steepest descent. Both are steepest descent
under a different ruler.
Downhill is not homeward
One more thing the derivation does not promise. It says the negative gradient
is the best direction for an infinitesimal step. It says nothing whatever about
the location of the minimum.
Take the bowl , whose minimum
sits at the origin. Its contours are ellipses stretched ten to one.
At that marked point the gradient is . The direction
that would take you straight to the minimum is . The angle
between the negative gradient and the straight line home is about 79 degrees.
The steepest direction is nearly perpendicular to the direction you actually
want.
Nothing has gone wrong. Both statements are true at once: no other direction
lowers faster over a short step, and the direction is nearly useless for
getting to the bottom. The disagreement grows with the stretch of the bowl, and
the lesson on conditioning turns that observation into a number that predicts
how many steps a run will take.
What to hold on to
The rate of change along a direction is a dot product. Cauchy-Schwarz caps that
dot product at the gradient's length and reaches the cap only along the
gradient itself. That is the theorem, and it is airtight.
The two soft spots are both in what it does not say. It does not say how to
measure a step, and the answer changes if you measure differently. And it is a
statement about an infinitesimal step, which is not a statement about where the
minimum is.
The next lesson leaves geometry aside and asks a mechanical question: given a
model with a hundred billion parameters, how is the gradient obtained at all,
and why does getting all hundred billion partial derivatives cost about the
same as evaluating the function once.
Recap
- The rate at which a function changes as you step along a direction is the gradient dotted with that direction, so choosing a step direction is choosing where to sit on a cosine curve.
- Cauchy and Schwarz supply the whole proof: the dot product of the gradient with any unit vector cannot beat the gradient's own length, and equality happens only for the direction that lies along it.
- Steepest means steepest per unit step, and what counts as a unit step is a choice. Change the way length is measured and the steepest direction moves, which is the loophole every adaptive optimiser exploits.
This is the reading half
Starting the course gives you your own copy of it. Every idea on every page has problems standing under it, marked with a reason rather than a tick, and any sentence you do not believe can be opened and argued with. None of that can happen on a page nobody owns.
The contents