Simple Algorithm
Reinforcement Learning · Fixed Point · 28 min

Divergence: Baird’s Counterexample

Seven states, eight weights, and values that run off to infinity.

Baird's counterexample is the standard proof that off-policy semi-gradient TD can fail, and it is small enough to analyze completely. This lesson computes its expected-update matrix exactly, finds the direction in which the weights escape and the precise discount, γ>15/17\gamma>15/17, above which they must escape, shows why positive definiteness is the wrong test (it already fails at γ≈0.55\gamma\approx0.55, long before anything diverges), proves why the on-policy distribution is always safe for linear TD, and maps the other classic counterexamples, including on-policy divergence with a nonlinear approximator.

What you’ll learn

  • Write off-policy semi-gradient TD and semi-gradient DP on Baird's counterexample as the mean iteration w←(I−αA)w\mathbf w\leftarrow(\mathbf I-\alpha\mathbf A)\mathbf w, and compute A\mathbf A.
  • Reduce A\mathbf A by symmetry, derive that it has eigenvalues with negative real part exactly when γ>15/17\gamma>15/17, and identify the escaping direction.
  • Prove the column-sum criterion for positive definiteness of the on-policy key matrix, and explain why it is sufficient but not necessary for stability.
  • Describe the counterexamples of Tsitsiklis and Van Roy (fitted value iteration, off-trajectory updates, a nonlinear spiral) and why Gordon's averagers are safe.

The construction, exactly

Sutton and Barto's version of Baird's (1995) example has states s1,…,s7s_1,\dots,s_7 and weights w1,…,w8w_1,\dots,w_8. The feature matrix, with states as rows, is

X=(2I6010⊤12)∈R7×8,v^(si)=2wi+w8 (i≤6),v^(s7)=w7+2w8.\mathbf X=\begin{pmatrix}2\mathbf I_6&\mathbf 0&\mathbf 1\\\mathbf 0^\top&1&2\end{pmatrix}\in\R^{7\times8},\qquad\hat v(s_i)=2w_i+w_8\ (i\le6),\quad\hat v(s_7)=w_7+2w_8.

From any state, dashed moves to one of s1,…,s6s_1,\dots,s_6 uniformly and solid moves to s7s_7. The behavior policy bb takes dashed with probability 6/76/7, so its next state is uniform on all seven states and its stationary distribution is d=171d=\tfrac17\mathbf 1. The target policy π\pi always takes solid, so Pπ=1e7⊤P_\pi=\mathbf 1\mathbf e_7^\top: every row sends all its probability to s7s_7. All rewards are 0 and γ=0.99\gamma=0.99.

The true value function is 0, and it is representable in many ways: Xw=0\mathbf X\mathbf w=\mathbf 0 exactly for w∈span⁡{n}\mathbf w\in\operatorname{span}\{\mathbf n\} with n=(1,1,1,1,1,1,4,−2)⊤\mathbf n=(1,1,1,1,1,1,4,-2)^\top, since 2⋅1−2=02\cdot1-2=0 and 4+2⋅(−2)=04+2\cdot(-2)=0. Off-policy semi-gradient TD(0) with importance ratio ρt=π(At∣St)/b(At∣St)\rho_t=\pi(A_t\mid S_t)/b(A_t\mid S_t) (7 for solid, 0 for dashed) has expected update, given St=sS_t=s, Eb[ρtδtxt]=x(s)(γv^(s7)−v^(s))\E_b[\rho_t\delta_t\mathbf x_t]=\mathbf x(s)\big(\gamma\hat v(s_7)-\hat v(s)\big). Averaging over dd,

