Skip to content
Iris (Jieun) Kim — home

Little Laboratory/ II

Gradient Descent

How does a step downhill find the bottom of a bowl?

A point on a bowl-shaped surface, moved downhill one step at a time against the gradient. Choose where it starts, how steep the bowl is and how large each step is, and see it settle, overshoot, or run away.

-2-20022
  • level curves of f
  • path
Iteration
0 of 41
Point
(-2.200, 1.600)
f(x, y)
6.260
|∇f|
5.280

η = 0.30 is below 2/max(a, b) = 0.67, and both step factors are positive: every step moves closer to the minimum.

A bowl, seen from above. The ellipses are level curves of f; the minimum is at the centre. Click or tap anywhere on the surface to start from there, or set the start with the sliders.

The model

The surface is a quadratic bowl,

f(x,y)=12(ax2+by2),a,b>0,f(x,y) = \tfrac{1}{2}\left(a x^2 + b y^2\right), \qquad a, b > 0,

whose only minimum is at the origin, and whose gradient is ∇f=(ax,  by)\nabla f = (a x,\; b y). Gradient descent moves against the gradient by a fixed fraction η\eta of its size — the learning rate — at every step:

pn+1=pn−η ∇f(pn).\mathbf{p}_{n+1} = \mathbf{p}_n - \eta\,\nabla f(\mathbf{p}_n).

When it works, and when it does not

For this bowl the two coordinates do not interact, and each step simply multiplies xx by (1−ηa)(1 - \eta a) and yy by (1−ηb)(1 - \eta b). So the iteration converges exactly when both factors are smaller than one in magnitude, that is, when

η<2max⁡(a,b).\eta < \frac{2}{\max(a, b)}.

If a factor is negative but still smaller than one in size, that coordinate overshoots the bottom and lands on the other side at each step, shrinking all the while: oscillation. If a factor reaches one in magnitude the steps stop shrinking and the point leaves the frame: divergence. A bowl that is much steeper one way than the other (a≪ba \ll b) is the awkward case, because the rate that is safe for the steep direction is slow for the shallow one.

Everything above is true of this quadratic. For a general non-convex function gradient descent is only guaranteed, at best, a local minimum, and whether it reaches even that depends on the function and the learning rate.

Connected ideas

Related research