Stochastic Optimization — SGD and Variants

Decision Sciences
Year
1951 (SGD); 2014 (Adam)
Type
Gradient-based iterative optimization

What does it do?

Stochastic optimization refers to iterative methods that minimise an objective function using gradients computed on randomly sampled examples or mini-batches rather than on the full dataset at every step.

Robbins and Monro introduced the underlying stochastic approximation idea in 1951. The approach became the basis for training large machine-learning models through variants such as SGD with momentum, AdaGrad, RMSProp and Adam. This page focuses on the stochastic mini-batch setting; full-batch methods are covered on the gradient-descent page.

The intuition behind the method

Imagine you want to find the lowest point in a vast hilly landscape, but measuring the slope of the entire landscape at every step is prohibitively expensive. Stochastic optimization works by measuring the slope at a small random patch of ground instead, taking a step downhill, and repeating the process many times. Each individual step is noisier than measuring the whole landscape, but the sheer number of cheap steps gets you to the bottom faster than a few expensive exact measurements would. Adaptive variants like Adam go further by remembering how bumpy each direction has been and scaling their steps accordingly.

History

Robbins and Monro (1951) introduced a stochastic approximation method for locating the point where the unknown expected response to a noisy experiment equals a given constant, by running successive experiments at levels that converge in probability to that point. Stochastic gradient descent applies the same idea of iterating with noisy estimates to minimising an expected loss. Duchi et al. introduced AdaGrad in 2011, Tieleman and Hinton proposed RMSProp in 2012, and Kingma and Ba introduced Adam, posted on arXiv in 2014 (arXiv:1412.6980) and published at ICLR 2015.

When to use it

Use stochastic optimization when you need to minimise a differentiable (or sub-differentiable) loss over a dataset large enough that computing exact gradients at every step is impractical. Typical cases are training neural networks and fitting large linear or generalised linear models by gradient methods. It is a poor fit when the objective provides no usable gradient or subgradient, because the method depends on one. If the dataset is small enough that full-batch gradient descent is affordable, the extra noise from mini-batches may not be worth it, and plain gradient descent is the simpler choice. Learning-rate selection is critical: a rate that is too large causes divergence, and one that is too small slows convergence, so the choice should be checked against the loss curve. Classical convergence guarantees assume a convex objective and unbiased gradient estimates (as with uniform random sampling of examples), together with a decreasing step-size schedule in the Robbins-Monro spirit: step sizes whose sum diverges while the sum of their squares converges. For non-convex problems such as deep networks, these guarantees do not apply directly and practice relies on empirical tuning.

Limitations and considerations

  • The learning rate is a critical hyperparameter: too large a value makes the loss diverge, and too small a value makes progress slow.
  • With a fixed step size, mini-batch noise keeps the iterates fluctuating around the optimum rather than settling on it, so the final parameters are usually not an exact minimiser.
  • For non-convex objectives there is no general guarantee of reaching a global minimum. Saddle points and poor local minima can stall progress, and gradient noise and momentum only partly mitigate this.
  • Adaptive methods such as Adam can reach solutions that generalise differently from those found by SGD with momentum. Which generalises better depends on the task and on how carefully each optimiser is tuned, so no general ranking is assumed here.

Source conditions do not replace independent scientific review or validation by an analysis engine.

Strengths

  • The cost of each update depends on the mini-batch size rather than the full dataset size, so the method can be applied to datasets too large for full-gradient updates.
  • Mini-batch noise is sometimes observed to help iterates move away from saddle points and shallow minima, but this is a heuristic tendency, not a guarantee.
  • Adaptive variants (AdaGrad, RMSProp, Adam) rescale each parameter's step using running gradient statistics, which reduces dependence on a single global step size compared with plain SGD, though a learning rate is still required.
  • The update rule is simple to implement and applies to any model whose gradients can be computed on a batch.

Applications

  • Training neural networks, from small models to large deep architectures.
  • Fitting large linear and generalised linear models where full-batch gradient computation is too expensive.
  • Online learning, where data arrive as a stream and the model is updated incrementally.
  • Policy-gradient methods in reinforcement learning, where Adam and RMSProp are commonly used optimisers.
  • Training embedding and recommendation models on large, sparse datasets.