E[ρtδtxt]=−Aw,A=X⊤D (I−γPπ) X=17 X⊤(X−γ 1 x7⊤)\E[\rho_t\delta_t\mathbf x_t]=-\mathbf A\mathbf w,\qquad\mathbf A=\mathbf X^\top\mathbf D\,(\mathbf I-\gamma P_\pi)\,\mathbf X=\tfrac17\,\mathbf X^\top\big(\mathbf X-\gamma\,\mathbf 1\,\mathbf x_7^\top\big)
Here D=17I\mathbf D=\tfrac17\mathbf I and x7=(0,…,0,1,2)⊤\mathbf x_7=(0,\dots,0,1,2)^\top. Sutton and Barto's semi-gradient DP sweep (their eq. 11.9), wk+1=wk+α∣S∣∑s(Eπ[R+γv^(S′)∣s]−v^(s))x(s)\mathbf w_{k+1}=\mathbf w_k+\frac{\alpha}{|\mathcal S|}\sum_s\big(\E_\pi[R+\gamma\hat v(S')\mid s]-\hat v(s)\big)\mathbf x(s), is exactly wk+1=(I−αA)wk\mathbf w_{k+1}=(\mathbf I-\alpha\mathbf A)\mathbf w_k: the mean dynamics of TD with no noise at all.

The spectrum, and the critical discount

A\mathbf A commutes with permutations of the six upper states, so it splits into two invariant pieces. On the 5-dimensional subspace where w1+⋯+w6=0w_1+\dots+w_6=0 and w7=w8=0w_7=w_8=0, it acts as 47I\tfrac47\mathbf I: harmless. Everything interesting happens on the symmetric subspace w1=⋯=w6=aw_1=\dots=w_6=a, w7=cw_7=c, w8=ew_8=e.

DerivationReducing to three dimensions
  1. Mγ=(4−2γ2(1−2γ)01−γ2(1−γ)122−8γ10−16γ)\mathbf M_\gamma=\begin{pmatrix}4&-2\gamma&2(1-2\gamma)\\0&1-\gamma&2(1-\gamma)\\12&2-8\gamma&10-16\gamma\end{pmatrix}

    On the symmetric subspace the estimates are 2a+e2a+e (upper states) and c+2ec+2e (s7s_7). The vector u=(X−γ1x7⊤)w\mathbf u=(\mathbf X-\gamma\mathbf 1\mathbf x_7^\top)\mathbf w has entries 2a+e−γ(c+2e)2a+e-\gamma(c+2e) on the upper states and (1−γ)(c+2e)(1-\gamma)(c+2e) on s7s_7. Applying 17X⊤\tfrac17\mathbf X^\top (component i≤6i\le6: 2ui2u_i; component 7: u7u_7; component 8: ∑i≤6ui+2u7\sum_{i\le6}u_i+2u_7) gives 7A7\mathbf A restricted to (a,c,e)(a,c,e):

  2. λ1+λ2=15−17γ,λ1λ2=4(1−γ)+16(1−γ)+6(1−γ)=26(1−γ)\lambda_1+\lambda_2=15-17\gamma,\qquad\lambda_1\lambda_2=4(1-\gamma)+16(1-\gamma)+6(1-\gamma)=26(1-\gamma)

    Mγ(1,4,−2)⊤=0\mathbf M_\gamma(1,4,-2)^\top=\mathbf 0: the null direction n\mathbf n again. Let λ1,λ2\lambda_1,\lambda_2 be the other two eigenvalues. Their sum is the trace, and their product is the sum of the principal 2×22\times2 minors (the coefficient of λ\lambda in the characteristic polynomial, since the third eigenvalue is 0):

  3. Re⁡λ1,2<0  ⟺  γ>1517≈0.882\operatorname{Re}\lambda_{1,2}<0\iff\gamma>\tfrac{15}{17}\approx0.882

    The product is positive for γ<1\gamma<1. If λ1,2\lambda_{1,2} are real they share a sign, the sign of their sum; if complex, their common real part is half the sum. Either way both real parts are negative exactly when the sum is:

Predict before you look

At γ=0.99\gamma=0.99 and α=0.01\alpha=0.01, the dominant eigenvalue of A\mathbf A is −0.239-0.239. By roughly what factor does the escaping component of the weights grow every 1,000 sweeps of semi-gradient DP?

Show the answer

11

Each sweep multiplies that component by 1+0.01⋅0.2391+0.01\cdot0.239, and (1.00239)1000≈e2.39≈10.9(1.00239)^{1000}\approx e^{2.39}\approx10.9. Iterating from (1,1,1,1,1,1,10,1)(1,1,1,1,1,1,10,1), w8w_8 is about 335 after 1,000 sweeps and 4,050 after 2,000, while w1=⋯=w6w_1=\dots=w_6 lock onto about 0.34 w80.34\,w_8, the shape of the unstable eigenvector (0.341,…,0.341,−0.012,1)(0.341,\dots,0.341,-0.012,1). Halving α\alpha halves the exponent; it never stops the growth.

