§8.1.3 Batch and minibatch algorithms
The cost function and its gradient are expectations over the training set — so instead of touching every example each step, estimate them from a random subset:
Term by term
| the exact (full-batch) gradient — an average over the WHOLE training set, expensive because it evaluates every example | exact, costly | |
| the minibatch estimate: average the gradient over m randomly-sampled examples — UNBIASED if they are drawn independently | cheap estimate | |
| the estimate error falls only as 1/√m, and (on the first epoch) ĝ is an unbiased estimate of the TRUE generalization gradient | the payoff |
Why not just use a huge batch? Because of the standard error of the mean — the returns to larger batches are sublinear. Slide the batch size and watch a 100× compute increase buy only a 10× smaller error:
Because the estimate error shrinks like 1/√n, huge batches are wasteful — a fast, noisy gradient from a small batch usually converges faster per unit of computation than a slow, exact one.
The vocabulary is slippery, so pin it down:
| examples per update | notes | |
|---|---|---|
| Batch / deterministic | the ENTIRE training set | "batch gradient descent" means full-set — but confusingly "batch size" means the MINIBATCH size |
| Stochastic / online | a single example | "online" is reserved for a continual stream of never-repeated examples |
| Minibatch (stochastic) | more than one, fewer than all (32–256, powers of 2) | the default in deep learning; now often just called "stochastic". SGD is the canonical case |
Choosing the minibatch size
Larger batches give more accurate gradients (with sublinear returns) but cost memory that scales with the batch. Very small batches underutilize multicore hardware; GPUs like powers of 2 (32–256). Small batches also regularize via gradient noise — generalization error is often best at batch size 1, though that needs a small learning rate and many steps. Crucially, minibatches must be drawn randomly: if the dataset is ordered (e.g. all of patient A, then patient B…), shuffle it once and store it shuffled, or every minibatch is biased. On the first epoch each minibatch is an unbiased estimate of the true generalization gradient; later epochs re-sample seen data and become biased.
§8.2 Challenges in neural network optimization
Traditionally, machine learning sidestepped the difficulty of general optimization by carefully designing convex objectives. Neural networks force us into the general non-convex case — and even convex optimization has its own traps. The next sections catalog the obstacles, starting with one that appears even in convex problems.
§8.2.1 Ill-conditioning
The most prominent convex-and-beyond obstacle is ill-conditioning ill-conditioning (of the hessian) When high curvature forces a tiny learning rate: a GD step of −εg adds ½ε²gᵀHg − εgᵀg to the cost, so learning stalls (even small steps raise the cost) once the ½ε²gᵀHg curvature term outgrows εgᵀg, despite a strong gradient. defined in ch. 8 — open in glossary of the Hessian. A second-order Taylor expansion predicts what a gradient step of does to the cost:
Term by term
| the first-order GAIN: moving along −g should reduce the cost by this much | the win | |
| the second-order CURVATURE penalty: it grows with how sharply the cost curves along g (the Hessian) | the tax | |
| when the curvature term overwhelms the gain, even a tiny step RAISES the cost — so ε must shrink and learning stalls despite a strong gradient | ill-conditioned |
The tell-tale sign: the gradient norm stays large while grows by an order of magnitude. In fact the gradient norm can increase throughout a perfectly successful training run (fig 8.1) — learning succeeds not by reaching a small gradient, but despite a growing one:
Newton’s method handles ill-conditioning well in convex problems, but — as later sections argue — needs significant modification before it is safe for neural networks. Next: local minima, the saddle points that actually dominate, cliffs, and vanishing/exploding gradients — the landscape of obstacles.
Check yourself — minibatches and ill-conditioning
1.Why do larger minibatches give diminishing returns for estimating the gradient?
2.In BatchSizeLab, going from n = 64 to n = 256 (4× the batch) does what to the gradient error?
3.The terminology is confusing. What does 'batch gradient descent' mean, versus 'batch size'?
4.A gradient step of −εg changes the cost by ≈ ½ε²gᵀHg − εgᵀg. When is ill-conditioning a problem?
5.Figure 8.1 shows the gradient norm INCREASING throughout a successful training run. What does this illustrate?