How it works

How it works

1

The parameter vector is initialised — typically with small random values. The learning rate (step size) and, for adaptive variants, moment decay rates are set as hyperparameters before training begins. These choices have a large effect on convergence speed and final performance.

2

At each iteration a mini-batch — a small random subset of the full dataset — is drawn. Mini-batch size controls a trade-off: smaller batches introduce more gradient noise but update parameters more frequently and often generalise better, while larger batches give lower-variance estimates at higher per-iteration cost.

Formula
D^{(k)} \leftarrow S \text{ random data points drawn from } D
3

The gradient of the objective (loss) function with respect to the current parameters is computed using the mini-batch. For adaptive optimisers, first and second moment estimates of the gradient are also maintained across iterations to track per-parameter scale and curvature information.

Formula
g^{(k)} = \nabla_z F\big(D^{(k)}\big)\big|_{z^{(k-1)}}
4

Parameters are updated by moving opposite to the gradient direction, scaled by the learning rate. Adaptive variants (AdaGrad, RMSProp, Adam) divide each parameter's step by a running estimate of past gradient magnitudes, effectively giving larger steps to infrequently updated parameters and smaller steps where the gradient has been large and consistent.

Formula
z^{(k)} = z^{(k-1)} - \eta^{(k)}\, g^{(k)}
5

The process repeats — sampling, gradient computation, and parameter update — until a convergence criterion is met: loss ceases to decrease, a maximum number of iterations is reached, or validation performance stops improving. Early stopping on a held-out validation set guards against overfitting.

Common pitfalls

  • A learning rate set too high makes the loss diverge or oscillate; monitor the loss curve from the first epochs.
  • Not reshuffling the data between epochs can make successive mini-batches follow a fixed order, which biases the gradient estimates over training.
  • Keeping the learning rate fixed throughout training often leaves performance on the table; warm-up and decay schedules such as cosine decay are common remedies.
  • Comparing optimisers fairly requires matching the total number of gradient evaluations (or wall-clock time), not just the number of epochs.
  • In sparse-feature settings, Adam's per-parameter scaling can behave differently from plain SGD and may suppress small but consistent gradient signals. Compare optimisers empirically rather than assuming the adaptive one is better.

Frequently asked questions

Which optimiser should I choose: SGD, Adam, or something else?

Adam is a widely used default for deep learning because it often needs less step-size tuning than plain SGD. SGD with momentum and a tuned learning-rate schedule is another common choice. Which generalises better depends on the task and on how carefully each is tuned, so compare them empirically. AdaGrad was designed with sparse gradients in mind, and RMSProp is often used for recurrent networks.

How do I choose the learning rate?

The learning rate is usually the most important hyperparameter. Start from the defaults recommended for your framework or model family, or run a sweep or learning-rate range test over a logarithmic scale, and watch the loss curve. A warm-up phase followed by cosine or step decay often improves results over a fixed rate.

What mini-batch size should I use?

Batch size is usually limited by memory and affects how noisy the gradient estimates are. Smaller batches add gradient noise and allow more frequent updates. Larger batches reduce noise but may generalise less well and usually call for a larger learning rate. A common starting heuristic is the linear scaling rule: scale the learning rate in proportion to the batch size when changing it.

How do I know when to stop training?

Monitor validation loss and stop when it has not improved for a set number of consecutive epochs, a technique called early stopping. This is more reliable than stopping after a fixed number of epochs and helps guard against overfitting.

Related methods

Sources

  1. Robbins, H. & Monro, S. (1951). A Stochastic Approximation Method. Annals of Mathematical Statistics, 22(3), 400-407.

    Open DOI reference
  2. Kingma, D.P. & Ba, J. (2015). Adam: A Method for Stochastic Optimization. International Conference on Learning Representations (ICLR 2015).

    Open publication reference
  3. A Course in Machine Learning, p. 173