3.2.1 · D1Training Deep Networks

Foundations — Stochastic gradient descent (SGD)

2,367 words11 min readBack to topic

This page assumes nothing. Every letter and squiggle in the parent note is unpacked here, in an order where each idea rests on the one before it. If a symbol on the parent page confused you, find it below. (The name SGD always means Stochastic Gradient Descent — "stochastic" is just a fancy word for "randomly sampled.")


0. The mental picture we keep returning to

Everything in SGD lives on one image: a landscape of hills and valleys, where low = good. Your position is your parameter setting; the height is how wrong the network is. Walking downhill = learning.

Figure — Stochastic gradient descent (SGD)

Figure 1 — the mistake landscape. Keep this picture in your head. Every symbol below is either a coordinate on this landscape, the height, or an instruction for how to step.


1. Parameters — the symbol

Picture. In the landscape image (Figure 1), is your location on the flat ground — your -coordinate (and , and a million more). Turn a dial → you slide to a new spot on the map.

Why the topic needs it. Training = "which setting of the dials is best?" You cannot talk about searching for a good setting without a symbol for "the current setting." That symbol is .

The little clock symbol means "the value of at step " — is where you start, after one step, and so on. is just a counter, like frame numbers in an animation.


2. The loss — the symbol and

The subscript is a label picking out which example: is example 1's badness, is example 2's, up to .

Reading the sum symbol. The big ("sigma") just means add up. is a compact way to write . The "" underneath is the start, the "" on top is the end. Dividing by turns "total" into "average."

Picture. is the height of the ground at your location . Move to a lower spot → smaller average mistake → better network. The whole surface in Figure 1 is the function .

Why the topic needs it. SGD is a minimizer. You cannot minimize without a single number to shrink — that number is .


3. Which direction is downhill? — the gradient

Here is the tool the whole method hinges on. We ask: standing at , which way is steepest downhill, and how steep? The mathematical answer to exactly that question is the gradient.

A note on the subscript. The upside-down triangle ("nabla") is the name of this operation: "give me the slope-arrow." The subscript in reminds us we're measuring steepness as the dials change (not, say, as the data changes). We will always write the subscript — — for consistency, even when it's obvious.

Figure — Stochastic gradient descent (SGD)

Figure 2 — the gradient arrow. Why this tool and not another? We need one object that answers two questions at once — which way and how much. A plain number (slope) gives "how much" in one dimension only. The gradient generalizes slope to millions of dials: it hands you a full arrow. That is precisely why it, and not a scalar derivative, is the engine of training.

Why the minus sign later. The gradient points uphill (steepest increase). We want down. So we step along . That single minus sign is the difference between learning and un-learning.

Where does come from mechanically for a real network? From Backpropagation — the algorithm that computes this arrow efficiently. Here we only need to trust that we can get it.


4. The learning rate — the symbol

Picture. The gradient tells you which way to walk; tells you how big a stride to take. Big = giant leaps (fast but you might overshoot the valley floor and bounce). Tiny = baby steps (safe but slow).

Figure — Stochastic gradient descent (SGD)

Figure 3 — stride size. Why the topic needs it. The gradient's length alone would give a stride nobody chose. is the human-tuned knob that scales it into a sensible step. How to shrink over time is the subject of Learning Rate Schedules.

Now we can read the heart of the parent note: In words: new position = old position − (stride) × (uphill arrow). The minus makes it downhill. This is plain Gradient Descent — SGD is one twist away.


5. The twist: mini-batches — the symbols , ,

Computing exactly means summing over all examples every step. If is millions, that's brutally slow. The fix: estimate the slope from a small random sample.

Picture. Instead of surveying the entire valley to judge the slope, you feel the ground under just a small patch beneath your feet. That patch is ; its size is .

The notation under the sum means "for each example inside the mini-batch." The three sizes give three flavours: is full-batch, is pure SGD, and in-between is what everyone uses (see Batch Size and Generalization).

Figure — Stochastic gradient descent (SGD)

Figure 4 — noisy mini-batch arrows. Each blue arrow is one mini-batch's guess ; the yellow arrow is the true gradient they scatter around.


6. Noise words — expectation and variance

The sampled slope is random (depends which patch you stepped on). Three symbols describe randomness precisely.

Why it matters here. The parent's key claim is : on average, the cheap patch-slope points the same way as the true slope. This is called unbiased — no systematic error, just wobble.

Picture. In Figure 4, each patch gives a slightly different arrow. is the spread of that cloud when the patch is a single example.

What it means. Bigger patch → tighter cloud → less wobble, but only as , so doubling only halves variance. Diminishing returns.


7. Epoch — a housekeeping word

Picture. If the dataset is a deck of cards and each step deals cards, one epoch = dealing the whole deck once. You shuffle before each epoch so batches stay random and un-correlated.


Prerequisite map

Parameters theta = the dials

Gradient descent step rule

Loss L = average mistake height

Gradient grad L = downhill arrow

Learning rate eta = stride size

Mini-batch B of size m

Noisy gradient g_B

Expectation E and Variance sigma squared

SGD = noisy but cheap descent

Epoch = one full sweep

Read it as: dials + mistake give the height; the height gives the downhill arrow; arrow + stride give the step; sampling a batch makes the arrow noisy; noisy step, repeated, is SGD.


Equipment checklist

Test yourself — you should be able to answer each before reading the parent note.

What does the symbol stand for, and what is its picture?
All the network's tunable dials; your location on the loss landscape.
What is and where does it live on the landscape?
The average mistake over all examples; the height of the ground at position .
What does the gradient tell you, in two parts?
The direction of steepest increase and how steep it is — an arrow pointing uphill.
Why do we step along rather than ?
The gradient points uphill; we want to go down, so we flip the sign.
Does the gradient operation apply to a single example's loss too?
Yes — is the same operation fed one example's loss .
What role does play that the gradient alone cannot?
It sets the stride length — a human-chosen scale for how far each step moves.
What is the difference between , , and ?
= whole dataset size; = the random mini-batch; = its size.
What is the formal definition of ?
— the average squared gap from the mean.
What random variable does refer to?
— the variance of one randomly drawn example's gradient.
What does "unbiased" mean for ?
On average it equals the true gradient: .
Why is ?
Averaging independent gradients (each variance ) divides variance by .
How many SGD steps are in one epoch?
steps — one full pass through the data.

Next: with these symbols earned, re-read the parent SGD note, then branch into Momentum and Nesterov and Adam and Adaptive Optimizers for smarter stepping rules.