Simple Algorithm
Artificial Intelligence · Deep Layer · 30 min

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.

DerivationMean estimation: why both conditions, and the floor of a constant step
  1. et+1=(1−αt) et+αt ξt+1,ξt+1=Xt+1−μe_{t+1}=(1-\alpha_t)\,e_t+\alpha_t\,\xi_{t+1},\qquad\xi_{t+1}=X_{t+1}-\mu

    Estimate the mean μ\mu of i.i.d. samples XtX_t with variance σ2\sigma^2 by θt+1=θt+αt(Xt+1−θt)\theta_{t+1}=\theta_t+\alpha_t(X_{t+1}-\theta_t). The error et=θt−μe_t=\theta_t-\mu obeys

  2. Eet+12=(1−αt)2 Eet2+αt2σ2\E e_{t+1}^2=(1-\alpha_t)^2\,\E e_t^2+\alpha_t^2\sigma^2

    Square and take expectations; the cross term vanishes because ξt+1\xi_{t+1} is independent of ete_t:

  3. αt=1t+1⟹θt=1t∑k=1tXk,Eet2=σ2t\alpha_t=\frac1{t+1}\quad\Longrightarrow\quad\theta_t=\frac1t\sum_{k=1}^{t}X_k,\qquad\E e_t^2=\frac{\sigma^2}{t}

    Decreasing steps. The initial error is multiplied by ∏t(1−αt)≤exp⁡(−∑tαt)\prod_t(1-\alpha_t)\le\exp\big(-\sum_t\alpha_t\big), which vanishes only if ∑tαt=∞\sum_t\alpha_t=\infty; the injected noise vanishes if αt→0\alpha_t\to0. Then Eet2→0\E e_t^2\to0, and almost-sure convergence follows from ∑tαt2<∞\sum_t\alpha_t^2<\infty through the martingale convergence theorem. With αt=1/(t+1)\alpha_t=1/(t+1) the iterate is the running sample mean:

  4. Ee∞2=α2σ21−(1−α)2=α σ22−α\E e_\infty^2=\frac{\alpha^2\sigma^2}{1-(1-\alpha)^2}=\frac{\alpha\,\sigma^2}{2-\alpha}

    Constant step. With αt≡α\alpha_t\equiv\alpha the recursion has a fixed point, so the error never falls below a floor proportional to α\alpha:

Predict before you look

A constant step α=0.1\alpha=0.1 tracks the mean of noisy targets whose standard deviation is σ=1\sigma=1. In the long run, what is the standard deviation of the estimate around the mean?

Show the answer

0.23

ασ2/(2−α)=0.1/1.9≈0.23\sqrt{\alpha\sigma^2/(2-\alpha)}=\sqrt{0.1/1.9}\approx0.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 (1−α)t(1-\alpha)^t.

Q-learning converges: a contraction under noise