The escaping direction has an intuition. Raise the shared weight w8w_8 alone: every upper state's estimate rises by 1, but its target γv^(s7)\gamma\hat v(s_7) rises by 2γ2\gamma, so each upper state's TD error grows by 2γ−12\gamma-1, and the six of them, sampled six times as often as s7s_7, push w8w_8 up further. Only s7s_7's own update pulls back, with weight 1/71/7 and a tiny net error 2(1−γ)2(1-\gamma). Formally the diagonal entry is A88=17(6(1−2γ)+2(2−2γ))=10−16γ7A_{88}=\tfrac17\big(6(1-2\gamma)+2(2-2\gamma)\big)=\tfrac{10-16\gamma}{7}, negative for γ>0.625\gamma>0.625, and the escaping eigenvector is dominated by w8w_8 with the upper weights following at a third of its size.

Why on-policy updates are always stable

DerivationProof
  1. Sss−∑s′≠s∣Sss′∣=(Kss−∑s′≠s∣Kss′∣)+(Kss−∑s′≠s∣Ks′s∣)=∑s′Kss′+∑s′Ks′s>0S_{ss}-\sum_{s'\ne s}\abs{S_{ss'}}=\Big(K_{ss}-\sum_{s'\ne s}\abs{K_{ss'}}\Big)+\Big(K_{ss}-\sum_{s'\ne s}\abs{K_{s's}}\Big)=\sum_{s'}K_{ss'}+\sum_{s'}K_{s's}>0

    y⊤Ky=12y⊤(K+K⊤)y\mathbf y^\top\mathbf K\mathbf y=\tfrac12\mathbf y^\top(\mathbf K+\mathbf K^\top)\mathbf y, so it suffices that the symmetric S=K+K⊤\mathbf S=\mathbf K+\mathbf K^\top is positive definite. Because off-diagonal entries are nonpositive, row ss of S\mathbf S has diagonal surplus equal to row sum plus column sum of K\mathbf K:

  2. 1⊤D(I−γP)=d⊤−γ d⊤P=(1−γ) d⊤>0\mathbf 1^\top\mathbf D(\mathbf I-\gamma P)=d^\top-\gamma\,d^\top P=(1-\gamma)\,d^\top>0

    A symmetric matrix with positive diagonal that is strictly diagonally dominant has only positive eigenvalues (Gershgorin's theorem). Now check the conditions on-policy. Diagonal d(s)(1−γP(s,s))>0d(s)(1-\gamma P(s,s))>0, off-diagonal −γd(s)P(s,s′)≤0-\gamma d(s)P(s,s')\le0, row sums d(s)(1−γ)>0d(s)(1-\gamma)>0, and column sums by stationarity:

  3. 1⊤D(I−γPπ)=(17,…,17, 17−γ),17−0.99≈−0.847<0\mathbf 1^\top\mathbf D(\mathbf I-\gamma P_\pi)=\Big(\tfrac17,\dots,\tfrac17,\ \tfrac17-\gamma\Big),\qquad\tfrac17-0.99\approx-0.847<0

    In Baird's problem with the behavior's d=171d=\tfrac17\mathbf 1 and the target's Pπ=1e7⊤P_\pi=\mathbf 1\mathbf e_7^\top, the sign pattern and the row sums are fine, but the target policy routes everyone's flow into s7s_7:

