Stochastic Gradient Descent
Stochastic Gradient Descent (SGD) is an iterative optimization algorithm that minimizes an objective function by taking steps in the direction of the negative gradient estimated from one or a few randomly sampled data points rather than the full dataset. Key result: despite using noisy gradient estimates, SGD converges (in expectation) to a minimizer for convex problems and to good solutions for non-convex ones, at vastly lower per-iteration cost. Where it applies: machine learning, deep neural network training, large-scale convex optimization, online learning. Who/when: rooted in the Robbins–Monro stochastic approximation method (1951); now the workhorse of modern deep learning.
The true gradient of an average is the average of gradients. Therefore a single randomly chosen gradient is an unbiased estimator of the true gradient: . You can replace an expensive exact gradient with a cheap noisy one and still, on average, move downhill. Trade per-step accuracy for a massive increase in the number of steps — and win.
Formal Statement
We seek to minimize an objective that is a finite average of component functions:
Derivation hint: In supervised learning, is the loss of model on the -th training pair ; the average is the empirical risk. The symbols:
- — the parameter vector (weights) being optimized, in .
- — the full objective (empirical risk / total loss).
- — the loss contributed by the -th data point.
- — number of training examples.
- — number of parameters.
The SGD update rule at iteration samples an index uniformly at random from and steps:
Derivation hint: Replace the full gradient in ordinary gradient descent by the single-sample estimate . Here is the learning rate (step size) at step . The mini-batch variant averages over a random subset of size :
Derivation hint: Averaging unbiased estimators keeps the estimator unbiased but divides its variance by (under independent sampling).
If is sampled uniformly from , then the stochastic gradient is unbiased:
Derivation hint: Expectation over a uniform discrete index is the arithmetic mean of the values; linearity of the gradient turns the mean of gradients into the gradient of the mean.
Let each be convex and the stochastic gradients have bounded second moment . Let be a minimizer and the iterates with . Using a decreasing step size, the averaged iterate satisfies:
with constant step , minimized at giving an rate. Derivation hint: Expand , take conditional expectation, apply convexity , telescope, and divide by .
Why It Holds / Derivation
Step 1 — One-step distance recursion. Start from the squared distance to the optimum and substitute the update [2]:
Expanding the square:
Step 2 — Take conditional expectation. Conditioning on and using unbiasedness [4], , and the bounded-moment assumption:
Step 3 — Apply convexity. For convex , . Substituting and rearranging:
Step 4 — Take total expectation and telescope. Summing , the distance terms telescope:
Step 5 — Use Jensen and average. Since is convex, . Dividing through by yields exactly [5].
∎The mathematical ancestor of SGD is the Robbins–Monro stochastic approximation method. Herbert Robbins (1915–2001), an American statistician, and his student Sutton Monro published "A Stochastic Approximation Method" in the Annals of Mathematical Statistics (1951). They studied the problem of finding the root of a function that can only be observed with random noise — solving using noisy measurements. Their iteration , with step sizes satisfying and , is precisely the convergence condition that modern SGD learning-rate schedules respect. Robbins also co-founded the field of empirical Bayes and made deep contributions to sequential analysis. SGD is the gradient-flavored special case of their general scheme: estimating the zero of the gradient (i.e., a stationary point) from noisy gradient observations.
Building Intuition
Picture a hiker descending a foggy mountain at night. Full-batch gradient descent is a hiker who, before each step, painstakingly surveys the entire surrounding terrain to find the steepest downhill direction — accurate but agonizingly slow. SGD is a hiker who glances at just one patch of ground near their feet and steps that way immediately. Any single glance might point slightly wrong, but over many quick steps the errors average out and the hiker descends — far faster overall because they take a thousand quick steps in the time the careful hiker takes one. The noise is not purely harmful. Near a narrow crevice (a sharp minimum), the random jitter knocks the SGD hiker out, so they tend to settle in wide, flat valleys (flat minima), which in machine learning correlate with better generalization. The learning rate controls step length: large early steps cover ground fast; shrinking later steps let the hiker settle precisely. This is why schedules like or "warmup then decay" work — they balance exploration against convergence.
Worked Examples
Given: Fit by minimizing squared error. Component loss . Current parameters , . Sampled point . Learning rate .
Step 1 — Prediction and residual.
Step 2 — Component gradient.
Step 3 — SGD update via [2].
Step 4 — Check. New prediction , closer to target than the old . ✓
Given: A convex problem with , gradient-norm bound , and a budget of iterations. Use the optimal constant step from Theorem [5].
Step 1 — Optimal learning rate.
Step 2 — Resulting optimality gap. Plugging into [5] (both terms equal at the optimum):
Step 3 — Scaling check. To halve the gap to we need to double, i.e. — four times as many iterations. The rate is the price of stochasticity.
Common Misconceptions
"SGD converges to the exact minimum." With a constant learning rate, SGD does not converge to ; it converges to a noise ball around it whose radius scales like , where is the gradient noise scale. To reach the exact minimizer you must decay the step size (Robbins–Monro conditions: , ). A constant rate gives fast initial progress but residual oscillation.
"A bigger batch is always better." Larger batches reduce gradient variance and allow larger learning rates, but they (a) cost more per step, (b) often generalize worse (the "large-batch generalization gap"), and (c) give diminishing returns — variance drops only as . There is no universal optimum; the right batch size depends on hardware, problem, and the noise's regularizing benefit.
Suppose you sample indices non-uniformly — say always picking the data points with the largest current loss (a naive "hard mining" scheme) — but still average plain gradients. Then , because the sampling probabilities are not . The estimator becomes biased, and the convergence proof in [4]–[5] collapses: SGD may converge to the wrong point or not at all. To fix importance/non-uniform sampling you must reweight each gradient by to restore unbiasedness:
Connections
SGD sits at the crossroads of several fields. It is a noisy special case of Gradient Descent, inheriting its first-order, derivative-based philosophy but trading exactness for speed. Its theoretical foundation is Stochastic Approximation (Robbins–Monro), and its analysis draws on Convex Optimization (for the convex rate [5]) and Martingale Theory (for almost-sure convergence proofs). In deep learning, the gradients are computed by Backpropagation, making SGD the optimizer that consumes what backprop produces. The continuous-time limit of SGD is a Stochastic Differential Equation — an overdamped Langevin diffusion — which links it to statistical physics and to Markov Chain Monte Carlo sampling. Variants like momentum connect it to Heavy-Ball Method and Nesterov acceleration, while adaptive schemes such as Adam blend it with per-coordinate scaling.
Real-World Applications
Historical Development
Subtleties & Limits
Several deep questions about SGD remain only partially understood. (1) Why does SGD generalize so well in deep, overparameterized networks? The "implicit regularization" / "flat-minima" hypothesis — that SGD noise biases solutions toward flat regions with low test error — is supported empirically but lacks a complete theory. (2) Non-convex convergence guarantees are weak: for general non-convex , SGD provably reaches only an approximate stationary point ( small), not a global minimum, yet in practice it finds excellent solutions. (3) The optimal learning-rate schedule — warmup, cosine decay, cyclic rates — is largely heuristic; principled, problem-adaptive schedules are an active research frontier. (4) The role of the noise covariance: the structure (not just magnitude) of SGD's gradient noise appears to matter for which minima are selected, and characterizing this anisotropic noise remains open. (5) Edge of stability: modern training often runs at learning rates where classical theory predicts divergence, yet loss still decreases — a phenomenon ("edge of stability") not explained by [5].
See Also
Gradient Descent · Stochastic Approximation · Convex Optimization · Backpropagation · Adam Optimizer · Momentum and Nesterov Acceleration · Variance Reduction Methods · Empirical Risk Minimization · Langevin Dynamics