Simple Algorithm
Reinforcement Learning · Fixed Point · 30 min

The Projected Bellman Equation & LSTD

TD’s fixed point, least-squares TD, and how far that fixed point can be from the best fit.

Linear TD does not converge to the best fit of the value function. It solves a different equation, the projected Bellman equation, whose solution can be computed in closed form from data and can sit far from the best fit. This lesson studies that equation: the three projections that TD, Monte Carlo and Bellman-residual minimization each compute, the norm in which TD contracts, a two-state example that nearly attains the worst-case error, least-squares TD and LSPI with their sample complexity, and why the Bellman residual cannot even be learned from single trajectories.

What you’ll learn

  • Write the TD fixed point as the solution of Φw=ΠTπΦw\Phi\mathbf w=\Pi\mathcal T^\pi\Phi\mathbf w and as an oblique projection of VπV^\pi, and contrast it with the orthogonal projection and the Bellman-residual solution.
  • Prove that ΠTπ\Pi\mathcal T^\pi is a γ\gamma-contraction in the norm of the stationary distribution and derive the 1/1−γ21/\sqrt{1-\gamma^2} error bound, including its TD(λ\lambda) form.
  • Derive LSTD with an O(d2)\order{d^2} recursive update, interpret it as certainty equivalence in a linear model, and state its finite-sample bound.
  • Explain LSPI, the double-sampling problem of residual methods, and why the Bellman error is not learnable while the TD fixed point is.

Three projections of one value function

Fix a policy π\pi on a finite MDP with transition matrix P=PπP=P^\pi, reward vector r=rπr=r^\pi and value V=Vπ=(I−γP)−1rV=V^\pi=(\mathbf I-\gamma P)^{-1}r. Let Φ∈RS×d\Phi\in\R^{S\times d} hold the features as rows (full column rank), let μ\mu be a distribution with all μ(s)>0\mu(s)>0, D=diag⁡(μ)\mathbf D=\diag(\mu), and ∥u∥μ2=u⊤Du\norm{u}_\mu^2=u^\top\mathbf Du. The μ\mu-orthogonal projection onto the feature span is

Π=Φ(Φ⊤DΦ)−1Φ⊤D,\Pi=\Phi(\Phi^\top\mathbf D\Phi)^{-1}\Phi^\top\mathbf D,

the map to the closest point of {Φw}\{\Phi\mathbf w\} in ∥⋅∥μ\norm\cdot_\mu. The fixed points of the three standard linear estimators are all projections of VV onto that span; they differ only in which directions the remaining error must be orthogonal to.

