Skip to content
AI360XpertBeta

Nesterov Accelerated Gradient

Plain gradient steps correct where you stand. Nesterov first jumps where momentum carries you, then corrects there, which damps zigzags and lifts smooth convex speed.

Nesterov lookahead reaches 4.48 in two steps where plain descent reaches 4.61, projecting to 28 versus 153 steps to 0.01
Nesterov lookahead reaches 4.48 in two steps where plain descent reaches 4.61, projecting to 28 versus 153 steps to 0.01

Why Does This Exist?

Ill-conditioned valleys stall plain descent. On f(x,y)=x2+25y2f(x, y) = x^2 + 25y^2 the curvature ratio is κ=25\kappa = 25, so a step that is stable across the steep yy axis crawls along the flat xx axis. From distance 5, gradient descent needs about 153 steps to reach ∣x∣≤0.01|x| \le 0.01, while each step in a real model touches millions of parameters. Heavy-ball momentum helps but reads the gradient at the stale position and still overshoots the walls.

Nesterov fixes the staleness by reading the gradient at the predicted position. The smooth convex rate lifts from O(1/k)O(1/k) to O(1/k2)O(1/k^2), which is optimal for first-order methods, and the strongly convex rate lifts from 1−1/κ1 - 1/\kappa to 1−1/κ1 - 1/\sqrt{\kappa}.

This page covers the lookahead mechanism and its rates. The loop taxonomy lives in gradient descent variants, the rate definitions in convergence rates, and noisy extensions in stochastic gradient descent variants.

The one idea you need first

Momentum carries velocity vk=xk−xk−1v_k = x_k - x_{k-1}, where xkx_k is the current iterate and vkv_k is the step just taken. Heavy-ball steps xk+1=xk−α∇f(xk)+βvkx_{k+1} = x_k - \alpha \nabla f(x_k) + \beta v_k, where α\alpha is the step size, ∇f(xk)\nabla f(x_k) is the gradient at the old spot, and β\beta is the momentum weight. Nesterov keeps the inertia but moves the gradient to the predicted spot. The full loop list is in gradient descent variants.

Think of It Like This

Steering where the car will be

Heavy-ball steers from the rear-view mirror: it measures the slope where the car was, then adds speed. Nesterov looks through the windshield at the predicted position and steers there.

Speed maps to momentum, the steering correction maps to the gradient, a straight highway maps to a well-conditioned bowl where both work, and a slalom maps to a stretched valley where mirror-steering oscillates wall to wall.

Where it stops: lookahead assumes a smooth road. Potholes such as nonsmooth kinks and stochastic noise punish prediction and need smaller momentum or proximal variants.

How It Actually Works

For LL-smooth convex ff, where ff is the objective and LL is the smoothness constant bounding curvature, the iterates are yk=xk+βk(xk−xk−1)y_k = x_k + \beta_k (x_k - x_{k-1}) and xk+1=yk−(1/L)∇f(yk)x_{k+1} = y_k - (1/L) \nabla f(y_k), where yky_k is the lookahead point, xkx_k is the current iterate, βk=(k−1)/(k+2)\beta_k = (k-1)/(k+2) is the scheduled weight, and ∇f(yk)\nabla f(y_k) is the gradient at the lookahead. This gives f(xk)−f⋆≤2L∥x0−x⋆∥2/(k+1)2f(x_k) - f^\star \le 2L\lVert x_0 - x^\star \rVert^2/(k+1)^2, where f⋆f^\star is the minimum value and x⋆x^\star is a minimizer.

For μ\mu-strongly convex ff, where μ\mu is the strong-convexity constant bounding curvature from below and κ=L/μ\kappa = L/\mu is the condition number, the fixed-weight variant uses β=(κ−1)/(κ+1)\beta = (\sqrt{\kappa}-1)/(\sqrt{\kappa}+1) and step 1/L1/L. Its linear rate is 1−1/κ1 - 1/\sqrt{\kappa} per step, versus 1−1/κ1 - 1/\kappa for plain descent. The proximal extension FISTA ports the schedule to f+gf + g with nonsmooth gg such as the Lasso penalty.

Worked example

Take f(x,y)=x2+25y2f(x, y) = x^2 + 25y^2. The Hessian is diagonal with entries 22 and 5050, so L=50L = 50, μ=2\mu = 2, and κ=25\kappa = 25. Use α=1/L=0.02\alpha = 1/L = 0.02 and β=(5−1)/(5+1)=0.6667\beta = (5-1)/(5+1) = 0.6667. Start at x0=(5.0,2.0)x_0 = (5.0, 2.0) with v0=(0.0,0.0)v_0 = (0.0, 0.0), where vv is velocity.

First step, with zero momentum, both methods agree. The gradient is ∇f(x,y)=[2x,50y]\nabla f(x, y) = [2x, 50y], so ∇f(5.0,2.0)=[10.0,100.0]\nabla f(5.0, 2.0) = [10.0, 100.0] and x1=(5.0−0.02×10.0,2.0−0.02×100.0)=(4.8,0.0)x_1 = (5.0 - 0.02 \times 10.0, 2.0 - 0.02 \times 100.0) = (4.8, 0.0). Velocity becomes v1=(−0.2,−2.0)v_1 = (-0.2, -2.0).

