Momentum › Visualizing Velocity Buildup
Language AI HandbookAll chapters Momentum › Visualizing Velocity BuildupSection view · Sections in this chapter16 / 18 ↓
Reading tools Definitions, links & notes
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 complete the intuitive picture, let us visualize how the velocity evolves over the first 50 training steps for a simple one-dimensional optimization problem.
PythonIn [11]Expand
# Simulate momentum velocity buildup on a 1D quadratic: L(x) = x^2
# True gradient at x is 2x; we start at x=5.0
def simulate_momentum_1d(start_x, lr, beta, n_steps, gradient_noise=0.5):
"""Simulate SGD with momentum on L(x) = x^2 with optional gradient noise."""
x = start_x
v = 0.0
xs = [x]
vs = [v]
for _ in range(n_steps):
g = 2 * x + np.random.randn() * gradient_noise
v = beta * v + g
x = x - lr * v
xs.append(x)
vs.append(v)
return np.array(xs), np.array(vs)
xs_no_mom, vs_no_mom = simulate_momentum_1d(5.0, lr=0.05, beta=0.0, n_steps=50)
xs_mom09, vs_mom09 = simulate_momentum_1d(5.0, lr=0.05, beta=0.9, n_steps=50)
xs_mom099, vs_mom099 = simulate_momentum_1d(5.0, lr=0.01, beta=0.99, n_steps=50)VisualizationsOut [12]Expand


The velocity buildup plot is illuminating. For plain SGD (), the velocity is simply the current gradient at each step: it fluctuates with the noisy gradient and never accumulates. For , the velocity builds up quickly over the first 10 steps and then stabilizes as the optimizer enters the basin around the minimum. For , the velocity builds up more slowly but reaches a higher peak, requiring the smaller learning rate to prevent the parameter from overshooting too far.
Comments
Add to the conversation
A question, a correction, or an example from your own work.
No comments yet. Be the first to share your thoughts!