ContentsThe library

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 ff from Rn\mathbb{R}^n to R\mathbb{R}, a point xx, and

a direction uu with ∥u∥=1\|u\| = 1. Step a small distance ε\varepsilon along

uu and ask what happens to ff.

FIG 1A step in any direction, to first order
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
Every question about which way to move becomes a question about one dot product, because the second-order term vanishes faster than the first as the step shrinks.

Divide by ε\varepsilon and let it shrink. What is left is the rate of change

of ff per unit distance travelled along uu, and it equals ∇f(x)⋅u\nabla f(x) \cdot u

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

nn 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 uu, and the only thing uu affects is one dot product.

The two-line proof

Write the dot product with the angle in it. For any two vectors,

∇f⋅u=∥∇f∥ ∥u∥cos⁡θ\nabla f \cdot u = \|\nabla f\| \, \|u\| \cos\theta, and since uu is a unit

vector this is just ∥∇f∥cos⁡θ\|\nabla f\| \cos\theta.

So the rate of change along uu is the gradient's length times the cosine of the

angle between uu and the gradient. The gradient's length is not something you

control; it is whatever the function is doing at xx. The cosine is entirely

yours.

FIG 2Every direction you could choose, laid out
-1.50-0.750.000.751.500.01.63.14.76.3angle between the step and the gradient, in radians
rate of change along the direction
The choice of direction is a choice of angle, and the payoff is a cosine. Directions at right angles to the gradient change nothing at all to first order, which is why contour lines exist.

The cosine is smallest at θ=π\theta = \pi, where it equals −1-1. That is the

direction exactly opposite the gradient. So the largest possible decrease per

unit step is ∥∇f∥\|\nabla f\|, achieved by

u=−∇f/∥∇f∥u = -\nabla f / \|\nabla f\|, and by no other direction.

The same statement without the angle, which is the version that generalises:

FIG 3The bound and its equality case
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
This is the Cauchy-Schwarz inequality. The useful half is not the bound but the condition for equality, which holds only when the two vectors are parallel. That is what makes the steepest direction unique rather than merely one of the good ones.

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 ∥u∥=1\|u\| = 1 means.

It does not say. The proof assumed the ordinary Euclidean length,

∥u∥2=∑iui2\|u\|^2 = \sum_i u_i^2, 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 uu 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 PP, so

that a unit step means u⊤Pu=1u^\top P u = 1. Running the same argument gives a

different answer: the steepest direction becomes proportional to

−P−1∇f-P^{-1} \nabla f. 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 PP to be

the Hessian and you get Newton's method. Choose PP 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 f(x,y)=12(x2+100y2)f(x, y) = \tfrac{1}{2}\left(x^2 + 100 y^2\right), whose minimum

sits at the origin. Its contours are ellipses stretched ten to one.

FIG 4Two contours of a stretched bowl
-1.0-0.50.00.51.0-0.10-0.050.000.050.10a point where the two directions disagreexy
f = 0.5f = 0.125
The marked point sits at roughly (0.71, 0.071). The minimum is at the centre, almost due left. The negative gradient there is proportional to (0.71, 7.07), which is almost straight down.

At that marked point the gradient is (x,100y)=(0.71,7.07)(x, 100y) = (0.71, 7.07). The direction

that would take you straight to the minimum is −(0.71,0.071)-(0.71, 0.071). 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 ff 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

NextWhere the Gradient Comes From →

The rest of this course

  1. 01Why the Steepest Direction Is the Negative Gradientyou are here
  2. 02Why the Gradient Is Computed Backwardsopening only
  3. 03The Largest Step a Curvature Will Tolerateopening only
  4. 04One Ratio Decides How Long Training Takesopening only
  5. 05What Momentum Multiplies Your Step Size Byopening only
  6. 06The Gradient You Use Is Always the Wrong Oneopening only
  7. 07Dividing by the Size of Your Own Gradientsopening only
  8. 08The Variance That Keeps a Deep Network Aliveopening only

Read alongside