Forward & Backward Views of TD(λ)
Why traces implement λ-returns, and true online TD(λ).
Sutton's TD(λ) of 1988 came with an identity for : summed over an episode, its updates equal those of the Monte Carlo (Widrow–Hoff) rule. With Watkins's λ-return as the forward view, Sutton and Barto (1998) extended it to every : the backward view's summed updates equal the forward view's. The identity needs the values to stand still, and real TD(λ) moves them at every step, so for a quarter of a century the online algorithm was understood only as an approximation, one that can even blow up. True online TD(λ) (van Seijen & Sutton, 2014) closed the gap exactly, with a new kind of trace. This lesson proves the off-line equivalence in general form, shows how and why the online algorithm drifts, derives dutch traces in the simplest case, and ends with what linear TD(λ) converges to and how good that answer is.
What you’ll learn
- Prove the off-line equivalence of the forward and backward views under linear function approximation, and identify its cases with every-visit and first-visit Monte Carlo.
- Explain why online TD(λ) departs from the forward view, and why accumulating traces can make it unstable at large and .
- Define the online λ-return algorithm, state the true online TD(λ) equivalence theorem, and derive the dutch trace in the Monte Carlo case.
- State Tsitsiklis and Van Roy's convergence theorem for linear TD(λ) and prove its error bound, including how it depends on .
The off-line equivalence, in general
Work with linear values , writing and at the end of the episode; the tabular case is . With held fixed during an episode:
- the forward view (off-line λ-return algorithm) sums the increments ;
- the backward view (off-line TD(λ)) sums , with and the accumulating trace , .
The λ-return recursion of n-Step Returns & Eligibility Traces, with in place of , gives the error of each target as a sum of later TD errors:
Multiply by , sum over , and exchange the order of summation over the triangle :
Nothing about linearity was used beyond the fact that the gradient does not depend on , which is why the off-line equality holds for linear (and tabular) values and not for nonlinear ones, whose gradients move with the weights.
Two Monte Carlo methods in disguise. Take the tabular case with and . The accumulating trace of a state counts its visits so far, and the theorem turns off-line TD(1) into every-visit Monte Carlo: one increment per visit. The replacing trace sets at each visit instead. Each TD error after the first visit then gets weight exactly 1, once, so the total increment is , with the first visit: first-visit Monte Carlo (Singh & Sutton, 1996). Their properties, first-visit unbiased and every-visit biased but consistent, are analyzed in Monte Carlo Estimation in Depth.
Off-line, tabular, : a state is visited at times 3 and 7 of an episode, and is its current estimate. What total update do accumulating and replacing traces produce for it?
- Accumulating: ; replacing:
- Both:
- Accumulating: ; replacing:
- Both:
Show the answer
C. Accumulating: ; replacing:
The accumulating trace is 1 between the visits and 2 after the second, so TD errors after time 7 are counted twice: that is one increment per visit, every-visit Monte Carlo. The replacing trace stays at 1 from the first visit on, so every later TD error is counted once, and they sum to : first-visit Monte Carlo.
Online, the views drift apart
Online TD(λ) updates at every step, so is computed with weights already moved by the episode's earlier updates. The exchange of sums still goes through, but the TD errors in it are no longer the ones a fixed would produce: the online and off-line totals differ by terms of second order in . This difference cuts both ways. Bootstrapping from estimates improved earlier in the same episode helps, which is why online TD(λ) often learns faster at small . At large the same feedback can turn into instability.
The culprit is the accumulating trace of a state that is revisited often. With it simply counts visits. On the 19-state random walk a walk from the middle lasts 100 steps on average and visits the middle state 10 times on average, often far more. A TD error that measures the state's own error is applied with the factor : beyond 1 the correction overshoots the target, and beyond 2 it overshoots by more than the error it corrects, so the errors grow. Every-visit Monte Carlo with the same applies the same kind of increments one at a time at the end of the walk, each moving a fraction toward a return in , and cannot blow up.
Sutton and Barto's comparison on the same walk (their Figure 12.6) shows the pattern: at step sizes up to each 's best, online TD(λ) and the off-line λ-return algorithm perform almost identically; above it, TD(λ) is much worse and can be unstable, while the λ-return algorithm degrades only a little. Is there an online algorithm that keeps the forward view's robustness and TD(λ)'s cost? Yes, but it needs a different forward view and a different trace.
True online TD(λ) and dutch traces
An online forward view. At time the data reach only to , so a forward view that learns during the episode must use truncated λ-returns, which put the remaining weight on the longest return available:
The online λ-return algorithm redoes, at every new horizon , all of the episode's updates from its initial weights, for , with the returns bootstrapping from the weights computed along the way. Its weights use all the data so far, but its cost per step grows with the length of the episode. On the 19-state walk it performs slightly better than the off-line λ-return algorithm (Sutton and Barto, Figure 12.8).
Take the simplest forward view: linear Monte Carlo with a single final return and , updating at every step toward . With the fading matrix , each update is affine in the weights:
Unroll to the end of the episode. is unknown until then, but it multiplies a sum that can be built along the way:
Both vectors update online in order- time: , and the trace satisfies , that is,
This is the dutch trace with , and reproduces the Monte Carlo result exactly without storing the episode. A trace appeared with no TD learning in sight: traces are what efficient online computation of a forward view looks like. The true online derivation follows the same plan with bootstrapping and , along the diagonal of the online λ-return algorithm's triangle of weights.
Tabular dutch traces. With , the visited state's trace becomes while all others decay by . With this is a replacing trace; with it approaches an accumulating one. With it can never exceed , so : no state's own correction can overshoot, which removes the mechanism of the blow-up above. Sutton and Barto now regard replacing traces as crude approximations to dutch traces, which usually perform better and rest on a clearer theory; accumulating traces remain in use with nonlinear function approximation, where no dutch trace is available.
A state is visited at three consecutive steps, starting from trace 0, with and . What is its tabular dutch trace after the third visit? (An accumulating trace would be 3, a replacing trace 1.)
Show the answer
2.71
at each visit: , then , then . After many visits it approaches and never passes it, so stays below 1.
Linear TD(λ): where it converges, and how good the answer is
Under the stationary distribution, (Jensen's inequality and stationarity). The linear part of is , so is a contraction in with modulus
is an orthogonal projection in the same norm, hence non-expansive, so is a -contraction with a unique fixed point . Now lies in the feature space and is -orthogonal to it, so Pythagoras applies:
Since , the first term is . Rearranging:
Finally , which gives Tsitsiklis and Van Roy's factor; squaring instead, , which is Sutton and Barto's version for the squared value error.
With , Tsitsiklis and Van Roy's factor is 100 for TD(0). What is it for ?
Show the answer
10.9
. The sharper factor is about 7.1 for TD(0) and 2.4 for (). At both equal 1: TD(1) finds the best approximation in the span, .
So trades two kinds of error. Larger moves the fixed point toward the best approximation in the feature space, but makes the updates noisier, and the bound says nothing about how many samples each setting needs. The bound is a worst case: with good features, TD(0)'s fixed point is often much closer than times the best error. The whole argument needs the stationary distribution of itself, through ; with off-policy sampling that inequality fails, and so can convergence (The Deadly Triad). The Projected Bellman Equation & LSTD develops the fixed point and its least-squares solution.
Key takeaways
- Off-line, for linear or tabular values, the backward view's summed updates equal the forward view's : one exchange of summations, path by path. With , accumulating traces give every-visit and replacing traces first-visit Monte Carlo.
- Online, TD errors use weights that changed earlier in the episode; the views then differ at second order in , which helps at small and can destabilize accumulating traces at large and .
- True online TD(λ) reproduces the online λ-return algorithm exactly for linear values, in order- time, using the dutch trace ; in tables it keeps when .
- On-policy linear TD(λ) converges to the fixed point of , a -contraction, with error at most (sharper: ) times the best approximation error.
Check yourself
In the interactive lesson these are scored with your confidence, and what you miss comes back for review.
What does the proof of the off-line equivalence rest on?
- The contraction of the Bellman operator
- Writing each λ-return error as a -discounted sum of TD errors computed with one fixed , then exchanging the order of summation, which collects each TD error's coefficients into the trace
- The Markov property of the environment
- Taking expectations over the episode
Show the answer
B. Writing each λ-return error as a -discounted sum of TD errors computed with one fixed , then exchanging the order of summation, which collects each TD error's coefficients into the trace
The identity is algebraic and holds on every sample path: no expectation, no contraction and no Markov property is involved. It needs fixed weights (so that each is the same number in both views) and gradients that do not depend on .
On the 19-state walk with and , online TD(λ) with accumulating traces blows up, while every-visit Monte Carlo with the same does not. Why?
- Because Monte Carlo uses a smaller effective discount
- Because TD(λ) bootstraps from terminal states
- Because TD errors with are biased
- Because a frequently revisited state's accumulating trace grows far above 1, so its own TD errors move its value by times the error, which overshoots once
Show the answer
D. Because a frequently revisited state's accumulating trace grows far above 1, so its own TD errors move its value by times the error, which overshoots once
With the trace counts the visits so far. In long walks the middle states are revisited dozens of times, passes 2, and each correction overshoots by more than it corrects. Monte Carlo applies each visit's increment separately, always moving a fraction toward a bounded return.
In the tabular case, how does a dutch trace change at a visit, and what does that guarantee when ?
- ; it guarantees nothing about the size of
- ; it guarantees
- ; it guarantees , so the visited state's own correction never exceeds 1
- ; it guarantees that traces vanish between visits
Show the answer
C. ; it guarantees , so the visited state's own correction never exceeds 1
With , , which for the visited state is . Its fixed point under repeated visits is , equal to when .
In Tsitsiklis and Van Roy's bound , what happens as increases from 0 to 1, and what is the catch?
- The factor falls from to 1, so TD(1)'s fixed point is the best approximation ; the catch is noisier updates, which the bound does not measure
- The factor grows, so larger is always worse
- The factor is constant; only changes the speed
- The factor falls to 0, so TD(1) recovers exactly with any features
Show the answer
A. The factor falls from to 1, so TD(1)'s fixed point is the best approximation ; the catch is noisier updates, which the bound does not measure
At the factor is 1 and , the best the features allow. Smaller bootstraps more, which can amplify the approximation error by up to but reduces variance. In practice intermediate usually learns best.
Further reading
- R. S. Sutton, "Learning to predict by the methods of temporal differences," Machine Learning 3, 9–44 (1988).
- S. P. Singh & R. S. Sutton, "Reinforcement learning with replacing eligibility traces," Machine Learning 22, 123–158 (1996).
- H. van Seijen & R. S. Sutton, "True online TD(λ)," Proceedings of the 31st International Conference on Machine Learning, 692–700 (2014).
- H. van Seijen, A. R. Mahmood, P. M. Pilarski, M. C. Machado & R. S. Sutton, "True online temporal-difference learning," Journal of Machine Learning Research 17(145), 1–40 (2016).
- 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).