5.6.9 · D3Machine Learning (Aerospace Applications)

Worked examples — Optimization — SGD, momentum, Adam — derivations

2,177 words10 min readBack to topic

Here = the gradient (slope of the loss), = learning rate (step-size knob), = decay/memory of the running average, and a tiny number to avoid dividing by zero.


The scenario matrix

Every worked example below is tagged with the cell it covers. The matrix lists every case class this topic can throw at you.

# Cell (scenario class) What is special Example
A Positive gradient, plain step , basic SGD walk Ex 1
B Negative gradient / sign flip and crossing zero Ex 2
C Consistent direction → momentum builds same-sign , speed-up Ex 3
D Oscillating direction → momentum cancels alternating-sign (a ravine) Ex 4
E Zero / degenerate gradient (saddle) : who moves, who stalls Ex 5
F Exploding gradient huge : Adam's rescue Ex 6
G Pure-noise direction (mean 0) , , step Ex 7
H Limiting behaviour bias correction fades, EMA saturates Ex 8
I Real-world word problem CFD surrogate LR schedule Ex 9
J Exam twist derive needed for target speed-up Ex 10

Example 1 — Cell A: positive gradient, one plain SGD step

  1. Compute the gradient. . Why this step? SGD needs the slope at where we stand; for the derivative is exactly .
  2. Apply the rule . Why this step? Positive slope means the loss rises as grows, so we move left (down the bowl), toward .

Verify: the minimum of is at , and is closer to than — loss dropped from to . Units: dimensionless, dimensionless. ✓


Example 2 — Cell B: negative gradient and a sign flip

  1. Step 1 gradient: (negative — loss decreases as grows). Why this step? Sign of tells direction: means go right (increase ).
  2. Update: . Why this step? Subtracting a negative adds — we correctly move toward from the left.
  3. Step 2 gradient: , still negative → keep moving right. .

Verify: shrank ; each step multiplies by . Indeed and . ✓ No overshoot because .


Example 3 — Cell C: consistent direction, momentum builds

  1. Unroll velocity. ; ; . Why this step? Momentum sums the recent gradients (an exponentially weighted sum); same-sign terms add up.
  2. Limit. Constant gives a geometric series . Why this step? for ; this is the source of the famous speed-up.
  3. Effective step , i.e. a 10× amplification of the raw .

Verify: against the partial geometric sum . ✓ And . ✓


Example 4 — Cell D: oscillating direction, momentum cancels

  1. .
  2. . Why this step? The old velocity is almost cancelled by the flipped ; the alternating signs destructively interfere.
  3. ; .

Verify: SGD's velocity would be exactly every step (swing amplitude ). Momentum's swing settles near / — the cross-ravine wobble is damped roughly on the cancelling part. Compare Ex 3 (consistent → grows to ) with this (oscillating → stays small): same rule, opposite outcome, exactly the design goal. ✓


Example 5 — Cell E: zero gradient at a saddle

  1. Plain SGD: step . Stalls instantly. Why this step? SGD has zero memory; no slope → no motion. This is why deterministic full-batch GD gets stuck at saddles.
  2. Momentum: , step . Keeps rolling. Why this step? Stored velocity carries it across the flat spot — like a ball coasting.
  3. Adam: , . Step . Also coasts.

Verify: ✓; ✓. The degenerate case cleanly separates memoryless SGD (stuck) from the memory-based methods (unstuck) — the whole practical argument for momentum/Adam. ✓


Example 6 — Cell F: exploding gradient, Adam rescues

  1. SGD step: . A catastrophic jump — likely diverges. Why this step? SGD's step is proportional to ; a big gradient means a big, dangerous leap.
  2. Adam step (settled): . Why this step? Dividing by normalizes the magnitude away, leaving a unit step. This is the per-coordinate rescaling Adam is famous for.

Verify: , so , times . The exploding-gradient scenario shows Adam's step is , independent of scale. ✓


Example 7 — Cell G: pure-noise direction, step dies

  1. First moment (mean tracker): ; ; ; . Why this step? estimates ; with alternating signs it hovers near 0.
  2. Second moment (magnitude tracker), using each step: ; ; and it climbs toward . Why this step? estimates regardless of sign — squaring erases the flip.
  3. Settled step . Adam freezes noisy directions.

Verify: ✓; ✓. Small over larger ⇒ tiny step — the signal-to-noise behaviour. Contrast Ex 6 (steady ) with this (noise → ). ✓


Example 8 — Cell H: limiting behaviour, bias correction fades

  1. Raw EMA at step : with , . Why this step? Starting from drags the average toward zero early; from the parent's series argument.
  2. Correction factors: , , .
  3. Corrected: exactly, at every . Why this step? Dividing by the same cancels the bias — that's the whole point of bias correction; it matters most when is small (factor at ).

Verify: , so ✓; corrected mean is exactly . As the factor , so bias correction quietly switches itself off. ✓


Example 9 — Cell I: real-world CFD surrogate word problem

  1. : . Why this step? Early on we want big exploratory steps to escape saddles.
  2. : . Halved.
  3. : . Why this step? Late training wants tiny steps so the noisy path stops zig-zagging and settles into the minimum.

Verify: , so ; ratio . Units: learning rate dimensionless throughout. ✓ This matches the parent's schedule.


Example 10 — Cell J: exam twist, solve for

  1. Set up: . Why this step? The steady-state velocity of momentum is (geometric sum, Ex 3); invert it for the target.
  2. Default check: .
  3. Bump: — a tiny change (0.9→0.99) multiplies the speed-up 10-fold, because shrinks nonlinearly. Why this step? The map blows up near ; that sensitivity is why is tuned in the top decimals.

Verify: ✓, ✓, ✓.


Recall Self-test: name the cell, then answer

Which optimizer moves at a saddle where right now, and why? ::: Momentum and Adam (stored velocity / coasts through); SGD stalls because it has no memory (Cell E). On a steady slope with , what is the momentum speed-up and where does it come from? ::: , from the geometric sum (Cell C). Why does Adam give a step for both and ? ::: It divides by , cancelling magnitude — a per-coordinate normalization (Cell F). In a pure-noise direction why does Adam's step go to zero? ::: (mean gradient) but , so the ratio (Cell G). Why does bias correction matter most at small ? ::: The factor is tiny early (0.1 at ), so uncorrected badly underestimates (Cell H).

Back to the parent derivations · Hinglish version: 5.6.09 Optimization — SGD, momentum, Adam — derivations (Hinglish)