Convergence of Q-Learning
Stochastic approximation and the deadly triad.
Q-learning updates one table entry at a time, from one noisy sample, toward a target built from its own estimates. That it converges at all is a theorem about stochastic approximation of a contraction. Add linear function approximation and off-policy data, and a closely related update can send its weights to infinity on a seven-state problem whose true values are all zero.
What you’ll learn
- State the Robbins–Monro conditions, explain the role of each, and compute the noise floor left by a constant step size.
- Prove tabular Q-learning's convergence by casting it as asynchronous stochastic approximation of a sup-norm contraction.
- Prove that on-policy linear TD(0) converges to the projected Bellman fixed point, and bound its error relative to the best linear fit.
- Explain the deadly triad with the two-state and Baird counterexamples, and derive gradient-TD methods from the projected Bellman error.
Stochastic approximation and the Robbins–Monro conditions
Robbins and Monro (1951) asked how to find the root of a function that can only be evaluated with noise. Their answer has the same shape as every TD update: take a small step in the direction of a noisy measurement, with steps that shrink at the right rate.
Estimate the mean of i.i.d. samples with variance by . The error obeys
Square and take expectations; the cross term vanishes because is independent of :
Decreasing steps. The initial error is multiplied by , which vanishes only if ; the injected noise vanishes if . Then , and almost-sure convergence follows from through the martingale convergence theorem. With the iterate is the running sample mean:
Constant step. With the recursion has a fixed point, so the error never falls below a floor proportional to :
A constant step tracks the mean of noisy targets whose standard deviation is . In the long run, what is the standard deviation of the estimate around the mean?
Show the answer
0.23
. Even a small constant step leaves the estimate jittering by almost a quarter of the noise. A smaller step lowers the floor but slows tracking, since the initial error decays like .
Q-learning converges: a contraction under noise
Let , and for the pair updated at time let . Subtracting from the update gives the lemma's recursion exactly:
The conditional mean of is a difference of Bellman backups. With and :
is a -contraction in the sup norm, because :
Rewards are bounded and is within of , so the variance condition holds. The lemma applies, and .
The work is in the lemma. Its proof first shows that the iterates stay bounded, then sandwiches between a deterministic contraction and a noise process that the Robbins–Monro conditions drive to zero; asynchrony, updating one pair at a time, is handled because each coordinate has its own step sequence. Watkins and Dayan's original proof was different: from the agent's experience they built an "action-replay process", an MDP whose optimal values are exactly the current Q-table, and showed that it converges to the true MDP.
How fast? It can be slow. With steps , Q-learning can need a number of steps exponential in the effective horizon , while polynomial steps with give polynomial bounds (Even-Dar & Mansour, 2003). With a generative model that samples every pair in every round, Q-learning needs on the order of samples for -accurate values, up to logarithmic factors, and this is tight for Q-learning (Li et al., 2024). That is one factor of the horizon above the minimax rate (Azar, Munos & Kappen, 2013), which model-based estimates and variance-reduced Q-learning (Wainwright, 2019) attain.
Linear TD and the projected Bellman equation
Now approximate with features. Linear TD(0) is a semi-gradient method: it updates , differentiating the estimate but not the target. Stack the features into (full column rank), let hold the stationary distribution of the policy's Markov chain , and let be the expected rewards. Averaged over the stationary distribution, the update is linear in :
does not expand the -norm (the same lemma appears in Bellman Equations & Contraction). Apply Jensen's inequality, then stationarity, :
So is a -contraction in , and so is , since an orthogonal projection expands nothing: it has a unique fixed point . Stability: by Cauchy–Schwarz and the first step, is positive definite, so the mean ODE is globally asymptotically stable and the ODE method applies.
Error bound. lies in the feature span, and is -orthogonal to it (Pythagoras). The first piece equals , so its norm is at most times the total error:
Rearrange. At the factor is about 7, not the 100 of the cruder bound. Note what is compared: TD's fixed point is not the best fit , only within this factor of it.
The deadly triad, and gradient-TD repairs
The stability proof used one fact twice: states are weighted by the policy's own stationary distribution. Sample them from a behavior distribution instead, as off-policy learning does, and can have eigenvalues with negative real part. The smallest example has two states and one weight.
Features 1 and 2 make the estimates and . A transition from the first state to the second pays reward 0, and its semi-gradient TD update is
If an off-policy behavior keeps updating this transition but rarely the second state's own transitions, every update multiplies by more than 1 whenever , and the weight diverges although is exact. On-policy, the second state's own updates, which pull toward its targets, restore stability.
Baird's counterexample (1995) removes every excuse: seven states, eight weights, all rewards zero, features that represent the true values exactly (all weights zero is a solution), and a behavior policy that spreads its visits evenly. Semi-gradient off-policy TD(0) diverges for any positive step size, even with exact expected updates instead of samples. Sutton and Barto name the culprit the deadly triad: function approximation, bootstrapping and off-policy training. With any two of them instability can be avoided (linear on-policy TD; off-policy Monte Carlo; tabular Q-learning), with all three it cannot be ruled out. Linear Q-learning sits inside the triad and can diverge too; sufficient conditions for its convergence are known only in restricted cases (Melo, Meyn & Ribeiro, 2008).
Gradient TD makes TD a true gradient method on an objective whose minimum is the TD fixed point, the mean-squared projected Bellman error (Sutton et al., 2009). States come from the behavior distribution, and corrects the choice of action.
The projected Bellman error has a closed form in three expectations under the behavior distribution:
Differentiate, using . The gradient is a product of expectations, so one sample of each factor would give a biased estimate:
Learn the last two factors as a second weight vector , the least-squares regression of on , on a faster timescale ():
Since , the first factor times equals . Sampling this gives TD with gradient correction (TDC); sampling the first form directly gives GTD2. Both cost per step and converge off-policy with linear features, by two-timescale stochastic approximation.
Emphatic TD (Sutton, Mahmood & White, 2016) takes another route: it reweights each update by a "followon" emphasis that makes the key matrix positive definite again, and it converges off-policy with linear features (Yu, 2015), at the cost of high variance. In deep RL, target networks and replay are the practical shields. Empirically, outright divergence is rare there, but value estimates that grow far beyond any achievable return ("soft divergence") are common (van Hasselt et al., 2018).
Which of these settings can diverge, according to the deadly-triad analysis?
- Tabular Q-learning with ε-greedy exploration
- Linear TD(0) evaluating the policy that generates the data
- Linear semi-gradient TD(0) evaluating a target policy from another policy's data
- Off-policy Monte Carlo evaluation with importance sampling and linear features
Show the answer
C. Linear semi-gradient TD(0) evaluating a target policy from another policy's data
Only the third combines all three elements: function approximation, bootstrapping and off-policy sampling. Baird's counterexample is exactly this case. Each of the others drops one element: tabular (no approximation), on-policy (no distribution mismatch), Monte Carlo (no bootstrapping; its update is a true gradient of a weighted squared error, although a high-variance one).
Key takeaways
- Stochastic approximation with Robbins–Monro steps (, ) averages noise away; a constant step leaves a floor of variance .
- Q-learning is asynchronous stochastic approximation of the sup-norm -contraction ; it converges almost surely to if every pair is updated infinitely often with Robbins–Monro steps, whatever the behavior.
- On-policy linear TD converges to the projected Bellman fixed point because is non-expansive in the stationary norm; its error is at most times the best linear fit's (for ).
- Off-policy sampling destroys that stability: function approximation, bootstrapping and off-policy updates together (the deadly triad) can diverge, as in the two-state and Baird examples.
- Gradient-TD methods (GTD2, TDC) perform true stochastic gradient descent on the projected Bellman error with a second, faster weight vector, and converge off-policy with linear features.
Check yourself
In the interactive lesson these are scored with your confidence, and what you miss comes back for review.
Which step-size sequence satisfies both Robbins–Monro conditions?
Show the answer
C.
because the exponent is at most 1, and because . Any with works.
Q-learning runs with , but the behavior policy never tries action in state . What does the convergence theorem guarantee?
- everywhere, because Q-learning is off-policy
- Nothing about , which keeps its initial value; and if is the best action there, errors propagate through the max to other states
- Convergence everywhere except at , with no effect on other entries
- Divergence, because the step sizes are not defined for that pair
Show the answer
B. Nothing about , which keeps its initial value; and if is the best action there, errors propagate through the max to other states
The theorem needs for every pair, which requires infinitely many visits. An unvisited entry keeps its initial value; if that value is too low and is optimal, underestimates , and every state that leads to inherits the error. Off-policy means any behavior works only if it explores everything.
On-policy linear TD(0) with ; the best linear fit has error . What does the Tsitsiklis–Van Roy analysis guarantee for TD's fixed point?
- Error at most 0.1: TD finds the best linear fit
- Error at most about 0.71
- Error at most 10
- No guarantee: TD may diverge
Show the answer
B. Error at most about 0.71
. TD's fixed point solves the projected Bellman equation, not the least-squares problem, so it can be worse than the best fit, by at most this factor. The cruder bound would give 10.
Why do gradient-TD methods such as TDC learn a second weight vector ?
- To store a slowly moving copy of , like a target network
- To estimate the importance-sampling ratio
- To learn a value function for the behavior policy
- The gradient of the projected Bellman error is a product of expectations, and estimates one factor, so single samples give an unbiased update
Show the answer
D. The gradient of the projected Bellman error is a product of expectations, and estimates one factor, so single samples give an unbiased update
. Multiplying single samples of each factor would be biased (the double-sampling problem), so tracks by least squares on a faster timescale.
Further reading
- H. Robbins & S. Monro, "A stochastic approximation method," Annals of Mathematical Statistics 22(3), 400–407 (1951).
- C. J. C. H. Watkins & P. Dayan, "Q-learning," Machine Learning 8, 279–292 (1992).
- J. N. Tsitsiklis & B. Van Roy, "An analysis of temporal-difference learning with function approximation," IEEE Transactions on Automatic Control 42(5), 674–690 (1997).
- R. S. Sutton, H. R. Maei, D. Precup, S. Bhatnagar, D. Silver, C. Szepesvári & E. Wiewiora, "Fast gradient-descent methods for temporal-difference learning with linear function approximation," ICML (2009).
- R. S. Sutton & A. G. Barto, Reinforcement Learning: An Introduction, ch. 9–11 (MIT Press, 2nd ed., 2018).