advanced28 min studyLesson 48 in Mathematics

Stochastic gradient methods

Separate conditional unbiasedness, variance, and step-size schedules when replacing an expensive gradient with a random estimate.

On this page

What you’ll understand

  • State conditional unbiasedness relative to the iterate history.
  • Calculate one-step mean and variance for a noisy quadratic update.
  • Explain variance reduction by independent averaging and the limits of constant steps.

A full gradient can require inspecting an entire dataset or averaging over an enormous collection of possible outcomes. Stochastic gradient methods trade an exact expensive direction for a cheaper random one. The randomness is useful only under stated assumptions: an estimate can be unbiased yet extremely noisy, or precise but systematically biased. Understanding these distinctions explains why a training curve can jump upward even while a method makes progress in expectation.

Condition on what the algorithm already knows

Let the history contain all previous iterates and sampled information. A standard stochastic-gradient model requires the next estimate to have conditional mean equal to the true gradient at the current iterate. This is stronger and more useful than merely saying that the error averages to zero over an unspecified experiment. The current iterate depends on earlier randomness, so the relationship between a new sample and that history is central to the analysis.

For a finite sum of losses, sampling an index uniformly and taking that term's gradient gives an unbiased estimate of the average gradient, provided sampling is appropriate for the conditioned history. Nonuniform sampling usually needs inverse-probability weighting. Sampling without replacement across an epoch can be beneficial, but its conditional behavior differs from independent sampling, so a proof assuming fresh independent indices should not be applied without checking the change in sampling mechanism.

xk+1=xk−ηkgk,E[gk∣Fk]=∇f(xk),E[∥gk−∇f(xk)∥2∣Fk]≤σ2x_{k+1}=x_k-\eta_k g_k,\qquad \mathbb E[g_k\mid\mathcal F_k]=\nabla f(x_k),\qquad\mathbb E[\|g_k-\nabla f(x_k)\|^2\mid\mathcal F_k]\leq\sigma^2
The history σ-algebra ℱₖ makes xₖ known. Conditional unbiasedness and a finite variance bound are separate assumptions about the gradient estimator.↔ Scroll wide equations horizontally.

Descent competes with noise

Apply the smoothness upper bound to a random step and then take conditional expectations. The exact-gradient descent term survives, while a variance penalty appears with the square of the step size. For a fixed nonzero step and persistent noise, this penalty generally prevents arbitrary precision. The iteration may enter a neighborhood rather than settle at one exact point. Smaller steps reduce the neighborhood but also reduce the speed of meaningful movement.

Averaging b independent, identically distributed unbiased estimates divides their variance by b. Correlation can remove that benefit, and a larger batch costs more evaluations. In classical stochastic-approximation settings, decreasing schedules with divergent total step length and finite total squared step length help balance persistent exploration against accumulated noise. Those two sums alone are not a universal convergence theorem: regularity, stability or boundedness, and noise conditions still have to be supplied.

E[f(xk+1)∣Fk]≤f(xk)−ηk(1−Lηk2)∥∇f(xk)∥2+Lηk2σ22\mathbb E[f(x_{k+1})\mid\mathcal F_k]\leq f(x_k)-\eta_k\left(1-\frac{L\eta_k}{2}\right)\|\nabla f(x_k)\|^2+\frac{L\eta_k^2\sigma^2}{2}
This conditional bound assumes L-smoothness, an unbiased estimator, and the stated variance bound. A realized single step can increase the objective even when the expected bound is favorable.↔ Scroll wide equations horizontally.

Identify what a deterministic picture leaves out

For the unit quadratic, writing a stochastic gradient as x plus zero-mean noise makes the distinction especially clear. The conditional mean contracts like ordinary gradient descent, but the next squared error includes an extra variance contribution. A mean trajectory near zero therefore does not imply that individual runs are near zero. Reporting only averaged parameter coordinates can hide substantial fluctuations and poor realized objective values.