DerivationProof of the theorem from the lemma
  1. Δt+1(s,a)=(1−αt(s,a))Δt(s,a)+αt(s,a) Ft(s,a)\Delta_{t+1}(s,a)=\big(1-\alpha_t(s,a)\big)\Delta_t(s,a)+\alpha_t(s,a)\,F_t(s,a)

    Let Δt=Qt−Q∗\Delta_t=Q_t-Q^*, and for the pair updated at time tt let Ft(s,a)=Rt+1+γmax⁡a′Qt(St+1,a′)−Q∗(s,a)F_t(s,a)=R_{t+1}+\gamma\max_{a'}Q_t(S_{t+1},a')-Q^*(s,a). Subtracting Q∗Q^* from the update gives the lemma's recursion exactly:

  2. E[Ft(s,a)∣Ft]=(TQt)(s,a)−(TQ∗)(s,a)\E[F_t(s,a)\mid\mathcal F_t]=(\mathcal TQ_t)(s,a)-(\mathcal TQ^*)(s,a)

    The conditional mean of FtF_t is a difference of Bellman backups. With (TQ)(s,a)=r(s,a)+γ∑s′P(s′∣s,a)max⁡a′Q(s′,a′)(\mathcal TQ)(s,a)=r(s,a)+\gamma\sum_{s'}P(s'\mid s,a)\max_{a'}Q(s',a') and Q∗=TQ∗Q^*=\mathcal TQ^*:

  3. ∣(TQt−TQ∗)(s,a)∣≤γ∑s′P(s′∣s,a)max⁡a′∣Δt(s′,a′)∣≤γ∥Δt∥∞\big|(\mathcal TQ_t-\mathcal TQ^*)(s,a)\big|\le\gamma\sum_{s'}P(s'\mid s,a)\max_{a'}\abs{\Delta_t(s',a')}\le\gamma\norm{\Delta_t}_\infty

    T\mathcal T is a γ\gamma-contraction in the sup norm, because ∣max⁡aq(a)−max⁡aq′(a)∣≤max⁡a∣q(a)−q′(a)∣\abs{\max_aq(a)-\max_aq'(a)}\le\max_a\abs{q(a)-q'(a)}:

  4. Var⁡[Ft(s,a)∣Ft]≤E[(Rt+1+γmax⁡a′Qt(St+1,a′))2 ∣ Ft]≤C(1+∥Δt∥∞2)\Var[F_t(s,a)\mid\mathcal F_t]\le\E\Big[\big(R_{t+1}+\gamma\max_{a'}Q_t(S_{t+1},a')\big)^2\,\Big|\,\mathcal F_t\Big]\le C\big(1+\norm{\Delta_t}_\infty^2\big)

    Rewards are bounded and max⁡a′Qt\max_{a'}Q_t is within ∥Δt∥∞\norm{\Delta_t}_\infty of max⁡a′Q∗\max_{a'}Q^*, so the variance condition holds. The lemma applies, and Qt→Q∗Q_t\to Q^*.

The work is in the lemma. Its proof first shows that the iterates stay bounded, then sandwiches Δt\Delta_t 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 α=1/N(s,a)\alpha=1/N(s,a), Q-learning can need a number of steps exponential in the effective horizon 1/(1−γ)1/(1-\gamma), while polynomial steps α=1/Nω\alpha=1/N^\omega with 12<ω<1\tfrac12<\omega<1 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 ∣S∣∣A∣/((1−γ)4ε2)\abs S\abs A/((1-\gamma)^4\varepsilon^2) samples for ε\varepsilon-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 ∣S∣∣A∣/((1−γ)3ε2)\abs S\abs A/((1-\gamma)^3\varepsilon^2) (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 V(s)≈ϕ(s)⊤θV(s)\approx\phi(s)^\top\theta with d≪∣S∣d\ll\abs S features. Linear TD(0) is a semi-gradient method: it updates θ←θ+α δt ϕ(St)\theta\leftarrow\theta+\alpha\,\delta_t\,\phi(S_t), differentiating the estimate ϕ(St)⊤θ\phi(S_t)^\top\theta but not the target. Stack the features into Φ∈R∣S∣×d\Phi\in\R^{\abs S\times d} (full column rank), let D=diag⁡(dπ)D=\diag(d_\pi) hold the stationary distribution of the policy's Markov chain PπP_\pi, and let rπr_\pi be the expected rewards. Averaged over the stationary distribution, the update is linear in θ\theta:

E[δt ϕ(St)]=b−Aθ,A=Φ⊤D (I−γPπ) Φ,b=Φ⊤D rπ\E[\delta_t\,\phi(S_t)]=b-A\theta,\qquad A=\Phi^\top D\,(I-\gamma P_\pi)\,\Phi,\qquad b=\Phi^\top D\,r_\pi
TD(0)'s limit solves Aθ=bA\theta=b. Because AA is not symmetric, TD is not gradient descent on any objective, and its stability has to be proved directly.
DerivationProof sketch for λ = 0
  1. ∥Pπv∥D2=∑sd(s)(∑s′Pπ(s,s′) v(s′))2≤∑sd(s)∑s′Pπ(s,s′) v(s′)2=∥v∥D2\norm{P_\pi v}_D^2=\sum_sd(s)\Big(\sum_{s'}P_\pi(s,s')\,v(s')\Big)^2\le\sum_sd(s)\sum_{s'}P_\pi(s,s')\,v(s')^2=\norm{v}_D^2

    PπP_\pi does not expand the DD-norm (the same lemma appears in Bellman Equations & Contraction). Apply Jensen's inequality, then stationarity, dπ⊤Pπ=dπ⊤d_\pi^\top P_\pi=d_\pi^\top:

  2. θ⊤Aθ=∥Φθ∥D2−γ ⟨Φθ,PπΦθ⟩D≥(1−γ) ∥Φθ∥D2>0(θ≠0)\theta^\top A\theta=\norm{\Phi\theta}_D^2-\gamma\,\langle\Phi\theta,P_\pi\Phi\theta\rangle_D\ge(1-\gamma)\,\norm{\Phi\theta}_D^2>0\qquad(\theta\ne0)

    So Tπv=rπ+γPπvT_\pi v=r_\pi+\gamma P_\pi v is a γ\gamma-contraction in ∥⋅∥D\norm\cdot_D, and so is ΠDTπ\Pi_DT_\pi, since an orthogonal projection expands nothing: it has a unique fixed point Φθ∗\Phi\theta^*. Stability: by Cauchy–Schwarz and the first step, AA is positive definite, so the mean ODE θ˙=b−Aθ\dot\theta=b-A\theta is globally asymptotically stable and the ODE method applies.

  3. ∥Φθ∗−Vπ∥D2=∥Φθ∗−ΠDVπ∥D2+∥ΠDVπ−Vπ∥D2≤γ2∥Φθ∗−Vπ∥D2+∥ΠDVπ−Vπ∥D2\norm{\Phi\theta^*-V^\pi}_D^2=\norm{\Phi\theta^*-\Pi_DV^\pi}_D^2+\norm{\Pi_DV^\pi-V^\pi}_D^2\le\gamma^2\norm{\Phi\theta^*-V^\pi}_D^2+\norm{\Pi_DV^\pi-V^\pi}_D^2

    Error bound. Φθ∗−ΠDVπ\Phi\theta^*-\Pi_DV^\pi lies in the feature span, and ΠDVπ−Vπ\Pi_DV^\pi-V^\pi is DD-orthogonal to it (Pythagoras). The first piece equals ΠDTπΦθ∗−ΠDTπVπ\Pi_DT_\pi\Phi\theta^*-\Pi_DT_\pi V^\pi, so its norm is at most γ\gamma times the total error:

  4. ∥Φθ∗−Vπ∥D≤11−γ2 ∥ΠDVπ−Vπ∥D\norm{\Phi\theta^*-V^\pi}_D\le\frac{1}{\sqrt{1-\gamma^2}}\,\norm{\Pi_DV^\pi-V^\pi}_D

    Rearrange. At γ=0.99\gamma=0.99 the factor is about 7, not the 100 of the cruder 1/(1−γ)1/(1-\gamma) bound. Note what is compared: TD's fixed point is not the best fit ΠDVπ\Pi_DV^\pi, 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 μ≠dπ\mu\ne d_\pi instead, as off-policy learning does, and Aμ=Φ⊤Dμ(I−γPπ)ΦA_\mu=\Phi^\top D_\mu(I-\gamma P_\pi)\Phi can have eigenvalues with negative real part. The smallest example has two states and one weight.

DerivationTwo states, one weight (Sutton & Barto, §11.2)
  1. θ←θ+α (0+γ⋅2θ−θ)⋅1=(1+α(2γ−1)) θ\theta\leftarrow\theta+\alpha\,\big(0+\gamma\cdot2\theta-\theta\big)\cdot1=\big(1+\alpha(2\gamma-1)\big)\,\theta

    Features 1 and 2 make the estimates θ\theta and 2θ2\theta. A transition from the first state to the second pays reward 0, and its semi-gradient TD update is

  2. γ>12⟹∣θt∣→∞\gamma>\tfrac12\quad\Longrightarrow\quad\abs{\theta_t}\to\infty

    If an off-policy behavior keeps updating this transition but rarely the second state's own transitions, every update multiplies θ\theta by more than 1 whenever γ>12\gamma>\tfrac12, and the weight diverges although θ=0\theta=0 is exact. On-policy, the second state's own updates, which pull 2θ2\theta 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 ρt=π(At∣St)/μ(At∣St)\rho_t=\pi(A_t\mid S_t)/\mu(A_t\mid S_t) corrects the choice of action.

DerivationFrom the projected Bellman error to TDC
  1. PBE‾(θ)=∥Π (TπΦθ−Φθ)∥μ2=E[ρδϕ]⊤ E[ϕϕ⊤]−1 E[ρδϕ]\overline{\mathrm{PBE}}(\theta)=\norm{\Pi\,(T_\pi\Phi\theta-\Phi\theta)}^2_\mu=\E[\rho\delta\phi]^\top\,\E[\phi\phi^\top]^{-1}\,\E[\rho\delta\phi]

    The projected Bellman error has a closed form in three expectations under the behavior distribution:

  2. −12∇PBE‾(θ)=E[ρ (ϕ−γϕ′) ϕ⊤]  E[ϕϕ⊤]−1 E[ρδϕ]-\tfrac12\nabla\overline{\mathrm{PBE}}(\theta)=\E\big[\rho\,(\phi-\gamma\phi')\,\phi^\top\big]\;\E[\phi\phi^\top]^{-1}\,\E[\rho\delta\phi]

    Differentiate, using ∇θ(ρδ)=ρ (γϕ′−ϕ)\nabla_\theta(\rho\delta)=\rho\,(\gamma\phi'-\phi). The gradient is a product of expectations, so one sample of each factor would give a biased estimate:

  3. w←w+β (ρ δ−ϕ⊤w) ϕw\leftarrow w+\beta\,\big(\rho\,\delta-\phi^\top w\big)\,\phi

    Learn the last two factors as a second weight vector w≈E[ϕϕ⊤]−1E[ρδϕ]w\approx\E[\phi\phi^\top]^{-1}\E[\rho\delta\phi], the least-squares regression of ρδ\rho\delta on ϕ\phi, on a faster timescale (β≫α\beta\gg\alpha):

  4. θ←θ+α ρ (δ ϕ−γ ϕ′ (ϕ⊤w))\theta\leftarrow\theta+\alpha\,\rho\,\big(\delta\,\phi-\gamma\,\phi'\,(\phi^\top w)\big)

    Since E[ρ ϕϕ⊤]=E[ϕϕ⊤]\E[\rho\,\phi\phi^\top]=\E[\phi\phi^\top], the first factor times ww equals E[ρδϕ]−γ E[ρ ϕ′ϕ⊤] w\E[\rho\delta\phi]-\gamma\,\E[\rho\,\phi'\phi^\top]\,w. Sampling this gives TD with gradient correction (TDC); sampling the first form directly gives GTD2. Both cost O(d)\order{d} 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).

Check your understanding

Which of these settings can diverge, according to the deadly-triad analysis?

  1. Tabular Q-learning with ε-greedy exploration
  2. Linear TD(0) evaluating the policy that generates the data
  3. Linear semi-gradient TD(0) evaluating a target policy from another policy's data
  4. 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 (∑αt=∞\sum\alpha_t=\infty, ∑αt2<∞\sum\alpha_t^2<\infty) averages noise away; a constant step leaves a floor of variance ασ2/(2−α)\alpha\sigma^2/(2-\alpha).
  • Q-learning is asynchronous stochastic approximation of the sup-norm γ\gamma-contraction T\mathcal T; it converges almost surely to Q∗Q^* 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 PπP_\pi is non-expansive in the stationary norm; its error is at most 1/1−γ21/\sqrt{1-\gamma^2} times the best linear fit's (for λ=0\lambda=0).
  • 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.

Question 1

Which step-size sequence satisfies both Robbins–Monro conditions?

  1. αt=1/t\alpha_t=1/\sqrt t
  2. αt=0.01\alpha_t=0.01
  3. αt=1/t0.7\alpha_t=1/t^{0.7}
  4. αt=1/t2\alpha_t=1/t^2
Show the answer

C. αt=1/t0.7\alpha_t=1/t^{0.7}

∑tt−0.7=∞\sum_t t^{-0.7}=\infty because the exponent is at most 1, and ∑tt−1.4<∞\sum_t t^{-1.4}<\infty because 1.4>11.4>1. Any αt=1/tω\alpha_t=1/t^\omega with 12<ω≤1\tfrac12<\omega\le1 works.

Question 2

Q-learning runs with αt(s,a)=1/Nt(s,a)\alpha_t(s,a)=1/N_t(s,a), but the behavior policy never tries action a2a_2 in state s1s_1. What does the convergence theorem guarantee?

  1. Qt→Q∗Q_t\to Q^* everywhere, because Q-learning is off-policy
  2. Nothing about Q(s1,a2)Q(s_1,a_2), which keeps its initial value; and if a2a_2 is the best action there, errors propagate through the max to other states
  3. Convergence everywhere except at (s1,a2)(s_1,a_2), with no effect on other entries
  4. Divergence, because the step sizes are not defined for that pair
Show the answer

B. Nothing about Q(s1,a2)Q(s_1,a_2), which keeps its initial value; and if a2a_2 is the best action there, errors propagate through the max to other states

The theorem needs ∑tαt(s,a)=∞\sum_t\alpha_t(s,a)=\infty for every pair, which requires infinitely many visits. An unvisited entry keeps its initial value; if that value is too low and a2a_2 is optimal, max⁡aQ(s1,a)\max_aQ(s_1,a) underestimates V∗(s1)V^*(s_1), and every state that leads to s1s_1 inherits the error. Off-policy means any behavior works only if it explores everything.

Question 3

On-policy linear TD(0) with γ=0.99\gamma=0.99; the best linear fit has error ∥ΠDVπ−Vπ∥D=0.1\norm{\Pi_DV^\pi-V^\pi}_D=0.1. What does the Tsitsiklis–Van Roy analysis guarantee for TD's fixed point?

  1. Error at most 0.1: TD finds the best linear fit
  2. Error at most about 0.71
  3. Error at most 10
  4. No guarantee: TD may diverge
Show the answer

B. Error at most about 0.71

0.1/1−0.992=0.1/0.141≈0.710.1/\sqrt{1-0.99^2}=0.1/0.141\approx0.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 1/(1−γ)1/(1-\gamma) would give 10.

Question 4

Why do gradient-TD methods such as TDC learn a second weight vector ww?

  1. To store a slowly moving copy of θ\theta, like a target network
  2. To estimate the importance-sampling ratio
  3. To learn a value function for the behavior policy
  4. The gradient of the projected Bellman error is a product of expectations, and ww 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 ww estimates one factor, so single samples give an unbiased update

−12∇PBE‾=E[ρ(ϕ−γϕ′)ϕ⊤] E[ϕϕ⊤]−1E[ρδϕ]-\tfrac12\nabla\overline{\mathrm{PBE}}=\E[\rho(\phi-\gamma\phi')\phi^\top]\,\E[\phi\phi^\top]^{-1}\E[\rho\delta\phi]. Multiplying single samples of each factor would be biased (the double-sampling problem), so ww tracks E[ϕϕ⊤]−1E[ρδϕ]\E[\phi\phi^\top]^{-1}\E[\rho\delta\phi] 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).