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 and as an oblique projection of , and contrast it with the orthogonal projection and the Bellman-residual solution.
- Prove that is a -contraction in the norm of the stationary distribution and derive the error bound, including its TD() form.
- Derive LSTD with an 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 on a finite MDP with transition matrix , reward vector and value . Let hold the features as rows (full column rank), let be a distribution with all , , and . The -orthogonal projection onto the feature span is
the map to the closest point of in . The fixed points of the three standard linear estimators are all projections of onto that span; they differ only in which directions the remaining error must be orthogonal to.
Because , the Bellman residual of any linear estimate is the true error pushed through :
Monte Carlo (the best fit) minimizes ; its normal equations make the error orthogonal to the features:
TD solves , that is . This says the projected residual vanishes, (the projected Bellman equation), and by the first line it is an oblique projection of , with test directions in place of :
Bellman-residual minimization (BR) minimizes , a third projection, with test directions . Scherrer (2010) analyzes all such solutions in this unified oblique-projection view.
In the same two-state cycle, take , where the best fit is . What is the TD fixed point ?
Show the answer
0.33
. The norm errors are now for TD against for the best fit, a ratio of 1.12 under the bound . Shorter horizons mean less bootstrapping and a smaller gap; as the true values grow like while stays bounded.
Contraction in the stationary norm, and the error bound
Non-expansion. Draw and , so that . Conditional Jensen, then stationarity ( as well):
Contraction. , and is an orthogonal projection in , hence non-expansive. Banach's theorem gives a unique fixed point, and is exactly . Positive definiteness follows from Cauchy–Schwarz and the first step:
Error bound. Let . Split into , which is -orthogonal to the span, and , which lies in it. Since and , the second piece is a difference of projected backups:
Pythagoras, then rearrange:
Stationarity is used exactly once, in the first line, and that is where off-policy learning breaks. If is a behavior distribution that is not stationary for the target policy's , then can expand , need not contract, 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 explicitly.
Least-squares TD and LSPI
Semi-gradient TD approaches by many small, noisy steps. Least-squares TD (Bradtke & Barto, 1996; LSTD(): Boyan, 1999, 2002) estimates and from a trajectory and solves for the fixed point directly:
On-policy, the ergodic averages converge to and , so with no step size to tune. Each sample adds a rank-one term to , so the Sherman–Morrison formula updates in per step, against for TD and for a fresh solve.
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} bOn a long trajectory of the two-state cycle with this returns , the TD fixed point, not the best fit 2.95. The regularizer matters only while is poorly determined.
LSPI (Lagoudakis & Parr, 2003) turns LSTD into control. LSTDQ evaluates a policy on state–action features from a fixed batch of transitions , using 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 when every evaluation is -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 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, estimates the wrong thing:
The first term is the Bellman residual. The second depends on too, so minimizing the mean squared TD error also flattens 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 , 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 , and .
In a state with random next states, equals the true values exactly, so . What happens if you minimize the average of over single sampled transitions?
- Nothing changes: the true values already minimize the mean squared TD error
- The minimizer moves away from the true values, toward estimates that make the next-state target less variable
- The objective becomes zero at the true values
- 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, , and that variance can be reduced by changing , for example by making the values of the possible next states more alike. So the minimizer of the sampled objective is biased away from . Residual gradient with two independent next-state samples avoids this, at the price of needing a resettable simulator.
| Estimator | Error orthogonal to | Learnable from one trajectory? | Guarantee |
|---|---|---|---|
| Monte Carlo (best fit) | Yes | Optimal in ; high-variance returns | |
| TD fixed point / LSTD | Yes | On-policy: within of the best; off-policy: none in general | |
| Bellman residual | No (needs double samples) | A bound for any (Scherrer, 2010), but often worse in practice |
Key takeaways
- Monte Carlo, TD and Bellman-residual minimization each compute a projection of onto the feature span; only Monte Carlo's is orthogonal, TD's is oblique through .
- On-policy, is a -contraction in , and ; a two-state cycle comes within 6% of this factor at .
- LSTD solves in per sample, equals certainty equivalence in a least-squares linear model, and needs about samples beyond its approximation error.
- LSPI reuses one batch for approximate policy iteration with LSTDQ; its guarantees inherit the 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.
The TD fixed point satisfies . What does this say geometrically?
- is the -orthogonal projection of onto the feature span
- minimizes the Bellman residual
- is an oblique projection of : the error is orthogonal to the directions rather than to
- whenever is the stationary distribution
Show the answer
C. is an oblique projection of : the error is orthogonal to the directions rather than to
Orthogonality to would give the best fit ; TD's test directions are distorted by . That distortion is why its error can exceed the best fit's, by at most on-policy.
Where does the proof that is a -contraction in use that is the stationary distribution of ?
- To show that is a projection
- To show that does not expand : if then also
- To show that the features are linearly independent
- It is not used; the result holds for any
Show the answer
B. To show that does not expand : if then also
Jensen gives , and stationarity turns the right side into . For a behavior distribution that is not stationary for , can exceed , and the contraction, and with it the stability of TD, can fail.
Why does recursive LSTD cost per transition rather than ?
- Each transition adds a rank-one matrix to , so Sherman–Morrison updates the inverse with matrix–vector products
- LSTD only stores the diagonal of
- LSTD uses a step size that removes the need for a matrix
- The features are binary
Show the answer
A. Each transition adds a rank-one matrix to , so Sherman–Morrison updates the inverse with matrix–vector products
grows by , a rank-one term, and costs a few products with vectors. TD's per step remains cheaper, which matters when is large.
Why do Sutton and Barto conclude that the Bellman-residual objective should not be the target of learning from trajectories?
- It is not differentiable
- Two environments can produce identically distributed data yet have different residual minimizers, so no amount of data identifies the right one
- Its minimum is always the TD fixed point
- 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).