The interactive lab contains no random sampling: it displays the exact deterministic recurrence. Use it to predict the conditional mean of one stochastic update at the same x and η, then calculate the extra variance below. It cannot demonstrate stochastic fluctuations, minibatch variance, or a stochastic convergence theorem. In actual experiments, record seeds, sampling rules, learning-rate schedules, and distributions across runs so the empirical claim matches the mathematical model.

The mean moves closer while uncertainty remains

For f(x)=x2/2f(x)=x^2/2 at x=2, use g=x+ξg=x+\xi with equally likely noise ξ=1\xi=1 or −1-1. Take η=1/2 and compute the next mean, variance, and expected objective.

  1. If ξ=1, the gradient estimate is three and the next point is 2−(1/2)3=0.52-(1/2)3=0.5. If ξ=−1, the estimate is one and the next point is 2−(1/2)1=1.52-(1/2)1=1.5. Both outcomes have probability one half.

  2. The conditional mean is (0.5+1.5)/2=1(0.5+1.5)/2=1, matching the deterministic mean update (1−1/2)2=1(1-1/2)2=1. Deviations from the mean are −0.5 and 0.5, so the variance is 0.25.

  3. The expected objective is [(0.52/2)+(1.52/2)]/2=0.625[(0.5^2/2)+(1.5^2/2)]/2=0.625. Evaluating f only at the mean would give 0.5 and miss the variance contribution 0.25/2=0.1250.25/2=0.125.

The result

The average point contracts to 1, but expected objective is 0.625 because noise leaves variance. Function of the mean and mean function value are different.

Explore the model

Interactive lab

Interactive lab · optimization

A deterministic conditional-mean baseline

Set x₀=2 and η=0.5, then predict the first exact update before stepping. Compare its value with the hand-computed noisy example. The lab has no random samples or stochastic gradient estimates; only the one-step conditional mean shares this update formula.

A deterministic conditional-mean baselineGradient descent on f(x) = x²/2: xₙ = (1 − η)ⁿx₀. Playback advances two discrete iterations per second. Values outside |x| ≤ 4 are explicitly reported. Current readings: Position x0: 2; Objective x²/2: 2; Iteration behavior: Stable step. All parameters are adjustable with the labeled controls below.−4−202402.174.356.528.7Parameter xf(x) = x²/2n = 0
ObjectiveDiscrete iterate
Position x0
2
Objective x²/2
2
Iteration behavior
Stable step
n = 0 · t = 0 s

Gradient descent on f(x) = x²/2: xₙ = (1 − η)ⁿx₀. Playback advances two discrete iterations per second. Values outside |x| ≤ 4 are explicitly reported. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.

Look forA deterministic mean update omits the variance that contributes to expected squared error and expected objective value.

Check your understanding

Averaging four independent unbiased gradient estimates with variance σ² each produces what variance for their average?

Try it yourself

Repeat the noisy update calculation at x=0 with η=0.2 and noise ξ=±1 equally likely. Compute the next mean and expected objective, and explain why zero is not absorbing.

Take a moment to make a prediction or work it out on paper. Open a hint when you need one.

Give me a hint

The true gradient is zero, but each noisy gradient estimate is nonzero. The two possible next points are symmetric about zero.

Compare with the solution

The next points are −0.2 and 0.2, so their mean is zero. Each objective value is 0.22/2=0.020.2^2/2=0.02, making the expected value 0.02 as well. Persistent gradient noise moves individual iterates away from the optimum despite zero conditional mean; a constant step does not make the minimizer absorbing in this model.

Take it with you

  • Conditional unbiasedness refers to the current iterate and the algorithm's history.
  • Variance contributes a step-size-squared penalty even when the mean direction is correct.
  • Independent averaging, diminishing steps, and repeated-run reporting address different aspects of stochastic behavior.

Read further

Original sources and deeper explanations to follow at your own pace.

Optional progress, saved in this browser when available. Revisit any lesson at any time.

Lesson not marked complete.