Stochastic Gradient Descent

Stochastic Gradient Descent (SGD) extends batch gradient descent by approximating the total loss function with the loss of a single sampled example . This drastically reduces computational cost while maintaining an unbiased estimate of the true loss gradient. Let denote the unknown probability distribution over test examples. Assuming that training data comes from the same distribution, then we can express the error function as

where is the pointwise loss function, and is a parametric transformation on defined by parameters .

In batch gradient descent, we compute the gradient over all training examples in each iteration. To decrease runtime, SGD replaces the true gradient with an unbiased estimate based on a single unformly sampled training point:

and runs in time per iteration, since only one example contributes to the gradient. To reduce bias and improve convergence, we can iterate through the entire dataset once per epoch while shuffling the order of samples at the beginning of each epoch. Like batch gradient descent, this still processes all N samples per epoch ( total), but unlike BGD - which performs a single update per epoch - SGD updates the weights after every sample. These frequent, low-cost updates allow SGD to reach low-loss regions faster in practice, even though the total computational complexity per epoch is similar.

A middle ground between the accuracy of BGD and the speed of SGD is Mini-Batch SGD, which takes a random sample of data points and performs the update rule

which runs in per iteration, such that . In practice, we shuffle the dataset at the beginning of each epoch, divide it into mini-batches, and perform one update per batch. Without shuffling, mini-batches may contain correlated samples, slowing or biasing convergence.