Optimization

SGD & Momentum: The Workhorses of Optimization

Why plain gradient descent is noisy, how momentum smooths and accelerates it, and why the same trick still sits under many modern optimizers.

status: reviewimportance: criticaldifficulty 3/5math: undergraduateread: 14mdemo planned

Concept Structure

SGD & Momentum: The Workhorses of Optimization

01Intuition

Start with the picture, metaphor, or geometric mechanism.

02Math

Make the objects explicit and connect them with notation.

03Code

Mirror the equations with runnable implementation details.

04Interactive Demo

Manipulate the mechanism and watch the idea respond.

2prerequisites
2next concepts
3related links

Learning map

SGD & Momentum: The Workhorses of Optimization
BeforeGradient DescentNow3/4 sections readyTryUse the demo notes to predict the mechanism before moving on.NextAdam Optimizer

Object flow

3/4 sections readyAsk about thisResearch room
ConceptSGD & Momentum: The Workhorses of OptimizationOptimization
Local snapshot ready
concept:optimization/sgd-momentum

Conceptual Bridge

What should feel connected as you move through this page.

Carry inGradient Descent

Bring the mental model from Gradient Descent; this page will reuse it instead of restarting from zero.

Work hereSGD & Momentum: The Workhorses of Optimization

Why plain gradient descent is noisy, how momentum smooths and accelerates it, and why the same trick still sits under many modern optimizers.

Carry outAdam Optimizer

The next edge should feel earned: use the demo prediction here before following Adam Optimizer.

Test the linkUse the demo notes to predict the mechanism before moving on.Then continue to Adam Optimizer
01

01

Intuition

Build the mental picture first so the rest of the page has something to attach to.

Section prompt

Stochastic gradient descent is the simplest training loop:

  1. look at a mini-batch,
  2. estimate the gradient,
  3. step downhill.

The problem is that mini-batch gradients are noisy. On a narrow ravine, SGD can spend many steps zig-zagging across the steep direction instead of making steady progress along the shallow direction you actually care about.

Momentum adds memory. Instead of trusting only the current gradient, you keep an exponentially weighted average of recent gradients and move using that average.

That does two useful things:

  • it smooths noise across batches,
  • it accelerates consistent directions, because repeated pushes in the same direction accumulate.

This is why momentum feels like a heavy ball rolling downhill: tiny bumps get averaged away, while persistent slope keeps building velocity.

02

02

Math

Translate the story into symbols, assumptions, and a derivation you can inspect.

Section prompt

Let θt\theta_t be parameters at step tt, gt=L(θt)g_t = \nabla L(\theta_t) the gradient, η\eta the learning rate, and μ[0,1)\mu \in [0,1) the momentum coefficient.

Plain SGD is

θt+1=θtηgt.\theta_{t+1} = \theta_t - \eta g_t.

Momentum introduces a velocity variable:

vt+1=μvt+gt,v_{t+1} = \mu v_t + g_t, θt+1=θtηvt+1.\theta_{t+1} = \theta_t - \eta v_{t+1}.

If gradients point in roughly the same direction for many steps, then vtv_t approaches a geometric sum:

vtgt+μgt+μ2gt+=11μgt.v_t \approx g_t + \mu g_t + \mu^2 g_t + \cdots = \frac{1}{1-\mu} g_t.

So with μ=0.9\mu = 0.9, the effective step along a persistent direction can be about 10×10\times larger than plain SGD with the same nominal learning rate.

Nesterov momentum evaluates the gradient at a look-ahead point:

vt+1=μvt+L(θtημvt),v_{t+1} = \mu v_t + \nabla L(\theta_t - \eta \mu v_t), θt+1=θtηvt+1.\theta_{t+1} = \theta_t - \eta v_{t+1}.

The mental model is: "if I keep moving this way, what slope will I see next?"

03

03

Code

Keep the implementation aligned with the notation so the algorithm is legible.

Section prompt
import numpy as np

A = np.diag([1.0, 25.0])  # shallow in x, steep in y
theta0 = np.array([6.0, 6.0])

def grad(theta):
    return A @ theta

def optimize(mu, lr, steps=60):
    theta = theta0.copy()
    v = np.zeros_like(theta)
    for _ in range(steps):
        v = mu * v + grad(theta)
        theta = theta - lr * v
    return theta

sgd = optimize(mu=0.0, lr=0.08)
mom = optimize(mu=0.9, lr=0.02)