The criterion is sufficient, not necessary. Baird's X\mathbf X has more columns than rows, so A\mathbf A always has the zero eigenvalue along n\mathbf n; the meaningful test is whether y⊤Ay=(Xy)⊤K(Xy)\mathbf y^\top\mathbf A\mathbf y=(\mathbf X\mathbf y)^\top\mathbf K(\mathbf X\mathbf y) is positive whenever Xy≠0\mathbf X\mathbf y\ne\mathbf 0, that is, whether the symmetric part 12(K+K⊤)\tfrac12(\mathbf K+\mathbf K^\top) of K=17(I−γ1e7⊤)\mathbf K=\tfrac17(\mathbf I-\gamma\mathbf 1\mathbf e_7^\top) is positive definite. Its smallest eigenvalue is 114(2−γ(1+7))\tfrac1{14}\big(2-\gamma(1+\sqrt7)\big), negative once γ>2/(1+7)≈0.549\gamma>2/(1+\sqrt7)\approx0.549. The column sum at s7s_7 is negative from γ>1/7\gamma>1/7, and even the diagonal entry A88A_{88} from γ>0.625\gamma>0.625; yet the mean dynamics stay stable until γ=15/17\gamma=15/17. At γ=0.75\gamma=0.75, for instance, the critical eigenvalues are 0.161±0.327i0.161\pm0.327i, with positive real part. Stability is a statement about eigenvalues, positive definiteness about the symmetric part, and the gap between them is real.

Restricting updates to the target policy's own distribution is safe for a simple reason here: it puts all weight on s7s_7, so Aon=(1−γ) x7x7⊤\mathbf A_{\text{on}}=(1-\gamma)\,\mathbf x_7\mathbf x_7^\top, positive semidefinite. Every update moves the weights along x7=(0,…,0,1,2)\mathbf x_7=(0,\dots,0,1,2) only, multiplying v^(s7)\hat v(s_7) by 1−5α(1−γ)1-5\alpha(1-\gamma), so the weights converge to w0−v^0(s7)5x7=(1,…,1,7.6,−3.8)\mathbf w_0-\tfrac{\hat v_0(s_7)}{5}\mathbf x_7=(1,\dots,1,7.6,-3.8). Because the upper states share w8w_8, their estimates end at 2−3.8=−1.82-3.8=-1.8: on-policy updates drive the error to 0 where the target policy goes, the only place the on-policy objective measures it, not everywhere.

Other counterexamples, and approximators that are safe

Fitted value iteration (Tsitsiklis & Van Roy, 1996; Sutton & Barto, Example 11.1). Even replacing each semi-gradient step by the exact least-squares fit of the backed-up values does not help. With features (1,2)(1,2), a transition from the first state to the second, and the second state staying put with probability 1−ϵ1-\epsilon and terminating otherwise (all rewards 0), the uniformly weighted least-squares iteration is wk+1=6−4ϵ5γwkw_{k+1}=\frac{6-4\epsilon}{5}\gamma w_k, divergent for γ>5/(6−4ϵ)\gamma>5/(6-4\epsilon): a projection that is non-expansive in a weighted L2L_2 norm composed with a backup that contracts in the max norm need contract in neither.

Off-trajectory updates (Tsitsiklis & Van Roy, 1997). Their analysis of linear TD identifies the condition that matters: updates must follow trajectories of the Markov chain being evaluated. They prove convergence under that condition and show divergence is possible when it is violated, which reconciles the earlier positive and negative results.

Nonlinear approximation, on-policy (Tsitsiklis & Van Roy, 1997). A three-state Markov chain with all costs zero, a single scalar parameter, and a nonlinear parameterization whose representable value functions trace a spiral in a plane: each backup rotates and scales the current estimate, the nearest point on the spiral lies further out, and TD(0) diverges although it samples on-policy. The positive-definiteness argument is a property of linear parameterizations; with nonlinear ones, on-policy sampling is no longer enough.

For control the picture is worse still. Q-learning with linear features can diverge in Baird-style examples, while for an ε\varepsilon-greedy behavior close to the greedy target policy Sutton and Barto (2018) note that no divergence had been found but no proof existed either. On-policy linear SARSA is bounded but may chatter (Gordon, 2001). Deep Q-learning, with nonlinear features and replay, sits inside every one of these warnings, which is why its stabilizers, and their limits, are studied empirically (The Deadly Triad).

