3.2.11 · D4Training Deep Networks

Exercises — Early stopping

3,503 words16 min readBack to topic

Level 1 — Recognition

Exercise 1.1 (L1)

Here is an epoch-by-epoch validation loss log:

1: 0.80, 2: 0.61, 3: 0.50, 4: 0.47, 5: 0.49, 6: 0.46, 7: 0.51, 8: 0.53

Which epoch holds the best-so-far weights?

Recall Solution

"Best-so-far" means the lowest seen up to and including that epoch. Scan the values: the running minimum is . The smallest value is , occurring at epoch 6. Answer: epoch 6. The dip at epoch 5 () does not reset the record because it is higher than epoch 4's .

Exercise 1.2 (L1)

True or false: the training loss curve is the one that forms a U-shape which early stopping watches for.

Recall Solution

False. Training loss keeps sliding down — the model can always fit the data it sees a little better. It is the validation loss that goes down, bottoms out, then climbs back up (the U-shape). Early stopping watches the validation curve. (This is exactly the two-curve picture described in the "U-shaped validation curve" callout above: training slides down forever, validation makes a valley.)


Level 2 — Application

Exercise 2.1 (L2)

Same log as 1.1, with patience :

1: 0.80, 2: 0.61, 3: 0.50, 4: 0.47, 5: 0.49, 6: 0.46, 7: 0.51, 8: 0.53

At which epoch does training stop, and which weights are restored?

Recall Solution

The rule: keep a counter of consecutive epochs that fail to beat the running minimum. Reset it to whenever a new record is set. Stop when the counter reaches .

Epoch New record? Counter
1 0.80 yes (first) 0
2 0.61 yes 0
3 0.50 yes 0
4 0.47 yes 0
5 0.49 no 1
6 0.46 yes 0
7 0.51 no 1
8 0.53 no 2 → STOP

Counter hits at epoch 8, so we stop after epoch 8 and restore the epoch-6 weights (the record holder ), not the epoch-8 weights.

Exercise 2.2 (L2)

Take one eigen-direction with . After gradient-descent steps (starting from weight ), what fraction of the ideal value has this direction reached? (This fraction is the shrinkage factor.)

Recall Solution

First check stability: ✓, so the formula applies. Use the page's one formula, the shrinkage factor: Why this formula? Each step multiplies the remaining gap by ; after steps the gap is , so the fraction covered is one minus that. Plug in: . Fraction reached . So this direction has travelled about 67% of the way to its ideal value.


Level 3 — Analysis

Exercise 3.1 (L3)

Using the matching condition with , , and : find the equivalent weight-decay strength .

Recall Solution

Stability check: ✓. Step 1 — compute the left side (WHAT): . (to 5 d.p.). Step 2 — set equal to the shrinkage of (WHY): this number is the fraction of the weight that survives shrinkage, and survives to the same fraction . So Step 3 — solve for (the algebra): cross-multiply: With : . Reading it: 20 steps at this learning rate is like a weight decay of in this direction.

Exercise 3.2 (L3)

Two eigen-directions share the same learning rate . Direction A has curvature (steep bowl), direction B has (nearly flat bowl). After steps, compute each shrinkage factor and explain what early stopping is doing to each.

Recall Solution

Stability check: ✓ and ✓. Shrinkage factor .

Direction A: . . Factor fully fit.

Direction B: . . Factor → barely moved, ~14%.

What early stopping did: it let the high-curvature direction A converge completely (these encode strong, general signal that reduces loss fast) while suppressing the low-curvature direction B (these barely move in the time budget, so they stay near — exactly like weight decay killing small-eigenvalue directions).

The figure below makes this concrete. The horizontal axis is training steps , the vertical axis is the shrinkage factor (fraction reached). The magenta curve (steep bowl, ) shoots up to within a few steps and stays pinned there — this direction is kept. The violet curve (flat bowl, ) crawls, reaching only ~ by the dashed orange stop line at — this direction is suppressed. Equal number of steps, wildly unequal distance travelled.

Figure — Early stopping
Figure: shrinkage factor vs training step , for a steep eigen-direction (magenta, kept) and a flat one (violet, suppressed); orange dashed line marks where we stop, steps.


Level 4 — Synthesis

Exercise 4.1 (L4)

You have samples. A colleague uses a validation set of only samples and finds the validation loss jitters by epoch-to-epoch. Their real improvements per epoch near the minimum are about . With patience , explain quantitatively why they keep stopping too early, then propose two independent fixes.

Recall Solution

