Batch, mini-batch, stochastic gradient descent
WHY does this distinction even exist?
The loss we truly want to minimise is the average over all training samples:
To move downhill we need the gradient . The exact gradient is:
The catch: computing this full sum is expensive when is huge (millions of aerodynamic CFD samples, sensor logs, etc.). So we approximate the gradient using a subset of data. The three methods are three choices of subset size.
HOW the update rule is derived (from first principles)
WHAT we want: parameters that minimise .
Step 1 — Taylor expand the loss around current for a small step :
Why this step? Near , the loss is locally linear; the linear term dominates the change.
Step 2 — Choose to decrease fastest. To make as negative as possible for a fixed step length, point opposite the gradient:
Why this step? The dot product is minimised when is anti-parallel to (Cauchy–Schwarz). is the learning rate (step size).
Step 3 — The general update:
where is our estimate of . The three methods differ only in :
Why is SGD "unbiased"? If we pick uniformly at random from :
So on average one random sample points the right way — it's just noisy. That noise is the whole story.
The variance trade-off (the 80/20 core)
For a mini-batch of size drawn from data with per-sample gradient variance :
Why? Variance of an average of i.i.d. terms shrinks like .

Worked Example 1 — one SGD step by hand
Fit with squared loss . Data: , start , .
Step: . Why this step? Chain rule: .
Update: . Why? Gradient is negative, so we step up in toward the true value .
We used one sample — this is SGD.
Worked Example 2 — one Batch step
Same model, now use both points: add , .
(as above). .
Batch gradient: . Why average? Batch GD uses the mean over all samples — the true gradient.
Update: . Smoother, single trustworthy step.
Worked Example 3 — mini-batch epoch bookkeeping
samples, . How many updates per epoch (one full pass over data)?
Why? Each mini-batch consumes samples; you need batches to cover all data once. Batch GD would give 1 update/epoch; pure SGD gives 1000.
Recall Feynman: explain to a 12-year-old
Imagine you're blindfolded on a hill and want to reach the bottom. To feel which way is downhill you tap the ground with your foot.
- Batch GD: you carefully measure the slope in every direction all around you before taking one slow, perfect step. Accurate but sloooow.
- SGD: you tap the ground once in a random spot and immediately take a step. Sometimes you step slightly wrong, but you take tons of quick steps and get down fast.
- Mini-batch: you tap a handful of spots, average them, then step. Not perfect, not random — the smart middle. That's why almost everyone uses it.
Flashcards
What is the batch size for Batch GD, SGD, and Mini-batch GD?
What is the single general update rule for all three methods?
Why is the SGD gradient estimate called "unbiased"?
How does gradient-estimate variance scale with batch size ?
How many parameter updates happen per epoch with samples and batch size ?
Why can a little noise in SGD be beneficial?
State the derivation reason the step direction is .
Why does Batch GD often lose to mini-batch in wall-clock time?
What is the linear scaling rule for learning rate?
What trick makes noisy SGD actually converge to the minimum?
Connections
- Gradient Descent — parent algorithm; these are its data-sampling variants.
- Learning Rate and Schedules — must adapt to batch size and time.
- Momentum and Adam — smooth out mini-batch noise using running averages.
- Loss Functions — the we sum over.
- Bias-Variance Tradeoff — the same variance logic governs .
- Saddle Points and Non-Convex Optimization — why noise helps in aerospace surrogate models.
- Backpropagation — how each is actually computed.
Concept Map
Hinglish (regional understanding)
Intuition Hinglish mein samjho
Dekho, teeno methods — Batch, Mini-batch, aur Stochastic (SGD) — ka basic kaam ek hi hai: loss ke pahaad par neeche utarna (downhill jaana). Farq sirf itna hai ki har ek step lene se pehle tum kitne training examples dekh kar direction decide karte ho. Batch GD saare examples dekhta hai — bahut accurate direction, lekin ek step lene mein bahut time. SGD sirf ek random example dekh kar step maar deta hai — direction thoda galat ho sakta hai (noisy), par steps bahut fast aur sasti hoti hain. Mini-batch beech ka smart raasta hai: 32 ya 64 examples ka chunk le kar average nikaalo, phir step. Isiliye real-world mein 90% log mini-batch hi use karte hain.
Update rule sab ke liye same hai: . Yahan gradient ka estimate hai aur learning rate (step size). Derivation simple hai — Taylor expansion se loss ka change nikalta hai, aur ise sabse zyada negative banane ke liye tumhe gradient ke opposite jaana padta hai. Bas yahi downhill direction hai.
Key insight yaad rakho: noise ka variance hota hai. Yaani jitna bada batch, utna kam shor, par utni mehngi compute. Chhota batch = zyada shor par sasti aur fast steps. Aur mazedaar baat — thoda noise actually achha hai, kyunki aerospace ke non-convex loss surfaces mein wo tumhe saddle points aur shallow minima se bahar nikaal deta hai. Isiliye "exact gradient wala Batch GD best hai" ye galat soch hai — accuracy per step matlab nahi, per second progress matlab rakhti hai.
Ek common galti: log sochte hain bada batch hamesha better trains karta hai. Lekin bahut bade batch aksar generalise kharaab karte hain (sharp minima mein fas jaate hain) aur noise reduction bhi se slow hoti hai — matlab diminishing returns. Isliye 32 se 256 ka mid-size batch practical sweet spot hai. Ye 80/20 rule hai: thodi si tuning se maximum fayda.