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

Subtitles:

Tap a line to see its words.

  1. The height of a valley side above its floor depends on where you stand: x metres east and y metres north.
  2. Fog comes down. The hiker is 3 metres east and 1 metre north of the floor’s lowest point, but cannot see it.
  3. Here the ground is 11 metres above the floor.
  4. Feeling with a boot: stepping east, the ground rises about 2x for each metre; stepping north, about 4y.
  5. So right here the steepest way up points 6 east and 4 north.
  6. The steepest way down is exactly the opposite arrow.
  7. The hiker takes a small step, one tenth of that arrow, and stands at 2.4 east and 0.6 north.
  8. The height has dropped from 11 to 6.48 metres.
  9. 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.

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.

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.

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.

5 Collect the slopes

Which arrow is the gradient at the point (1, 1)?

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).

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.

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.

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).

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.

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.

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.

13 The steady slope

A plane roof has height 3x + 4y. How steep is its steepest direction?

14 Walking sideways

At p the gradient points along y. What is the slope if you walk along x?

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?

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.

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.