Estimating the gradient from a few samples
Most fitting problems minimise an average over data, , for instance squared errors over observations. The exact gradient needs all terms at every step, which is too slow when is millions of ticks. Stochastic gradient descent draws a random mini-batch of observations and uses their average gradient instead. This estimate is unbiased, meaning that on average it equals the true gradient.
The price of the shortcut is noise. The variance of the batch gradient falls like , so halving its standard deviation needs a four times larger batch, a steeply diminishing return. One epoch is a full pass over the data and holds updates. With a constant step the iterates never settle: they keep jittering in a small ball around the minimum, because even at the minimum the batch gradient is not zero. The fix is a step that shrinks. The classical Robbins-Monro conditions ask that , so the walk can travel as far as needed, and , so the noise dies out. The schedule satisfies both.
- Unbiased: a random batch gradient equals the full gradient on average.
- Noisy: variance , so four times the batch halves the standard deviation.
- Shrinking steps: and , e.g. , give convergence.
The unbiasedness above relies on drawing the batch at random. A batch of consecutive days comes from one market regime, so its gradient is biased toward that regime, and training on the data in time order can drift with the regime. Shuffle the sample indices at the start of each epoch. When the order itself matters, as in a time-series model, keep the sequence inside each example and shuffle the examples.
Lab · what's graded
7 tasks · 100 pts- The full gradient15 pts
- The noise of one sample15 pts
- The noise of a batch15 pts
- Updates per epoch15 pts
- A step schedule that converges15 pts
- The mini-batch loop10 pts
- Why a constant step does not settle15 pts