Mini-Batch Gradient Descent
Mini-Batch Gradient Descent is an optimization algorithm that updates model parameters using the gradient of a loss function estimated on small, randomly selected subsets ("mini-batches") of the training data. Key result: it combines the low-variance updates of full-batch gradient descent with the computational efficiency and noise-driven exploration of stochastic gradient descent, making it the de facto training method for deep neural networks. Applies to large-scale machine learning, deep learning, and any empirical-risk-minimization problem. Who/when: crystallized in the 2000s–2010s deep learning era, building on Robbins–Monro stochastic approximation (1951).
The true gradient is an average over all training examples. Any unbiased random subset gives an unbiased estimate of that average whose variance shrinks like . Mini-batch gradient descent exploits this: pick a batch size large enough to tame variance and saturate hardware parallelism, but small enough that you take many cheap, frequent steps per pass through the data. You trade a little gradient accuracy for vastly more updates — and the leftover noise often helps.
Formal Statement
Let the training set be with per-example loss . The empirical risk (full objective) is
Derivation hint: this is the sample average of per-example losses; it estimates the true risk . A mini-batch of size is drawn (usually without replacement) from the training indices. The mini-batch gradient estimate is
Derivation hint: replace the average over all examples in with an average over the sampled examples. The update rule at iteration , with learning rate , is
Derivation hint: standard gradient-descent step but with the noisy estimate substituted for the exact gradient .
Symbols: parameters; total examples; batch size; the batch at step ; learning rate (step size); mini-batch gradient. Special cases: is full-batch gradient descent; is stochastic gradient descent (SGD).
If the batch indices are drawn uniformly at random, then the mini-batch gradient is an unbiased estimator of the full gradient:
Derivation hint: linearity of expectation; each index has equal probability of inclusion, so its average loss-gradient equals the population average. Moreover, for sampling with replacement (or large- approximation), the per-coordinate variance scales as
where is the variance of a single example's gradient. Derivation hint: variance of the mean of i.i.d. samples is the single-sample variance divided by .
Why It Holds / Derivation
Step 1 — Setup. Let contain indices each drawn uniformly from (with replacement for simplicity). For a single draw , the probability .
Step 2 — Expectation of one term. For any single sampled index ,
Step 3 — Expectation of the average. By linearity,
establishing Eq. [4].
Step 4 — Variance. Since the draws are i.i.d. with single-draw variance ,
giving Eq. [5].
Step 5 — Without-replacement correction. When sampling without replacement from a finite set of size , multiply by the finite-population correction factor . For this is , recovering the law.
∎Although mini-batch GD is a 21st-century computational staple, its theoretical bedrock is the Robbins–Monro stochastic approximation scheme. Robbins (a statistician and topologist) and Monro showed that you can find the root of an unknown function using only noisy measurements, provided the step sizes satisfy and . This established that noisy gradient updates can converge — the licence under which all of SGD and mini-batch GD operate.
Building Intuition
Imagine you want the average opinion of a city of people, but polling everyone takes a day. Polling one person (SGD) is instant but wildly unrepresentative; polling everyone (full-batch) is accurate but glacial. Polling a random people (mini-batch) gives an answer that's almost as accurate as the full poll — its error shrinks like — but costs almost nothing. You can re-poll every few minutes and steadily refine your estimate of where to move. Now picture the loss landscape as a foggy mountain. Full-batch descent walks downhill perfectly but pauses forever at every flat ledge (saddle point) and small dip (local minimum). Mini-batch's gradient jitter is like an occasional gust of wind: it knocks you off ledges and out of shallow dips, helping you find deeper valleys — while still trending downhill on average.
Worked Examples
Given: Model (single weight, no bias). Squared loss , so . Current , learning rate . A mini-batch of :
Steps: 1. Per-example gradients at :
2. Mini-batch gradient (Eq. 2): 3. Update (Eq. 3):
Answer:
The weight increased because both predictions were too low (residuals negative), so the negative gradient pushes up.
Given: Suppose the single-example gradient (a scalar) has standard deviation at the current . Compare the standard deviation of the gradient estimate for , , (sampling with replacement, large).
Steps: 1. From Eq. [5], , so . 2. 3. 4.
Answer:
Note the diminishing return: going from cuts noise 8×; going (4× the compute) only halves it. This law motivates moderate batch sizes.
Common Misconceptions
A common belief is "larger → better, since the gradient is more accurate." But:
- Variance only falls like , so doubling doubles compute for a noise reduction — diminishing returns.
- Very large batches lose the beneficial noise that helps escape saddle points and shallow minima, often converging to sharper minima that generalize worse (the "large-batch generalization gap").
- The learning rate must usually be rescaled with batch size (e.g., the linear scaling rule: ). Forgetting this makes large-batch training diverge or stall.
There is no universally optimal ; common choices are 32–512, tuned empirically.
It is tempting to treat each mini-batch step as "downhill on ." It is only downhill in expectation. Consider with gradients and at some point. The true gradient is — pointing in . But a mini-batch of just gives , moving the parameters in the direction, completely orthogonal to (and uncorrelated with) the true descent direction. Individual mini-batch steps can temporarily increase the full loss; only their average trends downward.
Connections
Mini-batch GD sits at the center of a family of methods. It generalizes Stochastic Gradient Descent () and Full-Batch Gradient Descent (). Its noisy updates are analyzed through Stochastic Approximation (Robbins–Monro) and modeled as a continuous-time SGD diffusion. Practically, it is the base on which Momentum (Optimization), Adam Optimizer, and RMSProp build adaptive or accelerated variants. Its computation relies on Backpropagation to obtain efficiently, and its objective is the Empirical Risk Minimization framework. The implicit regularization it provides connects to Generalization (Machine Learning) and the flat-vs-sharp-minima debate.
Real-World Applications
Historical Development
Subtleties & Limits
Several questions about mini-batch GD remain active research:
- Optimal batch size theory: Why moderate batches generalize better than huge ones — the precise mechanism linking gradient noise to flat minima and generalization — is not fully understood.
- SGD as approximate inference: Whether mini-batch noise can be rigorously characterized as sampling from a Bayesian posterior (the "SGD-as-MCMC" view) is only partially resolved.
- Adaptive batch sizing: Principled, automatic schedules that grow during training (to reduce noise as you approach a minimum) lack a complete theory.
- Non-convex convergence rates: Tight, instance-dependent bounds for mini-batch GD on the highly non-convex, over-parameterized landscapes of deep nets remain open.
- Heavy-tailed gradient noise: Empirically, mini-batch gradient noise is often heavy-tailed (non-Gaussian), challenging the standard finite-variance assumption behind Eq. [5] and its diffusion approximations.
See Also
Stochastic Gradient Descent · Gradient Descent · Stochastic Approximation · Adam Optimizer · Backpropagation · Empirical Risk Minimization · Generalization (Machine Learning) · Learning Rate Scheduling