print("SGD final theta     :", np.round(sgd, 3))
print("Momentum final theta:", np.round(mom, 3))

The learning rate for momentum is smaller here on purpose: once gradients accumulate, the effective step can become much larger than the raw lr suggests.

04

04

Interactive Demo

Use direct manipulation to connect the explanation to a moving system.

Section prompt

No interactive demo yet for this concept. A natural next step is a ravine visualization that overlays SGD and momentum trajectories while you change learning rate and μ\mu.

No live visualization is registered for this concept yet.

The page still supports explanatory demo notes above; when a viz.tsx exists, it will render here without changing the route.

After The First Pass

Turn the concept into an inspected object.

Once the invariant is visible in the intuition, math, code, and demo, use these panels to inspect the mechanism visually, check source support, practice the idea, and attach a grounded research question.

Mechanism Storyboard

See the idea move before the page explains it

Why plain gradient descent is noisy, how momentum smooths and accelerates it, and why the same trick still sits under many modern optimizers.

Demo notes open01 / Intuition
Prediction lens

Start with the picture, metaphor, or geometric mechanism.

Commit first

Before reading further, choose the kind of change SGD & Momentum: The Workhorses of Optimization should make visible.

Visual Inquiry

Make the image answer a mathematical question

Why plain gradient descent is noisy, how momentum smooths and accelerates it, and why the same trick still sits under many modern optimizers.

3/4 stages readyDemo notes connected
Prediction

Which visible object should carry the first intuition?

Commit first

Pick the cue that should make SGD & Momentum: The Workhorses of Optimization easier to reason about before the page gives the answer.

Claim Review

Why plain gradient descent is noisy, how momentum smooths and accelerates it, and why the same trick still sits under many modern optimizers.

StatusSubstantive claim review pending

Source IDs and witness objects are attached for review; they are not proof by themselves.

SourcesNo references

Add source metadata before claiming support.

Witnesses3 local objects

Use equation, code, and demo objects to check whether the source support is operational.

Practice Loop

Try the idea before it explains itself

Why plain gradient descent is noisy, how momentum smooths and accelerates it, and why the same trick still sits under many modern optimizers.

Readiness0/3 checks ready
Predict

Before touching the demo, predict one visible change that should happen in SGD & Momentum: The Workhorses of Optimization.

Hint 1

Reveal when your model needs a nudge.

Hint 2

Reveal when your model needs a nudge.

Hint 3

Reveal when your model needs a nudge.

Object research drawerClose
ConceptSGD & Momentum: The Workhorses of OptimizationOptimization

Research Room

Attach the question to an exact object

Pick the concept, equation, source, code witness, claim, misconception, or demo state before asking for help. The handoff stays grounded to that object.
Next local actionNo local draft saved yet

Open the draft below to save one note and next action in this browser.

conceptOptimization

SGD & Momentum: The Workhorses of Optimization

Anchored question

What is the smallest example that makes SGD & Momentum: The Workhorses of Optimization click without losing the math?

Local action draftNo local draft saved yetExpand only when ready to capture one local next action
Local action draft

This draft stays locally in this browser for concept:optimization/sgd-momentum.

No local draft saved.
Evidence to inspect
  • Definition, prerequisite, and contrast concept links
  • The equation or code witness that makes the concept operational
  • One demo state that shows the invariant instead of a slogan
What would resolve this
  • The learner can state the mechanism in their own words
  • The learner can name the prerequisite that would repair confusion
  • The learner can predict how the mechanism changes under one perturbation
Grounded AI handoff

I am working in Continuous Function's research reading room. Object: concept - SGD & Momentum: The Workhorses of Optimization Object key: concept:optimization/sgd-momentum Context: Optimization Anchor id: concept/concept-notebook/optimization/sgd-momentum Open question: What is the smallest example that makes SGD & Momentum: The Workhorses of Optimization click without losing the math? Evidence to inspect: - Definition, prerequisite, and contrast concept links - The equation or code witness that makes the concept operational - One demo state that shows the invariant instead of a slogan What would resolve this: - The learner can state the mechanism in their own words - The learner can name the prerequisite that would repair confusion - The learner can predict how the mechanism changes under one perturbation Answer as a careful research tutor: stay source-grounded, separate verified evidence from assumptions, name the relevant math objects, and end with one next action.

Open source object
concept/concept-notebook/optimization/sgd-momentum concept:optimization/sgd-momentum