Core idea. Many reinforcement learning algorithms are noisy versions of deterministic fixed-point or optimization algorithms. Stochastic approximation gives a mathematical language for recursions of the form
where \(h\) is the mean drift, \(M_{t+1}\) is random noise with conditional mean zero, and \(\alpha_t\) is a learning rate. The central question is: when does a noisy recursive algorithm behave like the deterministic differential equation \(\dot \theta=h(\theta)\)?
17.1 Learning goals
After reading this chapter, students should be able to:
explain the Robbins-Monro stochastic approximation idea;
identify the mean drift and noise terms in an iterative algorithm;
state and interpret the classical step-size conditions;
define martingale-difference noise in the RL setting;
connect stochastic approximation to fixed-point iteration and gradient descent;
explain the ODE method at an intuitive mathematical level;
analyze simple one-dimensional and linear stochastic approximation recursions;
write TD learning and Q-learning as stochastic approximation algorithms;
compare diminishing and constant learning rates;
use AI tools to audit convergence claims, assumptions, and implementation details.
17.2 14.1 Why stochastic approximation matters in RL
The previous chapters introduced exact and sample-based algorithms. In dynamic programming, we often update values by applying a deterministic Bellman operator. For example, value iteration uses
\[
V_{k+1}=T V_k.
\]
In sample-based reinforcement learning, the algorithm usually cannot compute the exact conditional expectation inside the Bellman operator. Instead, it observes one random transition and makes a noisy update. For example, tabular TD(0) updates
This update is not the exact Bellman update. It is a noisy estimate of a Bellman update. Stochastic approximation explains why repeated noisy updates can still converge.
The term \(M_{t+1}\) is called a martingale-difference noise term.
17.3.1 Interactive: Noisy root finding
A stochastic approximation update moves toward the root of \(h(\theta)=0\) using noisy observations of \(h(\theta)\). Small learning rates reduce noise but move slowly; large learning rates move quickly but may fluctuate.
17.3.2 Example: one-dimensional stable root
Consider
\[
h(\theta)=a-\theta.
\]
The unique root is \(\theta^*=a\). A noisy update has the form
The first condition says that learning never stops too early. The second says that the accumulated variance from noise remains controlled.
A common family is
\[
\alpha_t=\frac{c}{(t+1)^p}.
\]
For this family,
\[
\sum_{t=0}^{\infty}\alpha_t=\infty
\quad \text{if and only if} \quad p\leq 1,
\]
while
\[
\sum_{t=0}^{\infty}\alpha_t^2<\infty
\quad \text{if and only if} \quad 2p>1.
\]
Thus both classical conditions hold when
\[
\frac{1}{2}<p\leq 1.
\]
17.4.1 Interactive: Step-size schedules
This figure compares several learning-rate schedules. A good diminishing schedule keeps \(\sum_t \alpha_t\) large while making \(\sum_t \alpha_t^2\) finite.
import pandas as pdimport numpy as npT =10000schedules = {"1/(t+1)^0.4": lambda t: 1/ ((t +1) **0.4),"1/(t+1)^0.7": lambda t: 1/ ((t +1) **0.7),"1/(t+1)": lambda t: 1/ (t +1),"0.05 constant": lambda t: 0.05,}rows = []for name, rule in schedules.items(): alphas = np.array([rule(t) for t inrange(T)]) rows.append({"schedule": name,"sum alpha up to T": alphas.sum(),"sum alpha^2 up to T": np.square(alphas).sum(),"alpha_T": alphas[-1], })pd.DataFrame(rows)
schedule
sum alpha up to T
sum alpha^2 up to T
alpha_T
0
1/(t+1)^0.4
417.525500
27.110644
0.025119
1
1/(t+1)^0.7
50.052177
3.042751
0.001585
2
1/(t+1)
9.787606
1.644834
0.000100
3
0.05 constant
500.000000
25.000000
0.050000
17.5 14.4 Martingale-difference noise
Let \(\mathcal F_t\) represent the information available at time \(t\). A sequence \(M_{t+1}\) is a martingale-difference sequence if
\[
\mathbb E[M_{t+1}\mid \mathcal F_t]=0.
\]
This condition is the stochastic approximation analogue of unbiased sampling. It does not mean that the update has no variance. It means that, conditional on the current information, the noise does not systematically point in the wrong direction.
In TD learning, define the TD sample update for state \(s\) as
The conditional expectation of \(Y_{t+1}(s)\) depends on the current value estimate and the policy-induced transition law. The stochastic update is a noisy version of the expected Bellman correction.
Note
In RL, the noise is more subtle than in iid regression because samples are generated by a Markov chain. Conditional mean-zero arguments are usually made with respect to the filtration generated by the trajectory.
When \(\alpha_t\) is small, this deterministic recursion resembles the ordinary differential equation
\[
\dot \theta(t)=h(\theta(t)).
\]
The ODE method studies stochastic approximation by comparing the random discrete-time path to the deterministic flow of this differential equation.
17.6.1 Interactive: ODE method intuition
The stochastic recursion fluctuates around the deterministic ODE trajectory. As the step size decreases, the random path increasingly tracks the stable flow toward the equilibrium.
17.6.2 Stable equilibrium
A point \(\theta^*\) is an equilibrium of the ODE if
\[
h(\theta^*)=0.
\]
It is locally stable when trajectories starting near \(\theta^*\) move toward it. In one dimension, if \(h\) is differentiable and
\[
h'(\theta^*)<0,
\]
then \(\theta^*\) is locally stable. This is the reason that the recursion
Not every RL update is the gradient of a scalar objective. TD learning is often a stochastic fixed-point method rather than ordinary gradient descent on the mean-squared Bellman error.
17.9 14.8 TD learning as stochastic approximation
Consider a fixed policy \(\pi\) in a finite MDP. The Bellman equation is
where \(e_{S_t}\) is the coordinate vector for the visited state.
17.9.1 Interactive: TD as stochastic approximation
TD learning is a noisy fixed-point method. The expected update moves toward the Bellman fixed point, while sample paths fluctuate around that direction.
This is a stochastic approximation recursion for the fixed point of the optimal Bellman operator. The mean drift is related to \(T_*Q-Q\), but the update is asynchronous because only one state-action coordinate is changed at a time.
The usual convergence intuition requires:
all state-action pairs are visited infinitely often;
learning rates for each state-action pair satisfy the classical stochastic approximation conditions;
rewards have controlled variance;
the finite discounted Bellman optimality operator is a contraction.
Under these conditions, the noise averages out while the mean drift pulls the table toward \(Q^*\).
17.11 14.10 Constant step sizes and tracking
The classical theory often uses diminishing step sizes. In modern reinforcement learning, however, constant step sizes are common:
\[
\alpha_t=\alpha.
\]
A constant step size does not eliminate noise. Instead, the algorithm tends to fluctuate around the desired solution. This is useful in nonstationary environments, where the target itself may change over time.
import numpy as npimport matplotlib.pyplot as pltrng = np.random.default_rng(1403)T =700sigma =1.0alphas = [0.02, 0.08, 0.25]def target(t):return1.5if t <350else-0.5plt.figure(figsize=(7, 4))for alpha in alphas: theta =0.0 path = []for t inrange(T): a_t = target(t) theta += alpha * (a_t - theta + rng.normal(0.0, sigma)) path.append(theta) plt.plot(path, label=f"alpha={alpha}")plt.plot([target(t) for t inrange(T)], linestyle="--", linewidth=2, label="moving target")plt.xlabel("iteration")plt.ylabel("theta")plt.title("Constant-step stochastic approximation tracks a changing target")plt.legend()plt.show()
Constant step sizes produce persistent fluctuations around the target.
17.12 14.11 Projection and stability
Stochastic approximation algorithms can diverge if the iterates become unstable. A common theoretical device is projection onto a compact set \(\Theta\):
Projection is not always used in practical code, but it clarifies theory. It prevents extremely large parameter values and helps make compactness assumptions valid.
In approximate RL, stability is especially important because off-policy learning, bootstrapping, and function approximation may interact badly. This combination is often called the deadly triad.
Usually the critic is updated on the faster time scale:
\[
\frac{\alpha_t}{\beta_t}\to 0.
\]
This means that, from the actor’s point of view, the critic approximately equilibrates before the actor changes much. This idea is central in actor-critic theory.
17.13.1 Interactive: Two-time-scale learning
The critic should usually adapt faster than the actor. When the two learning rates are too similar, the actor may chase a poorly estimated critic.
AI tools can be helpful for checking whether an algorithm has been correctly written as a stochastic approximation recursion. The important point is to ask the AI to identify mathematical objects, not merely summarize the algorithm.
17.14.1 AI prompt: identify the stochastic approximation structure
Given an RL update rule, ask an AI assistant:
What is the parameter vector \(\theta_t\)?
What is the sample update \(Y_{t+1}\)?
What is the conditional mean drift \(h(\theta_t)\)?
What filtration \(\mathcal F_t\) is natural for this algorithm?
What is the martingale-difference noise term?
What step-size conditions are required for the classical convergence argument?
Is the update a stochastic gradient method, a stochastic fixed-point method, or both?
17.14.2 AI prompt: code-review checklist
Paste a small implementation of TD, SARSA, or Q-learning and ask:
Are learning rates attached to the correct visited state or state-action pair?
Does the code accidentally update using the new value where the old value is required?
Does the behavior policy ensure sufficient exploration?
Is the target on-policy or off-policy?
Are random seeds and simulation horizons adequate for a fair comparison?
Are convergence plots measuring value error, Bellman residual, or return performance?
17.15 14.14 Summary
Stochastic approximation provides the mathematical foundation for many sample-based RL algorithms. The main idea is to study noisy recursions through their conditional mean dynamics.
The term \(h(\theta_t)\) describes the deterministic direction of progress. The term \(M_{t+1}\) describes martingale-difference noise. The step size controls the balance between motion and averaging.
For reinforcement learning, this viewpoint explains why TD learning, SARSA, Q-learning, linear TD, and actor-critic algorithms are not isolated tricks. They are examples of noisy fixed-point or noisy optimization procedures.
17.16 Exercises
17.16.1 Conceptual exercises
Explain why stochastic approximation is needed for reinforcement learning but not for exact dynamic programming.
In your own words, explain why \(\sum_t\alpha_t=\infty\) and \(\sum_t\alpha_t^2<\infty\) are natural conditions.
What is martingale-difference noise? Why is it weaker than assuming iid noise?
Explain the ODE method without using measure-theoretic language.
Why can constant step sizes be useful in nonstationary environments?
17.16.2 Mathematical exercises
Let \(\alpha_t=1/(t+1)^p\). Prove that both classical step-size conditions hold exactly when \(1/2<p\leq 1\).
Consider \(\theta_{t+1}=\theta_t+\alpha_t(a-\theta_t)\). Derive an explicit formula for \(\theta_t-a\) in terms of \(\theta_0-a\) and the step sizes.
For \(h(\theta)=a-\theta\), show that \(\theta^*=a\) is a globally stable equilibrium of \(\dot\theta=h(\theta)\).
For linear stochastic approximation with drift \(b-A\theta\), show that the fixed point is \(\theta^*=A^{-1}b\) when \(A\) is invertible.
Write tabular TD(0) as a stochastic approximation recursion and identify the noise term.
Write tabular Q-learning as an asynchronous stochastic approximation recursion.
Explain why the Bellman contraction is important in the convergence intuition for Q-learning.
17.16.3 Computational exercises
Simulate the scalar Robbins-Monro recursion for several values of \(p\) in \(\alpha_t=(t+1)^{-p}\). Compare convergence and variance.
Implement TD(0) for a fixed-policy three-state Markov reward process and plot the sup-norm error.
Compare constant and diminishing step sizes in TD learning.
Simulate a changing target problem and show that constant step sizes track changes better than rapidly diminishing step sizes.
Implement a two-time-scale recursion where the critic uses \(\beta_t=(t+1)^{-0.6}\) and the actor uses \(\alpha_t=(t+1)^{-0.9}\).
17.16.4 AI-assisted exercises
Ask an AI assistant to rewrite SARSA as stochastic approximation. Check whether it correctly identifies the on-policy target.
Ask an AI assistant to compare TD learning and SGD. Find at least one way the comparison can be misleading.
Ask an AI assistant to audit a Q-learning implementation for step-size and exploration errors.
Ask an AI assistant to explain the ODE method, then rewrite the explanation in your own mathematical language.
Ask an AI assistant to generate a convergence plot for stochastic approximation and then verify that the plotted quantity is mathematically meaningful.
17.17 Notes for instructors
For MA Applied Math students, emphasize fixed points, dynamical systems, stability, and ODE intuition. For MS Statistics students, emphasize conditional expectation, martingale-difference noise, stochastic gradients, and sampling variability. This chapter can be taught as the mathematical core connecting TD learning, Q-learning, function approximation, and actor-critic methods.