Second step splits them. Plain descent stays on axis: x2=(4.8−0.02×9.6,0.0−0.0)=(4.608,0.0)x_2 = (4.8 - 0.02 \times 9.6, 0.0 - 0.0) = (4.608, 0.0). Nesterov first looks ahead to y2=x1+0.6667v1=(4.8−0.1333,0.0−1.3333)=(4.6667,−1.3333)y_2 = x_1 + 0.6667 v_1 = (4.8 - 0.1333, 0.0 - 1.3333) = (4.6667, -1.3333), reads ∇f(y2)=[9.3333,−66.6667]\nabla f(y_2) = [9.3333, -66.6667], then steps to x2=(4.6667−0.1867,−1.3333+1.3333)=(4.48,0.0)x_2 = (4.6667 - 0.1867, -1.3333 + 1.3333) = (4.48, 0.0). Two steps give 4.6084.608 plain versus 4.484.48 lookahead, and the gap widens because Nesterov steps grow while plain steps shrink.

Project to ∣x∣≤0.01|x| \le 0.01 from 5.05.0, which makes f≤0.0001f \le 0.0001 on axis. Plain descent shrinks by 0.960.96 per step, so 0.96k×5.0≤0.010.96^k \times 5.0 \le 0.01 needs k≥153k \ge 153. Nesterov shrinks by about 0.800.80 per step, so 0.80k×5.0≤0.010.80^k \times 5.0 \le 0.01 needs k≥28k \ge 28. Those are the 28 versus 153 counts in the diagram.

Code

The point is the check: the same two steps and the same 28 versus 153 projection, in plain Python with no dependencies.

import math

def grad(p: tuple[float, float]) -> tuple[float, float]:    return (2.0 * p[0], 50.0 * p[1])

def sub(a: tuple[float, float], b: tuple[float, float]) -> tuple[float, float]:    return (a[0] - b[0], a[1] - b[1])

def add(a: tuple[float, float], b: tuple[float, float]) -> tuple[float, float]:    return (a[0] + b[0], a[1] + b[1])

def scale(a: tuple[float, float], s: float) -> tuple[float, float]:    return (a[0] * s, a[1] * s)

alpha: float = 0.02beta: float = 2.0 / 3.0x0: tuple[float, float] = (5.0, 2.0)g0 = grad(x0)x1: tuple[float, float] = sub(x0, scale(g0, alpha))print((round(x1[0], 4), round(x1[1], 4)))  # -> (4.8, 0.0)
v1 = sub(x1, x0)y2 = add(x1, scale(v1, beta))print((round(y2[0], 4), round(y2[1], 4)))  # -> (4.6667, -1.3333)
g2 = grad(y2)x2_nes: tuple[float, float] = sub(y2, scale(g2, alpha))print((round(x2_nes[0], 4), round(x2_nes[1], 4)))  # -> (4.48, 0.0)
g1 = grad(x1)x2_gd: tuple[float, float] = sub(x1, scale(g1, alpha))print((round(x2_gd[0], 4), round(x2_gd[1], 4)))  # -> (4.608, 0.0)
k_gd: int = math.ceil(math.log(0.002) / math.log(0.96))k_nes: int = math.ceil(math.log(0.002) / math.log(0.80))print((k_gd, k_nes))  # -> (153, 28)

The prints give (4.8,0.0)(4.8, 0.0), lookahead (4.6667,−1.3333)(4.6667, -1.3333), Nesterov (4.48,0.0)(4.48, 0.0) versus plain (4.608,0.0)(4.608, 0.0), and the projection (153,28)(153, 28). The only change from heavy-ball is where the gradient is read.

Watch Out For

Running textbook schedule on noisy stochastic gradients

The O(1/k2)O(1/k^2) proof needs exact gradients. With minibatch noise, the lookahead chases sampling noise: at β=0.6667\beta = 0.6667 the loss oscillates worse than plain SGD and can diverge, even though the same schedule glides on full batches.

Symptom is early violent oscillation that lowering α\alpha only slows. Dampen to β≤0.5\beta \le 0.5, grow batches, or switch to variance-reduced accelerated variants. If Nesterov-SGD oscillates worse than SGD, noise is driving the wheel.

Skipping restarts on locally strong bowls

Global O(1/k2)O(1/k^2) scheduling overshoots near the bottom once local strong convexity kicks in. The loss sawtooths late: it falls for 20 steps, ripples up, then falls again, wasting the 2828-step linear tail the fixed β\beta would give.

Restart momentum when ∇f(xk)⋅vk>0\nabla f(x_k) \cdot v_k > 0, meaning the velocity points uphill. That recovers the fast tail. If the loss sawtooths late, momentum is stale, not small.

The Quick Version

  • Nesterov reads the gradient at the lookahead yky_k, not at the position xkx_k.
  • Smooth convex rates lift from O(1/k)O(1/k) to O(1/k2)O(1/k^2), which is optimal for first-order oracles.
  • On x2+25y2x^2 + 25y^2 from (5,2)(5, 2), two steps give 4.484.48 versus 4.6084.608 plain.
  • Reaching 0.010.01 takes about 2828 steps versus about 153153 plain.
  • Strongly convex rate lifts from 1−1/κ1 - 1/\kappa to 1−1/κ1 - 1/\sqrt{\kappa}.
  • FISTA extends the schedule to proximal nonsmooth splits such as Lasso.
  • Dampen momentum under noise and restart it when it points uphill.