Speak Maths Β· University
The gradient: which way is uphill
On a surface with many directions, the gradient is one arrow that tells you everything about the slope where you stand. Machine learning walks against it.
Draft: written by an AI helper and not yet checked by a teacher.
The alphabet
Read each sign aloud, the way it is written under it.
- Say: partial f by partial xMeans: how fast f changes when only x moves and everything else stays still
- Say: grad f (or βnabla fβ, βdel fβ)Means: an arrow pointing the steepest way uphill
- Say: grad f is the vector of partial f by partial x and partial f by partial yMeans: the gradient puts all the partial derivatives side by side
- Say: the norm of grad fMeans: the length of the arrow: how steep the steepest way is
- Say: the derivative of f in direction u is grad f dot uMeans: the slope if you walk in direction u (a unit vector)
- Say: f of x, y equals cMeans: a level set or contour: every point at the same height c
- Say: theta becomes theta minus eta times grad L of thetaMeans: one step of gradient descent: move a little in the downhill direction
The story: The hiker in the fog
Tap a line to see its words.
- The height of a valley side above its floor depends on where you stand: x metres east and y metres north.
- Fog comes down. The hiker is 3 metres east and 1 metre north of the floorβs lowest point, but cannot see it.
- Here the ground is 11 metres above the floor.
- Feeling with a boot: stepping east, the ground rises about 2x for each metre; stepping north, about 4y.
- So right here the steepest way up points 6 east and 4 north.
- The steepest way down is exactly the opposite arrow.
- The hiker takes a small step, one tenth of that arrow, and stands at 2.4 east and 0.6 north.
- The height has dropped from 11 to 6.48 metres.
- Step after step, the arrow shrinks, until at the lowest point there is no uphill left at all.
In words this story is 712 letters long; in symbols, 125.
Read it
What does it say?
Write it
Which notation says this?
The gradient of f is the vector of its two partial derivatives.
Update ΞΈ by a step against the gradient of the loss, of size Ξ· times the gradient.
Along a contour line, the height f stays the same number c.
The partial derivative of f with respect to y.
The steepest slope at the point p is 3.
The slope of f in the direction of the unit arrow u, written as a dot product.
The contour of the hill h at height 4.
The gradient of x squared plus y squared is the arrow (2x, 2y).
One step of gradient descent with learning rate 0.1.
The gradient is perpendicular to the contour line.
Walking in direction u, f climbs 2 units of height per unit of distance.
At the lowest point of the valley the gradient is the zero vector.
Build it
Tap the tiles in order. One tile does not belong.
The slope of f in direction u is the gradient of f dotted with u.
The next ΞΈ is this ΞΈ minus Ξ· times the gradient of the loss at this ΞΈ.
The gradient of f is the arrow (2x, 2y).
The norm of the gradient of f at p is 5.
A contour line: h of x, y equals c.
Partial f by partial x equals 2 x.
Challenges
Creative puzzles that use every sign of this chapter. Take your time; there is no clock.
1 The foggy hill, mapped
Here f(x, y) = xΒ² + yΒ². The grid shows which contour each point lies on. Judge each sentence: true or false?
| β | |||
| β | |||
| β | |||
A tick means the point of the row lies on the contour f(x, y) = c of the column.
The gradient (2x, 2y) points straight away from the origin and is perpendicular to the contour; walking along the contour, the slope is zero.
2 The slope dictionary
Six lines for ideas about slopes in two or more variables. Pair each with its meaning.
Tap a line, then its meaning.
Each sign answers a different question: slope along one axis, all slopes at once, the steepest slope, the slope along any direction, same-height points, and a step downhill.
3 Which way is down?
This should be one step of gradient descent, going downhill. One tile is wrong. Find it, then fix it.
Tap the tile that is wrong.
The gradient points uphill, so to go downhill the step must be taken against it: a minus sign.
4 Slope in any direction
This should give the slope of f along the unit arrow u. One tile is wrong. Find it, then fix it.
Tap the tile that is wrong.
Two arrows produce a single number through the dot product: βf Β· u, the part of the gradient that lies along u.
5 Collect the slopes
Which arrow is the gradient at the point (1, 1)?
βf/βx = 2x gives 2 and βf/βy = 6y gives 6: the gradient is (2, 6).
6 Slope in a chosen direction
With the gradient of xy, find the slope in the direction of the unit arrow u at (2, 1).
βf = (y, x) = (1, 2) at the point, and (1, 2) Β· (0.6, 0.8) = 0.6 + 1.6 = 2.2.
7 Walking along the contour
Along a contour line you neither climb nor descend. Write in symbols: if the gradient is perpendicular to the direction u, then the slope in that direction is zero. Then compare.
One way:
D_u f is the dot product of βf and u, and a dot product of perpendicular arrows is zero.
8 Compute and collect
For f(x, y) = xΒ² y, write the gradient as the arrow of its two partial derivatives, and give its value. Then compare.
One way:
βf/βx = 2xy and βf/βy = xΒ²: the gradient collects them into one arrow.
9 The saddle
A mountain pass has height f(x, y) = xΒ² β yΒ²: up along x, down along y. Judge each sentence: true or false?
| β | |||
| β | |||
| β | |||
| β | β |
A tick means the columnβs claim holds at the rowβs point, for f = xΒ² β yΒ², whose gradient is (2x, β2y).
At (1, 0) the height is 1 and at (0, 1) it is β1: different contours. At the very middle the gradient is zero, yet it is neither a top nor a bottom.
10 Climb, coast or drop
Four things the slope in direction u can be. Pair each with what it means for the walker.
Tap a line, then its meaning.
D_u f = βf Β· u ranges from βββfβ to ββfβ as u turns; zero happens at right angles to the gradient.
11 Hold y still
Take both partial derivatives of f = 3xy + yΒ². One tile is wrong. Find it, then fix it.
Tap the tile that is wrong.
For βf/βx, y is a constant: 3xy gives 3y and yΒ² gives nothing. The 2y belongs to βf/βy.
12 A step the wrong way
One step of gradient descent with ΞΈ = 4, gradient 6 and learning rate 0.5. One tile is wrong. Find it, then fix it.
Tap the tile that is wrong.
Descent goes against the gradient: 4 β 0.5 Β· 6 = 1. Adding would climb to 7, and the learning rate must not be dropped.
13 The steady slope
A plane roof has height 3x + 4y. How steep is its steepest direction?
βf = (3, 4) everywhere, and its length is β(9 + 16) = 5. Adding 3 + 4 = 7 is not a length.
14 Walking sideways
At p the gradient points along y. What is the slope if you walk along x?
(0, 2) Β· (1, 0) = 0: walking at right angles to the gradient, you neither climb nor descend.
15 One step down
The loss is ΞΈΒ², you stand at ΞΈ = 3 and the learning rate is 0.1. Where does one step of gradient descent take you?
βL = 2ΞΈ = 6, so ΞΈ β 3 β 0.1 Β· 6 = 2.4. Going to 3.6 would be climbing.
16 The steepest way
Write in symbols: among all unit directions, the slope is largest along the gradient, and that largest slope is the norm of the gradient. Then compare.
One way:
D_u f = βf Β· u = ββfβ cos ΞΈ, which is biggest when u points along βf and ΞΈ = 0.
Chapter finished. The symbols are yours.
Tell your own
Write a two-line story of something going downhill β a ball, a price, a mistake shrinking β in notation only: a height, a point, a gradient, a step.
Kept on this device only.