3.2.4 · D3Training Deep Networks

Worked examples — AdaGrad and RMSprop

2,217 words10 min readBack to topic

This is the worked-example lab for the parent note. There we derived the two update rules. Here we run them through every case class — tiny gradients, huge gradients, gradients that flip sign, zero gradients, the long-run limit, a real word problem, and an exam-twist. Guess each answer before you read the steps.

A quick reminder of the two rules we are stress-testing (both act on one coordinate , so every , , below is a plain number, not a vector):


The scenario matrix

Every situation these optimizers face falls into one of these cells. The examples below are tagged with the cell(s) they cover.

Cell Scenario What we must check
C1 Large gradient vs small gradient (two coordinates) the equalizing effect — does a small- coord get a big step?
C2 Sign of flips () update direction flips, but the divisor uses so it ignores sign
C3 Constant gradient, long run AdaGrad step ; RMSprop step
C4 (dead / flat direction) update = 0, but does the divisor keep its memory?
C5 First step, empty accumulator saves us from dividing by zero
C6 Sudden gradient spike (exploding-ish) how each optimizer damps a burst — links to Vanishing and Exploding Gradients
C7 Real-world word problem translate an English scenario into the update
C8 Exam twist: choose for a memory horizon connect to "how many steps back it remembers"

Example 1 — the equalizing effect · Cell C1

Forecast: guess — will B (with the tiny gradient) take a tiny step, or does AdaGrad rescue it?

  1. A: , so step . Why this step? First gradient sets A's own scale — dividing by leaves the raw learning rate untouched.
  2. B: , so step . Why this step? B divides by its own small , which cancels B's small gradient. The tiny gradient is boosted back up.

Result: both move . B's raw gradient was smaller yet it takes an equal step. This is the whole point — see the parent's "fog / cliffs and slopes" picture.

Figure — AdaGrad and RMSprop

Verify: . Units: and gradient are in "parameter per step" balance so the step is a plain parameter displacement. ✓


Example 2 — the sign of the gradient · Cell C2

Forecast: does flipping the sign change how big the step is, or only which way it goes?

  1. Step 1: . Step . Why this step? The divisor only sees ; the positive step moves down (subtracted).
  2. Step 2: . Step . Why this step? again, so the divisor grew ( rose to ), and the sign of the update flipped because is now negative.

Lesson: the divisor is sign-blind (it squares ), but the numerator carries the sign — so direction reverses while magnitude is governed only by accumulated size.

Verify: and . ✓


Example 3 — the long run: AdaGrad dies, RMSprop lives · Cell C3

Forecast: which one is still moving at step 100?

  1. AdaGrad, step : since always, . Step .
    • : . : . : . Why? The sum only grows, so the denominator grows without bound — the parameter freezes.
  2. RMSprop steady state: solve . Step forever. Why? The EWMA saturates at the true mean-square ; a bounded divisor gives a constant step.
Figure — AdaGrad and RMSprop

Result: at step 100 AdaGrad crawls at while RMSprop still strides at — a gap, growing forever. This is the parent note's "Accumulates → Arrests" vs "Remembers Recently → Runs."

Verify: AdaGrad; RMSprop steady state , step . ✓


Example 4 — a dead direction: · Cell C4

Forecast: does the parameter move? Does the optimizer forget its accumulated memory?

  1. Update: step . Why? Zero gradient in the numerator kills the whole step — no gradient, no reason to move. (Momentum, by contrast, would keep coasting; see Momentum.)
  2. New accumulator: . Why? A zero-gradient step is still an observation of "recent size ," so the average decays from toward — the memory of past bumpiness fades but is not erased.

Lesson: ⇒ no move, but the divisor shrinks toward the recent mean-square. If gradients stay zero forever, and the next nonzero gradient would get a very large effective step (that's what ultimately bounds).

Verify: update exactly; . ✓


Example 5 — the very first step and the role of · Cell C5

Forecast: with and , does the formula explode ()?

  1. Step 1: . Step . Why matters: without we'd write , undefined. With the denominator is — finite — and the numerator's makes the whole step anyway. turns a "" into a clean "."
  2. Step 2: . Step . Why? cancels the gradient , leaving . The is negligible here — it only ever matters when the accumulator is tiny.

Verify: step 1 ; step 2 . ✓


Example 6 — a gradient spike (near-exploding) · Cell C6

Forecast: SGD would take a step of (huge!). Does RMSprop take a bigger step too?

  1. Update with the spike: . Why? The squared spike enters the average, but weighted only by , so jumps to , not all the way to .
  2. RMSprop step: . Why? Because the divisor grew with the spike, the -bigger gradient produces only a -bigger step, not . RMSprop self-damps bursts.
  3. Plain SGD step: . Why the contrast? SGD has no divisor, so the spike passes straight through — a jump of that can destabilize training. This is exactly the exploding-gradient danger in Vanishing and Exploding Gradients that per-coordinate scaling tames.

Verify: ; RMSprop step ; SGD step . ✓


Example 7 — real-world word problem · Cell C7

Forecast: which rare word gets the bigger update when it finally appears?

  1. "the": hit 10,000 times with , so . Step . Why? A frequent word has accumulated a huge ; its effective rate is now tiny — it has already learned, so it fine-tunes.
  2. "aardvark": hit once with , so . Step . Why? A rare word has a tiny accumulator, so its one appearance earns a full-sized step — it learns fast from scarce data.

Result: the rare word moves farther on its update. This is why AdaGrad shines on sparse NLP problems (the parent's "good for convex / sparse" note).

Verify: "the" step ; "aardvark" step ; ratio . ✓


Example 8 — exam twist: pick for a memory horizon · Cell C8

Forecast: guess before computing.

  1. Solve the horizon: . Why this formula? In an EWMA the weight on the gradient steps ago is ; these weights sum to and their "center of mass" (effective window) is steps. Longer memory ⇒ closer to .
  2. Weight on the newest gradient: the newest term carries weight . Why so small? A long memory means each single step contributes little — the estimate is smooth, changing slowly. (Contrast the default : window steps, newest weight .)

Lesson: is a memory dial, not a step-size dial — that's the parent's " vs " mistake warning. Bigger = smoother, longer-memory divisor.

Verify: ; newest weight . ✓


Recall Which cell did each example cover?

Ex1 equalizing (C1) ::: small vs large gradient get equal steps Ex2 sign flip (C2) ::: divisor squares , only numerator carries sign Ex3 long run (C3) ::: AdaGrad , RMSprop Ex4 dead direction (C4) ::: ⇒ no move, but decays Ex5 first step + (C5) ::: turns into a clean Ex6 spike (C6) ::: RMSprop self-damps a burst; SGD lets it through Ex7 word problem (C7) ::: rare word gets a huge step, frequent word a tiny one Ex8 exam twist (C8) ::: for a 100-step memory window

Recall Quick self-test

Constant , AdaGrad, : step at ? ::: Same but RMSprop steady state? ::: (E saturates at 1) RMSprop for a 20-step memory window? ::: If one step, does RMSprop's stay the same? ::: No — it decays:

Connections