3.2.1 · D3Training Deep Networks

Worked examples — Stochastic gradient descent (SGD)

2,645 words12 min readBack to topic

Before anything, recall the one rule everything below uses. In plain words: take your current guess, feel the downhill direction, step a little that way.

We will need two more symbols throughout. = the total number of training examples in the dataset (its size). = the mini-batch size, i.e. how many of those examples we sample on one step. So ranges from up to .


The scenario matrix

Every SGD situation is one of these cells. The examples below are each tagged with the cell(s) they cover.

Cell Scenario What could break / surprise
A Gradient negative () must move right, sign flip in update
B Gradient positive () must move left
C Gradient zero (at/over the minimum) step does nothing — degenerate
D Mini-batch (pure SGD, max noise) zig-zag path, chases single points
E Mini-batch vs full batch ( = dataset size) noise reduction , cost trade-off
F Fixed → bounces forever never settles exactly
G Decaying (Robbins–Monro) → settles wobbles die out
H too large → divergence / overshoot loss explodes
I Real-world word problem translate story → loss → update
J Exam twist (linear scaling rule / epochs count) conceptual, not just arithmetic

Prerequisites worth a glance: Gradient Descent (the deterministic parent), Learning Rate Schedules (cell G/H), Batch Size and Generalization (cell E/J), Backpropagation (how real is computed).


Worked Examples

For examples 1–5 we reuse one tiny, fully transparent world so you can see every number:

Figure — Stochastic gradient descent (SGD)
Figure s01 — The two dashed parabolas are each single-point losses (cyan , amber ); the solid white curve is their average, the full loss. Its lowest point sits at the mean . Reading it: SGD samples one dashed curve at a time, but on average it descends the white one.











Recall Which cell was hardest for you?

The zero-gradient degenerate case (C) and the divergence case (H) are the two that trip people up. In cell C, does the parameter move? ::: No — the step is ; only the next mini-batch (with nonzero slope) can move it. In cell H, what quantity multiplies the error each step for our sandbox? ::: ; if that exceeds (here ), the error grows. In general the stability bound is , where is the gradient's steepness (Lipschitz constant of ); our toy has , giving .

Related deep dives: Momentum and Nesterov (smoothing the zig-zag of Example 4), Adam and Adaptive Optimizers (per-parameter ), Bias-Variance Tradeoff (why flat minima from noise generalize).