DerivationMonte Carlo, TD and the Bellman residual as projections
  1. TπΦw−Φw=r+γPΦw−Φw=(I−γP) (V−Φw)\mathcal T^\pi\Phi\mathbf w-\Phi\mathbf w=r+\gamma P\Phi\mathbf w-\Phi\mathbf w=(\mathbf I-\gamma P)\,(V-\Phi\mathbf w)

    Because r=(I−γP)Vr=(\mathbf I-\gamma P)V, the Bellman residual of any linear estimate is the true error pushed through I−γP\mathbf I-\gamma P:

  2. Φ⊤D (V−ΦwMC)=0⟺ΦwMC=ΠV\Phi^\top\mathbf D\,(V-\Phi\mathbf w_{\mathrm{MC}})=\mathbf 0\quad\Longleftrightarrow\quad\Phi\mathbf w_{\mathrm{MC}}=\Pi V

    Monte Carlo (the best fit) minimizes ∥V−Φw∥μ\norm{V-\Phi\mathbf w}_\mu; its normal equations make the error orthogonal to the features:

  3. Φ⊤D (I−γP) (V−ΦwTD)=0⟹ΦwTD=Φ(Φ⊤D(I−γP)Φ)−1Φ⊤D(I−γP) V\Phi^\top\mathbf D\,(\mathbf I-\gamma P)\,(V-\Phi\mathbf w_{\mathrm{TD}})=\mathbf 0\quad\Longrightarrow\quad\Phi\mathbf w_{\mathrm{TD}}=\Phi\big(\Phi^\top\mathbf D(\mathbf I-\gamma P)\Phi\big)^{-1}\Phi^\top\mathbf D(\mathbf I-\gamma P)\,V

    TD solves Aw=b\mathbf A\mathbf w=\mathbf b, that is Φ⊤D(TπΦw−Φw)=0\Phi^\top\mathbf D(\mathcal T^\pi\Phi\mathbf w-\Phi\mathbf w)=\mathbf 0. This says the projected residual vanishes, Φw=ΠTπΦw\Phi\mathbf w=\Pi\mathcal T^\pi\Phi\mathbf w (the projected Bellman equation), and by the first line it is an oblique projection of VV, with test directions (I−γP)⊤DΦ(\mathbf I-\gamma P)^\top\mathbf D\Phi in place of DΦ\mathbf D\Phi:

  4. Φ⊤(I−γP)⊤D (I−γP) (V−ΦwBR)=0\Phi^\top(\mathbf I-\gamma P)^\top\mathbf D\,(\mathbf I-\gamma P)\,(V-\Phi\mathbf w_{\mathrm{BR}})=\mathbf 0

    Bellman-residual minimization (BR) minimizes ∥TπΦw−Φw∥μ2=∥(I−γP)(V−Φw)∥μ2\norm{\mathcal T^\pi\Phi\mathbf w-\Phi\mathbf w}_\mu^2=\norm{(\mathbf I-\gamma P)(V-\Phi\mathbf w)}_\mu^2, a third projection, with test directions (I−γP)⊤D(I−γP)Φ(\mathbf I-\gamma P)^\top\mathbf D(\mathbf I-\gamma P)\Phi. Scherrer (2010) analyzes all such solutions in this unified oblique-projection view.

Predict before you look

In the same two-state cycle, take γ=0.5\gamma=0.5, where the best fit is wMC=(1+2γ)/(5(1−γ2))≈0.53w_{\mathrm{MC}}=(1+2\gamma)/\big(5(1-\gamma^2)\big)\approx0.53. What is the TD fixed point wTD=1/(5−4γ)w_{\mathrm{TD}}=1/(5-4\gamma)?

Show the answer

0.33

wTD=1/(5−2)=13w_{\mathrm{TD}}=1/(5-2)=\tfrac13. The norm errors are now 0.5≈0.71\sqrt{0.5}\approx0.71 for TD against 0.4≈0.63\sqrt{0.4}\approx0.63 for the best fit, a ratio of 1.12 under the bound 1/1−0.25≈1.151/\sqrt{1-0.25}\approx1.15. Shorter horizons mean less bootstrapping and a smaller gap; as γ→1\gamma\to1 the true values grow like 1/(1−γ)1/(1-\gamma) while wTD→1w_{\mathrm{TD}}\to1 stays bounded.

Contraction in the stationary norm, and the error bound