Key takeaways

  • On Baird's counterexample, off-policy semi-gradient TD and semi-gradient DP share the mean dynamics w←(I−αA)w\mathbf w\leftarrow(\mathbf I-\alpha\mathbf A)\mathbf w with A=17X⊤(X−γ1x7⊤)\mathbf A=\tfrac17\mathbf X^\top(\mathbf X-\gamma\mathbf 1\mathbf x_7^\top).
  • By symmetry the critical eigenvalues satisfy λ1+λ2=15−17γ\lambda_1+\lambda_2=15-17\gamma and λ1λ2=26(1−γ)\lambda_1\lambda_2=26(1-\gamma), so the dynamics diverge for every step size exactly when γ>15/17\gamma>15/17; at γ=0.99\gamma=0.99 the weights grow about elevenfold per 1,000 sweeps at α=0.01\alpha=0.01.
  • On-policy, the key matrix D(I−γP)\mathbf D(\mathbf I-\gamma P) has positive row and column sums and is positive definite; in Baird's problem the column of s7s_7 sums to 17−γ<0\tfrac17-\gamma<0. Positive definiteness is sufficient, not necessary, for stability.
  • Fitted value iteration with least squares can diverge, nonlinear TD can diverge even on-policy, and averagers, being max-norm non-expansions, are safe.

Check yourself

In the interactive lesson these are scored with your confidence, and what you miss comes back for review.

Question 1

Which weight vector makes every estimate in Baird's counterexample exactly 0?

  1. (1,1,1,1,1,1,10,1)(1,1,1,1,1,1,10,1)
  2. (1,1,1,1,1,1,4,−2)(1,1,1,1,1,1,4,-2), or any multiple of it
  3. Only w=0\mathbf w=\mathbf 0
  4. (0,0,0,0,0,0,1,0)(0,0,0,0,0,0,1,0)
Show the answer

B. (1,1,1,1,1,1,4,−2)(1,1,1,1,1,1,4,-2), or any multiple of it

Upper states: 2⋅1+(−2)=02\cdot1+(-2)=0; s7s_7: 4+2⋅(−2)=04+2\cdot(-2)=0. Eight weights and seven independent feature vectors leave a one-dimensional null space, so exact solutions form a line. Divergence happens although the target is not just representable but representable in infinitely many ways.

Question 2

At γ=0.75\gamma=0.75, Baird's key matrix has A88<0A_{88}<0, so it is not positive definite. What happens to the mean iteration w←(I−αA)w\mathbf w\leftarrow(\mathbf I-\alpha\mathbf A)\mathbf w for small α\alpha?

  1. It converges, because every nonzero eigenvalue of A\mathbf A has positive real part when γ<15/17\gamma<15/17
  2. It diverges, because A\mathbf A is not positive definite
  3. It diverges only for large step sizes
  4. It neither converges nor diverges
Show the answer

A. It converges, because every nonzero eigenvalue of A\mathbf A has positive real part when γ<15/17\gamma<15/17

Stability of a linear iteration depends on the eigenvalues, not on the symmetric part. At γ=0.75\gamma=0.75 the critical pair is 0.161±0.327i0.161\pm0.327i, with positive real part, so small steps converge (with oscillation). Positive definiteness is a convenient sufficient condition, which Baird's key matrix fails from γ=2/(1+7)≈0.549\gamma=2/(1+\sqrt7)\approx0.549 on (its diagonal entry A88A_{88} is negative from 0.625), well before the instability at 15/1715/17.

Question 3

What does Tsitsiklis and Van Roy's spiral example show?

  1. That linear TD can diverge on-policy
  2. That fitted value iteration diverges with averagers
  3. That importance sampling causes divergence
  4. That TD(0) can diverge on-policy when the value function is a nonlinear function of the parameters
Show the answer

D. That TD(0) can diverge on-policy when the value function is a nonlinear function of the parameters

Linear on-policy TD converges (positive definite key matrix). With a nonlinear parameterization whose representable functions form a spiral, each backup rotates the estimate and the closest representable point moves outward, so TD(0) diverges even with on-policy sampling and zero rewards.

Further reading

  • L. Baird, "Residual algorithms: Reinforcement learning with function approximation", ICML (1995).
  • R. S. Sutton & A. G. Barto, Reinforcement Learning: An Introduction, §9.4 and §11.2 (MIT Press, 2nd ed., 2018).
  • J. N. Tsitsiklis & B. Van Roy, "Feature-based methods for large scale dynamic programming", Machine Learning 22 (1996).
  • J. N. Tsitsiklis & B. Van Roy, "An analysis of temporal-difference learning with function approximation", IEEE Transactions on Automatic Control 42(5) (1997).
  • G. J. Gordon, "Stable function approximation in dynamic programming", ICML (1995).