The core problem: the noise band () is four times larger than the signal (real improvement ). Near the minimum a genuine improvement of is easily hidden inside a random dip followed by a bounce. So the "running minimum" can be set by a lucky noise spike, after which real improvements of can't beat it for many epochs → the patience counter fills up → premature stop, i.e. underfitting.

Fix 1 — bigger validation set. Validation-loss noise shrinks roughly like . Going from to samples cuts the jitter by , from down to — now noise signal, which is workable. (For the theory of why bigger sets give steadier estimates see Validation and Cross-Validation.)

Fix 2 — larger patience and a sensible min-delta. Raise (e.g. ) so a run of noise-driven misses doesn't trigger a stop. And recall min-delta is the minimum drop that counts as improvement: set it below the real signal (say ) so genuine gains still register, but above zero so pure noise wiggles of a fraction of the jitter don't keep falsely resetting the counter. Note how min-delta and patience cooperate: min-delta filters what counts as an improvement per epoch, while patience decides how many non-improvements to tolerate. Smoothing the monitored curve (moving average over a few epochs) is an equivalent third option.

Why the two fixes are independent: Fix 1 attacks the noise itself; Fix 2 attacks our tolerance for noise. Either helps; together they are robust.

Exercise 4.2 (L4)

Recall (parent note) that "more steps plays the role of ." A decaying learning rate means shrinks over training. Argue what a decaying does to the effective regularization near the end of training, using the shrinkage formula.

Recall Solution

Look at the surviving fraction . Progress in one step multiplies the remaining gap by : larger = bigger cut, faster arrival = weaker effective regularization (as long as we stay in the stable zone ). As decays toward the end, each late step barely changes the gap . So:

  • Early training (large ): weights move fast, high-curvature directions lock in.
  • Late training (small ): weights nearly freeze — the effective number of "useful" steps stops growing, so the effective stops shrinking. The model settles at a fixed regularization strength instead of drifting toward (no regularization).

Synthesis takeaway: a decaying schedule and early stopping cooperate — the decay naturally slows the march toward overfitting, giving early stopping a gentler, less noisy minimum to catch. See Gradient Descent for the underlying update rule.


Level 5 — Mastery

Exercise 5.1 (L5)

Design problem. You are told: , a "signal" eigen-direction has , a "noise" eigen-direction has . You want the noise direction shrunk to at most 25% of its ideal value (fraction reached ) while the signal direction reaches at least 99%. Find a number of steps (an integer) that satisfies both, or prove none exists.

Recall Solution

Stability check first: ✓ and ✓. Both directions are in the stable, monotone regime, so the shrinkage formula applies cleanly.

Set up the two inequalities using the shrinkage factor .

Noise constraint (want it small): fraction Take logs (log is monotone; , so the inequality flips): So .

Signal constraint (want it large): fraction Since gives (just fails) and gives (passes), we need .

Combine: we need . This range is non-empty, so a valid budget exists — for instance steps.

Check :

  • Signal fraction
  • Noise fraction

Answer: any integer steps works; is a safe pick. The steep signal direction converges in ~10 steps while the flat noise direction stays well below the 25% cap for up to 57 steps — a wide window, which is exactly why early stopping is forgiving in practice.

Exercise 5.2 (L5)

Conceptual mastery. In two sentences, explain why early stopping is called an implicit regularizer while (weight decay) is explicit, even though the parent note proves they are approximately equal. Then state the one situation where the equivalence breaks.

Recall Solution

Explicit vs implicit: adds a term directly to the objective — the regularization is written into the math you optimize. Early stopping changes nothing in the objective; it regularizes only as a side effect of not finishing the optimization, so the penalty is never written down (implicit) — its "strength" is hidden inside the stopping time .

Where the equivalence breaks: the proof relies on the quadratic (bowl) approximation of the loss near a single minimizer, with a fixed learning rate satisfying the stability condition , and plain gradient descent. That is where the clean map holds. The moment the real loss stops looking like one clean bowl — non-quadratic landscapes, several competing minima, momentum, or adaptive/decaying learning rates — the eigen-directions no longer shrink by the tidy independent factors , so early stopping and only roughly agree rather than matching exactly.

One-line takeaway: they coincide only in the local quadratic regime (the loss-bowl picture from Hessian and Curvature); outside it, treat them as related-but-distinct tools — a theme in Overfitting and Generalization.


Recall One-line self-check before you leave

The shrinkage factor answers: "how far did direction travel in steps?" ::: Steep ( big) → near (kept); flat ( small) → near (suppressed) — provided so steps stay stable. Stopping the clock ≈ weight decay.