Momentum › A Worked Example: Tracking Velocity Through an Update

Michael BrenndoerferApril 23, 20252 min read
Language AI HandbookAll chapters
Part 10 of 67Neural Network Foundations
Chapter 67Momentum › A Worked Example: Tracking Velocity Through an Update
Reading section 12 of 18 · A Worked Example: Tracking Velocity Through an Update · 2 minSection 12 of 18 · 2 min

Book contents

Section 12 of 18 · 2 min read

Momentum › A Worked Example: Tracking Velocity Through an UpdateOne section · Sections in this chapter12 / 18 ↓
Reading tools Definitions & inline links

Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.

Article links

Make inline references clickable

To solidify the mechanics, let us trace through a few steps of momentum by hand on a simple two-parameter problem. Consider a loss function L(θ1,θ2)=25θ12+θ22\mathcal{L}(\theta_1, \theta_2) = 25\theta_1^2 + \theta_2^2 (a narrow valley with curvature ratio 25:1 between the two dimensions). Starting at (θ1,θ2)=(1.0,0.5)(\theta_1, \theta_2) = (1.0, 0.5) with learning rate α=0.01\alpha = 0.01 and momentum β=0.9\beta = 0.9 (PyTorch formulation), initial velocity v0=(0,0)\mathbf{v}_0 = (0, 0).

The gradient at position (θ1,θ2)(\theta_1, \theta_2) is:

∇L=(50θ1, 2θ2)\nabla \mathcal{L} = (50\theta_1, \, 2\theta_2)

Step 1: Gradient at (1.0,0.5)(1.0, 0.5) is (50,1.0)(50, 1.0).

v1=0.9⋅(0,0)+(50,1.0)=(50,1.0)\mathbf{v}_1 = 0.9 \cdot (0, 0) + (50, 1.0) = (50, 1.0) θ1=(1.0,0.5)−0.01⋅(50,1.0)=(0.5,0.49)\theta_1 = (1.0, 0.5) - 0.01 \cdot (50, 1.0) = (0.5, 0.49)

Step 2: Gradient at (0.5,0.49)(0.5, 0.49) is (25,0.98)(25, 0.98).

v2=0.9⋅(50,1.0)+(25,0.98)=(45+25, 0.9+0.98)=(70,1.88)\mathbf{v}_2 = 0.9 \cdot (50, 1.0) + (25, 0.98) = (45 + 25, \, 0.9 + 0.98) = (70, 1.88) θ2=(0.5,0.49)−0.01⋅(70,1.88)=(−0.2,0.471)\theta_2 = (0.5, 0.49) - 0.01 \cdot (70, 1.88) = (-0.2, 0.471)

Notice what happened: the velocity in the θ1\theta_1 direction (the steep dimension) jumped from 50 to 70, even though the step reduced θ1\theta_1 by half. The velocity has overshot and is now pointing in the wrong direction. This will cause oscillations in θ1\theta_1 before damping out.

Step 3: Gradient at (−0.2,0.471)(-0.2, 0.471) is (−10,0.942)(-10, 0.942).

v3=0.9⋅(70,1.88)+(−10,0.942)=(63−10, 1.692+0.942)=(53,2.634)\mathbf{v}_3 = 0.9 \cdot (70, 1.88) + (-10, 0.942) = (63 - 10, \, 1.692 + 0.942) = (53, 2.634)

The θ1\theta_1 velocity is shrinking (from 70 to 53) because the gradient flipped sign. Meanwhile θ2\theta_2 velocity is growing from 1.0 to 1.88 to 2.634, because the gradient in θ2\theta_2 has been consistently positive. After many steps, the θ1\theta_1 velocity will oscillate and decay while θ2\theta_2 velocity grows steadily. This is precisely the dampening-oscillations, accelerating-consistent-directions behavior described earlier, made concrete in numbers.