DerivationProof
  1. ∥PV∥μ2=E[E[V(S′)∣S]2]≤E[E[V(S′)2∣S]]=E[V(S′)2]=∥V∥μ2\norm{PV}_\mu^2=\E\big[\E[V(S')\mid S]^2\big]\le\E\big[\E[V(S')^2\mid S]\big]=\E\big[V(S')^2\big]=\norm{V}_\mu^2

    Non-expansion. Draw S∼μS\sim\mu and S′∼P(S,⋅)S'\sim P(S,\cdot), so that (PV)(S)=E[V(S′)∣S](PV)(S)=\E[V(S')\mid S]. Conditional Jensen, then stationarity (S′∼μS'\sim\mu as well):

  2. y⊤Ay=∥Φy∥μ2−γ ⟨Φy,PΦy⟩μ≥(1−γ) ∥Φy∥μ2>0(y≠0)\mathbf y^\top\mathbf A\mathbf y=\norm{\Phi\mathbf y}_\mu^2-\gamma\,\langle\Phi\mathbf y,P\Phi\mathbf y\rangle_\mu\ge(1-\gamma)\,\norm{\Phi\mathbf y}_\mu^2>0\qquad(\mathbf y\ne\mathbf 0)

    Contraction. TπV−TπU=γP(V−U)\mathcal T^\pi V-\mathcal T^\pi U=\gamma P(V-U), and Π\Pi is an orthogonal projection in ∥⋅∥μ\norm\cdot_\mu, hence non-expansive. Banach's theorem gives a unique fixed point, and Φw=ΠTπΦw\Phi\mathbf w=\Pi\mathcal T^\pi\Phi\mathbf w is exactly Aw=b\mathbf A\mathbf w=\mathbf b. Positive definiteness follows from Cauchy–Schwarz and the first step:

  3. ∥ΠV−vˉ∥μ=∥ΠTπV−ΠTπvˉ∥μ≤γ ∥V−vˉ∥μ\norm{\Pi V-\bar v}_\mu=\norm{\Pi\mathcal T^\pi V-\Pi\mathcal T^\pi\bar v}_\mu\le\gamma\,\norm{V-\bar v}_\mu

    Error bound. Let vˉ=ΦwTD\bar v=\Phi\mathbf w_{\mathrm{TD}}. Split V−vˉV-\bar v into V−ΠVV-\Pi V, which is μ\mu-orthogonal to the span, and ΠV−vˉ\Pi V-\bar v, which lies in it. Since V=TπVV=\mathcal T^\pi V and vˉ=ΠTπvˉ\bar v=\Pi\mathcal T^\pi\bar v, the second piece is a difference of projected backups:

  4. ∥V−vˉ∥μ2=∥V−ΠV∥μ2+∥ΠV−vˉ∥μ2≤∥V−ΠV∥μ2+γ2∥V−vˉ∥μ2 ⟹ ∥V−vˉ∥μ≤∥V−ΠV∥μ1−γ2■\norm{V-\bar v}_\mu^2=\norm{V-\Pi V}_\mu^2+\norm{\Pi V-\bar v}_\mu^2\le\norm{V-\Pi V}_\mu^2+\gamma^2\norm{V-\bar v}_\mu^2\ \Longrightarrow\ \norm{V-\bar v}_\mu\le\frac{\norm{V-\Pi V}_\mu}{\sqrt{1-\gamma^2}}\qquad\blacksquare

    Pythagoras, then rearrange:

Stationarity is used exactly once, in the first line, and that is where off-policy learning breaks. If μ\mu is a behavior distribution that is not stationary for the target policy's PP, then PP can expand ∥⋅∥μ\norm\cdot_\mu, ΠTπ\Pi\mathcal T^\pi need not contract, A\mathbf A can have eigenvalues with negative real part, and a fixed point, when one exists, carries no guarantee: Kolter (2011) shows the error of the off-policy TD solution can be unboundedly large, and that restricting the sampling distribution to a certain convex set restores on-policy-like guarantees. Divergence: Baird’s Counterexample computes such an A\mathbf A explicitly.

Least-squares TD and LSPI

Semi-gradient TD approaches A−1b\mathbf A^{-1}\mathbf b by many small, noisy steps. Least-squares TD (Bradtke & Barto, 1996; LSTD(λ\lambda): Boyan, 1999, 2002) estimates A\mathbf A and b\mathbf b from a trajectory and solves for the fixed point directly:

A^n=1n∑t=0n−1xt(xt−γxt+1)⊤,b^n=1n∑t=0n−1Rt+1xt,w^n=A^n−1b^n.\hat{\mathbf A}_n=\frac1n\sum_{t=0}^{n-1}\mathbf x_t(\mathbf x_t-\gamma\mathbf x_{t+1})^\top,\qquad\hat{\mathbf b}_n=\frac1n\sum_{t=0}^{n-1}R_{t+1}\mathbf x_t,\qquad\hat{\mathbf w}_n=\hat{\mathbf A}_n^{-1}\hat{\mathbf b}_n.

On-policy, the ergodic averages converge to A\mathbf A and b\mathbf b, so w^n→wTD\hat{\mathbf w}_n\to\mathbf w_{\mathrm{TD}} with no step size to tune. Each sample adds a rank-one term to A\mathbf A, so the Sherman–Morrison formula updates A^−1\hat{\mathbf A}^{-1} in O(d2)\order{d^2} per step, against O(d)\order{d} for TD and O(d3)\order{d^3} for a fresh solve.

python
import numpy as np

def lstd(transitions, d, gamma, eps=1e-3):
    """Recursive LSTD(0); transitions are (x, r, x_next), x_next = 0 at termination."""
    A_inv = np.eye(d) / eps               # inverse of the regularizer eps * I
    b = np.zeros(d)
    for x, r, x_next in transitions:
        u = x - gamma * x_next            # this sample adds outer(x, u) to A
        Ax = A_inv @ x
        A_inv -= np.outer(Ax, u @ A_inv) / (1.0 + u @ Ax)   # Sherman-Morrison
        b += r * x
    return A_inv @ b                      # w = A^{-1} b

On a long trajectory of the two-state cycle with γ=0.9\gamma=0.9 this returns w≈0.7143=57w\approx0.7143=\tfrac57, the TD fixed point, not the best fit 2.95. The regularizer ε\varepsilon matters only while A^\hat{\mathbf A} is poorly determined.

LSPI (Lagoudakis & Parr, 2003) turns LSTD into control. LSTDQ evaluates a policy π\pi on state–action features from a fixed batch of transitions (s,a,r,s′)(s,a,r,s'), using x(s′,π(s′))\mathbf x(s',\pi(s')) as the next feature: the batch can come from any behavior policy and is reused at every iteration. The greedy policy for the result is evaluated next, until the weights stop changing. Approximate policy iteration guarantees lim sup⁡k∥Q⋆−Qπk∥∞≤2γε/(1−γ)2\limsup_k\norm{Q^\star-Q^{\pi_k}}_\infty\le2\gamma\varepsilon/(1-\gamma)^2 when every evaluation is ε\varepsilon-accurate in the max norm (Bertsekas & Tsitsiklis, 1996). LSPI's errors are least-squares errors, so its guarantees go through weighted norms and assumptions on the state distributions of the greedy policies (Lazaric et al., 2012); in practice it may cycle among a few policies instead of converging.

Why not minimize the Bellman residual?

The residual ∥Tπv^−v^∥μ2\norm{\mathcal T^\pi\hat v-\hat v}_\mu^2 is a genuine objective, so true gradient descent on it seems cleaner than TD. Baird's (1995) residual-gradient algorithm does exactly that. Two problems undo it.

Double sampling. From one sampled transition, δt2\delta_t^2 estimates the wrong thing:

E[δt2∣St=s]=(E[δt∣St=s])2+Var⁡[Rt+1+γv^(St+1,w)∣St=s].\E\big[\delta_t^2\mid S_t=s\big]=\big(\E[\delta_t\mid S_t=s]\big)^2+\Var\big[R_{t+1}+\gamma\hat v(S_{t+1},\mathbf w)\mid S_t=s\big].

The first term is the Bellman residual. The second depends on w\mathbf w too, so minimizing the mean squared TD error also flattens v^\hat v across the possible next states, a bias that persists with infinite data. An unbiased gradient of the residual needs two independent next states from the same ss, which requires a simulator that can be reset; Antos, Szepesvári & Munos (2008) instead subtract a fitted estimate of the variance term, which leads to a min–max problem.

Learnability. Sutton & Barto (§11.6) construct two Markov reward processes that emit identically distributed streams of features and rewards but whose Bellman-residual minimizers differ. No amount of data from the stream can tell which minimizer is right: the residual objective is not a function of the data distribution. The projected Bellman error and the TD fixed point are, since they depend only on A\mathbf A, b\mathbf b and E[xx⊤]\E[\mathbf x\mathbf x^\top].

Check your understanding

In a state with random next states, v^\hat v equals the true values exactly, so E[δt∣St=s]=0\E[\delta_t\mid S_t=s]=0. What happens if you minimize the average of δt2\delta_t^2 over single sampled transitions?

  1. Nothing changes: the true values already minimize the mean squared TD error
  2. The minimizer moves away from the true values, toward estimates that make the next-state target less variable
  3. The objective becomes zero at the true values
  4. The minimizer moves toward the Monte Carlo solution
Show the answer

B. The minimizer moves away from the true values, toward estimates that make the next-state target less variable

At the true values, E[δt2∣s]=Var⁡[R+γv^(S′)∣s]>0\E[\delta_t^2\mid s]=\Var[R+\gamma\hat v(S')\mid s]>0, and that variance can be reduced by changing v^\hat v, for example by making the values of the possible next states more alike. So the minimizer of the sampled objective is biased away from VπV^\pi. Residual gradient with two independent next-state samples avoids this, at the price of needing a resettable simulator.

EstimatorError orthogonal toLearnable from one trajectory?Guarantee
Monte Carlo (best fit)DΦ\mathbf D\PhiYesOptimal in ∥⋅∥μ\norm\cdot_\mu; high-variance returns
TD fixed point / LSTD(I−γP)⊤DΦ(\mathbf I-\gamma P)^\top\mathbf D\PhiYesOn-policy: within 1/1−γ21/\sqrt{1-\gamma^2} of the best; off-policy: none in general
Bellman residual(I−γP)⊤D(I−γP)Φ(\mathbf I-\gamma P)^\top\mathbf D(\mathbf I-\gamma P)\PhiNo (needs double samples)A bound for any μ\mu (Scherrer, 2010), but often worse in practice
Scherrer (2010) finds no universal winner: TD's solution was usually slightly better than BR's in his experiments, but numerically unstable and very bad in some cases, which made it worse on average.

Key takeaways

  • Monte Carlo, TD and Bellman-residual minimization each compute a projection of VπV^\pi onto the feature span; only Monte Carlo's is orthogonal, TD's is oblique through I−γP\mathbf I-\gamma P.
  • On-policy, ΠTπ\Pi\mathcal T^\pi is a γ\gamma-contraction in ∥⋅∥μ\norm\cdot_\mu, and ∥ΦwTD−Vπ∥μ≤∥ΠVπ−Vπ∥μ/1−γ2\norm{\Phi\mathbf w_{\mathrm{TD}}-V^\pi}_\mu\le\norm{\Pi V^\pi-V^\pi}_\mu/\sqrt{1-\gamma^2}; a two-state cycle comes within 6% of this factor at γ=0.9\gamma=0.9.
  • LSTD solves A^w=b^\hat{\mathbf A}\mathbf w=\hat{\mathbf b} in O(d2)\order{d^2} per sample, equals certainty equivalence in a least-squares linear model, and needs about d/((1−γ)2ε2)d/((1-\gamma)^2\varepsilon^2) samples beyond its approximation error.
  • LSPI reuses one batch for approximate policy iteration with LSTDQ; its guarantees inherit the 2γε/(1−γ)22\gamma\varepsilon/(1-\gamma)^2 structure of approximate policy iteration.
  • Residual minimization needs double samples, and the residual is not learnable from trajectories; the TD fixed point is.

Check yourself

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

Question 1

The TD fixed point satisfies Φ⊤D(I−γP)(Vπ−Φw)=0\Phi^\top\mathbf D(\mathbf I-\gamma P)(V^\pi-\Phi\mathbf w)=\mathbf 0. What does this say geometrically?

  1. Φw\Phi\mathbf w is the μ\mu-orthogonal projection of VπV^\pi onto the feature span
  2. Φw\Phi\mathbf w minimizes the Bellman residual
  3. Φw\Phi\mathbf w is an oblique projection of VπV^\pi: the error is orthogonal to the directions (I−γP)⊤DΦ(\mathbf I-\gamma P)^\top\mathbf D\Phi rather than to DΦ\mathbf D\Phi
  4. Φw=Vπ\Phi\mathbf w=V^\pi whenever D\mathbf D is the stationary distribution
Show the answer

C. Φw\Phi\mathbf w is an oblique projection of VπV^\pi: the error is orthogonal to the directions (I−γP)⊤DΦ(\mathbf I-\gamma P)^\top\mathbf D\Phi rather than to DΦ\mathbf D\Phi

Orthogonality to DΦ\mathbf D\Phi would give the best fit ΠVπ\Pi V^\pi; TD's test directions are distorted by I−γP\mathbf I-\gamma P. That distortion is why its error can exceed the best fit's, by at most 1/1−γ21/\sqrt{1-\gamma^2} on-policy.

Question 2

Where does the proof that ΠTπ\Pi\mathcal T^\pi is a γ\gamma-contraction in ∥⋅∥μ\norm\cdot_\mu use that μ\mu is the stationary distribution of PπP^\pi?

  1. To show that Π\Pi is a projection
  2. To show that PπP^\pi does not expand ∥⋅∥μ\norm\cdot_\mu: if S∼μS\sim\mu then also S′∼μS'\sim\mu
  3. To show that the features are linearly independent
  4. It is not used; the result holds for any μ\mu
Show the answer

B. To show that PπP^\pi does not expand ∥⋅∥μ\norm\cdot_\mu: if S∼μS\sim\mu then also S′∼μS'\sim\mu

Jensen gives ∥PπV∥μ2≤E[V(S′)2]\norm{P^\pi V}_\mu^2\le\E[V(S')^2], and stationarity turns the right side into ∥V∥μ2\norm{V}_\mu^2. For a behavior distribution that is not stationary for PπP^\pi, E[V(S′)2]\E[V(S')^2] can exceed ∥V∥μ2\norm V_\mu^2, and the contraction, and with it the stability of TD, can fail.

Question 3

Why does recursive LSTD cost O(d2)\order{d^2} per transition rather than O(d3)\order{d^3}?

  1. Each transition adds a rank-one matrix to A^\hat{\mathbf A}, so Sherman–Morrison updates the inverse with matrix–vector products
  2. LSTD only stores the diagonal of A^\hat{\mathbf A}
  3. LSTD uses a step size that removes the need for a matrix
  4. The features are binary
Show the answer

A. Each transition adds a rank-one matrix to A^\hat{\mathbf A}, so Sherman–Morrison updates the inverse with matrix–vector products

A^\hat{\mathbf A} grows by xt(xt−γxt+1)⊤\mathbf x_t(\mathbf x_t-\gamma\mathbf x_{t+1})^\top, a rank-one term, and (M+xu⊤)−1=M−1−M−1xu⊤M−1/(1+u⊤M−1x)(\mathbf M+\mathbf x\mathbf u^\top)^{-1}=\mathbf M^{-1}-\mathbf M^{-1}\mathbf x\mathbf u^\top\mathbf M^{-1}/(1+\mathbf u^\top\mathbf M^{-1}\mathbf x) costs a few d×dd\times d products with vectors. TD's O(d)\order{d} per step remains cheaper, which matters when dd is large.

Question 4

Why do Sutton and Barto conclude that the Bellman-residual objective should not be the target of learning from trajectories?

  1. It is not differentiable
  2. Two environments can produce identically distributed data yet have different residual minimizers, so no amount of data identifies the right one
  3. Its minimum is always the TD fixed point
  4. It requires knowing the reward function
Show the answer

B. Two environments can produce identically distributed data yet have different residual minimizers, so no amount of data identifies the right one

An objective that is not a function of the data distribution cannot be estimated from data, even infinitely much. The TD fixed point and the projected Bellman error depend only on expectations over observed transitions, so they can.

Further reading

  • J. N. Tsitsiklis & B. Van Roy, "An analysis of temporal-difference learning with function approximation", IEEE Transactions on Automatic Control 42(5) (1997).
  • S. J. Bradtke & A. G. Barto, "Linear least-squares algorithms for temporal difference learning", Machine Learning 22 (1996).
  • M. G. Lagoudakis & R. Parr, "Least-squares policy iteration", Journal of Machine Learning Research 4 (2003).
  • A. Lazaric, M. Ghavamzadeh & R. Munos, "Finite-sample analysis of least-squares policy iteration", Journal of Machine Learning Research 13 (2012).
  • B. Scherrer, "Should one compute the temporal difference fix point or minimize the Bellman residual? The unified oblique projection view", ICML (2010).