How do full-batch gradient descent, stochastic gradient descent (SGD) and mini-batch gradient descent differ in how they compute each parameter update, and why is mini-batch SGD the standard choice in machine learning (ML)?
Linear algebra and optimisation, Stochastic optimisation
Level L1 Beginner. Length Short. Nature Th Theoretical.
What's being asked
Whether you understand the speed-versus-noise trade-off behind mini-batch training before analysing gradient variance or optimisers.
Key idea
All three update parameters by stepping opposite the loss gradient (the direction in which the loss rises fastest), , where is the learning rate and is the gradient estimate, but they differ in how many training examples go into . Full-batch uses all examples, SGD uses 1 random example, and mini-batch SGD uses a small random batch of examples (such as 32 or 64) to balance low noise with fast parallel updates.
Steps
- Describe full-batch gradient descent: it computes the average gradient over all training points for each single step. Think of grading all 100,000 exam papers before adjusting your teaching once: the direction is smooth and accurate, but each step is slow and memory-heavy.
- Describe pure SGD (batch size ): it picks 1 random example and updates immediately. It is cheap and fast per step, but one odd example can point the update the wrong way, making the path noisy and zig-zaggy.
- Describe mini-batch SGD (batch size , e.g., 32 to 256): it averages the gradient over a small random slice of examples, cancelling out much of the single-example noise while still making many updates per pass over the dataset (one epoch).
- Explain why mini-batch SGD wins in practice: GPUs (graphics processing units) process a matrix of 64 examples in almost the same wall-clock time as 1 example, so mini-batches give both hardware speed and steady progress.
Common mistakes
- Confusing batch size with an epoch: one epoch is a full pass over all training examples, which takes mini-batch steps.
- Assuming full-batch always finishes training faster because each step is cleaner; on large datasets, mini-batch SGD reaches good accuracy long before full-batch finishes a few steps.
- Forgetting to shuffle the dataset before slicing mini-batches, which can feed an entire batch of a single class and skew the updates.
How long your answer should be
1–2 minutes: compare the three batch sizes and give the noise-vs-GPU explanation.
Read this
Previous in Linear algebra and optimisation: Why does gradient descent step in the direction ?
Next in Linear algebra and optimisation: What is constrained optimisation in plain words, and why does a constraint change where the best answer is? Use a farmer who has 20 m of fencing and wants the biggest rectangular field?