TL;DR
Many problems ask for the input at which some function equals zero, but the only way to learn about is through noisy measurements of it. Stochastic approximation solves this by starting from a guess and repeatedly stepping in the direction the noisy measurement suggests, with steps that shrink over time. Under the right step sizes the guesses settle on the true zero, even though no single measurement is accurate.
Builds on: Random Variable, Expected Value, Limit of a Sequence · Leads to: Simultaneous Perturbation Stochastic Approximation, Stochastic Gradient Descent
Where it's used
- Training large models. Stochastic Gradient Descent is a stochastic approximation method. Its gradient is computed from a random mini-batch, so each step is a noisy measurement of the true gradient. The Learning Rate schedule plays the role of the step sizes in the theorem below.
- Tuning a physical process. A heater or a chemical reactor has a setting that should produce a target temperature or yield, but each reading from the sensor carries noise. An operator who adjusts the setting by small amounts, guided by the noisy readings, is doing stochastic approximation, whether or not they call it that.
- Adaptive filters and control. Signal processing systems adjust filter weights from noisy error signals on every sample. The least-mean-squares filter is a stochastic gradient update of this kind. Its step size must stay small enough for stability, which is a different requirement from the step-size conditions discussed below.
How it works
Take one tiny instance. We want the zero of , which is . Suppose we could measure exactly, but we use noise-free measurements to keep the arithmetic clean. Start at and use step sizes .
- Measure at the current guess. At the measurement is . Check: the guess is left of the zero at 2, and the measurement is negative, which says "move right".
- Step against the measurement. Update . Check: the step is 2 to the right, and the guess lands exactly on the zero.
- Measure again. At the measurement is , so the step is zero and the guess stays put. Check: is the zero, so no further move is needed.
That tiny example finishes at once, so we add noise to see the real behaviour. Keep the same and , but let each measurement be , with noise values , , , .
- Step 1. , so . Check: the noise pushed the measurement toward zero, so the step is smaller than the noise-free step of 2.
- Step 2. , so . Check: the guess reaches 2 again.
- Step 3. , so . Check: the noise made the measurement say "move left", which is wrong, so the guess leaves the zero and sits left of it at .
- Step 4. , so . Check: the guess is exactly on the zero again.
The noise made the path wander, but the shrinking step sizes pulled the guesses back. Each step is smaller than the last, so later noise cannot push the guess far.
- g(theta) = theta - 2
The math
Let be an unknown function that we can only sample. We want with . Each measurement is , where is noise with mean zero. The iteration is
with step sizes .
The step sizes control everything, and the theorem about them is the heart of the method.
Step 1 in symbols: the measurement
Write . The term is the signal, the part we want. The term is the noise. Because , the average measurement is , which is the reason a noisy measurement carries useful information on average.
Step 2 in symbols: the error
Subtract from both sides of the update:
The term pulls the error toward zero when has the right sign. If is increasing, it is positive to the right of and negative to the left, so for . The update subtracts , so on average each step moves the guess closer to . The term is the random kick that the rest of the analysis must control.
Step 3 in symbols: the step-size conditions
The Robbins-Monro theorem requires two conditions on the step sizes:
The first condition says the steps add up to an infinite total, so the guess can travel from any starting point to however far away it begins. The second says the squares of the steps add up to a finite total. The noise kicks have variance , so their total variance is finite, and the random wandering settles instead of growing without limit.
Under these two conditions, plus a bound on the noise variance and the sign and growth conditions on from Step 2, the guesses converge to in mean square and almost surely. Mean-square convergence also implies Convergence in Probability.
Step 4 in symbols: the standard choice
The choice satisfies both conditions. The harmonic series diverges, while converges to .
For a concrete link, take , so , and observe with . Set . Then the update with becomes
If is the average of the first observations, this update gives the average of the first . So the sample mean is the Robbins-Monro method applied to the simplest possible .
Worked examples
Let , with no noise, , and step sizes , .
- The first measurement is .
- The update is . The error fell from 2 to 1.
- The second measurement is .
- The update is . The error fell from 1 to 0.75.
- Each step moves the guess toward 2 by a fraction of the error. The fraction is .
Interpretation: with exact measurements the method is a step toward the zero that gets shorter as the steps shrink. The error does not reach zero in a finite number of steps unless the step size is exactly right.
The observations are , , , . We want their mean , so use , measurements , and .
- The update is .
- Step 1: . This is the average of one value, 4.
- Step 2: . This is the average of 4 and 8, which is 6.
- Step 3: . This is the average of 4, 8 and 6, which is 6.
- Step 4: . This is the average of all four values, .
- The sequence of guesses is 0, 4, 6, 6, 5. The final guess equals the sample mean exactly.
Interpretation: the Robbins-Monro update with is an online way to compute an average. Each new observation nudges the estimate by its share of the total.
A heater setting should make the temperature reading equal 2 units above a target. The reading is , so the setting that works is . Each reading is noisy. Start at and use the constant step . The noise values are at the first step, at the second, and at the third.
- Step 1: , so , and .
- Step 2: , so , and .
- Step 3: , so , and .
- The distance to the target fell from 3 to 2.05, then 1.455, then 1.0185. Each step closes about 30 percent of the gap, since the slope 3 times the step 0.1 is 0.3.
- The constant step does not meet the condition . Noise keeps adding kicks of size about forever, so the guesses will never settle exactly. They will hover near 2 within a band set by the step size.
Interpretation: a constant step gives fast early progress and a permanent wobble. Shrinking the step, for example to , trades speed for a smaller wobble.
Try it: the next step is , with noise and . What is ?
Answer: , so and , which is about . The guess is closer to 2 again.
Common mistakes and tradeoffs
It is tempting to think that noisy steps should always be small. In fact small constant steps are not enough. The step sizes must shrink, with , because a constant step keeps the noise alive forever.
It is tempting to think the steps should shrink as fast as possible. In fact shrinking too fast is a failure too. If , for example , the steps add up to a finite total, and the guesses can freeze before they reach . The condition is what guarantees arrival from any start.
It is tempting to think stochastic approximation is only gradient descent with noise. In fact it solves any root-finding problem, , and it needs only noisy values of . Gradient descent is the special case where is the gradient of a loss.
It is tempting to think that a small error in the final guess means a small error in the answer for every run. In fact the guarantee is about the limit, and any finite run has some error. The error can be reduced by averaging the guesses over time, a standard refinement.
When to use it: when each evaluation of the function is noisy or expensive, and you can afford many cheap, noisy steps. It fits online settings where data arrive one at a time. When not to use it: when the function can be evaluated exactly and cheaply, a case where Newton-Raphson or bisection finds the zero in far fewer steps. When the parameter has many dimensions, estimating a full gradient at each step is costly, and simultaneous perturbation methods reduce the cost by perturbing all parameters at once.
History
Herbert Robbins and Sutton Monro published "A Stochastic Approximation Method" in 1951. They posed the problem of finding the root of a function observed only with random error, and they proved that the iteration converges under step-size conditions like the ones above. A year later Jack Kiefer and Jacob Wolfowitz treated the related problem of finding a maximum, using finite differences in place of a direct derivative. Their work is the ancestor of the modern gradient methods used in training. The method spread through statistics and control engineering in the decades after, because it needs nothing more than noisy readings, which experiments and sensors always provide.
Recap
- The goal is an input with , where is observed only through noisy measurements.
- The update steps against each noisy measurement.
- The step sizes must satisfy , so the guess can reach the zero, and , so the noise settles.
- With and , the method computes the sample mean.
- Stochastic gradient descent is this method applied to a gradient, and the constant-step version wobbles near the answer.
Read next: Simultaneous Perturbation Stochastic Approximation, which estimates a gradient cheaply when the parameter has many coordinates, and Stochastic Gradient Descent, which applies these ideas to training.