ContentsChapter 3 · Statistics and optimisation3 of 4

3.3

Gradient descent and convexity

In this chapter
  1. 3.1Maximum likelihood
  2. 3.2Priors and MAP
  3. 3.3Gradient descent and convexity
  4. 3.4Lagrange multipliers
Before you readYou know the slope of your loss where you are now, but not where its minimum is. Which way should you step?
Watch: Gradient Descent, Step-by-Step · StatQuest with Josh Starmer

Gradient descent takes a step against the gradient of the loss JJ then recomputes the gradient at the new point:

θt+1=θt−η∇J(θt).\theta_{t+1}=\theta_t-\eta\nabla J(\theta_t).

The gradient points in the direction of steepest increase, so the minus sign sends you downhill for a small enough step. The learning rate η>0\eta>0 scales the step. Too small and progress is slow; too large and you can overshoot or even move farther from the minimum on every step.

0481216-4-2024
x = -0.39Loss = 0.15
Start at x = 1.8 on the loss curve J(x) = x². The larger dot is your latest step. Try rates of 0.10, 0.50 and 1.10: when do you approach, land on or move away from the minimum?

A loss is convex if the line segment between any two points on its graph lies on or above the graph. For a differentiable convex loss on Rd\mathbb{R}^d a zero gradient is enough to identify a global minimum. For a non-convex loss, a zero gradient could instead mark a local minimum, a maximum or a saddle.

For example, J(x)=∑i=1n(x−yi)2J(x)=\sum_{i=1}^n(x-y_i)^2 is convex. Setting J′(x)=2(nx−∑iyi)J'(x)=2(nx-\sum_i y_i) to zero gives x=1n∑iyix=\frac1n\sum_i y_i the mean is the best constant prediction under squared loss. Here you can solve for it directly; gradient descent is useful when that shortcut is unavailable.

Recall
Which direction does gradient descent move, and what scales the step?
Recall
For a differentiable convex loss on Rd\mathbb{R}^d what does a zero gradient tell you?
Exercise
For J(x)=x2J(x)=x^2 start at x0=2x_0=2 and take one gradient descent step with η=0.75\eta=0.75 What is x1x_1
Exercise
Find the xx that minimises (x−1)2+(x−4)2+(x−7)2(x-1)^2+(x-4)^2+(x-7)^2