Temporal Difference Learning: TD(0), TD(λ), and Eligibility Traces
4478 words
22 min read
Visual companion
Python
Type and operator map
Python Week 1: the first filter for runtime behavior
View
Revision summary
What this note is really saying
Short form
# Temporal Difference Learning: TD(0), TD(λ), and Eligibility Traces ## 🎯 Learning Objectives - Understand how TD learning combines ideas from DP (bootstrapping) and MC (sampling) - Implement TD(0) for policy evaluation - Analyze the bias-variance tradeoff between MC and TD - Extend to n-step TD and TD(λ) with elig...

Temporal Difference Learning: TD(0), TD(λ), and Eligibility Traces
🎯 Learning Objectives
- Understand how TD learning combines ideas from DP (bootstrapping) and MC (sampling)
- Implement TD(0) for policy evaluation
- Analyze the bias-variance tradeoff between MC and TD
- Extend to n-step TD and TD(λ) with eligibility traces
- Understand the forward and backward views of TD(λ)
📋 Prerequisites
- MDPs (Week 2): Returns, value functions, Bellman equations
- MC Methods (Week 4): Episode-based learning, returns
- Dynamic Programming (Week 3): Bootstrapping concept
1. 📖 Core Content
1.1 Intuition: Learning from Every Step
Imagine you're learning to drive. You don't wait until the trip ends to decide if you drove well. After every turn, you think: "That turn felt good — I'm improving." You update your driving skill based on partial feedback.
That's Temporal Difference (TD) learning.
TD learning is the central idea of reinforcement learning. It combines:
- Monte Carlo's sampling: Learning from real experience (no model needed)
- DP's bootstrapping: Updating estimates based on other estimates The TD update is:
This uses:
- The actual reward R (like MC — real experience)
- The estimated value of the next state V(s′) (like DP — bootstrapping) Why does this matter? TD is the reason RL scales to large problems:
- Learns from incomplete episodes (unlike MC)
- Doesn't need a model (unlike DP)
- Updates online at every step
- Works for continuing tasks (unlike MC)
1.2 TD Prediction (Policy Evaluation)
1.2.1 TD(0) Algorithm
textInitialize V(s) arbitrarily α ∈ (0, 1] (learning rate) loop for each episode: Initialize S for each step of episode: Take action A from policy π(S) Observe reward R and next state S' V(S) ← V(S) + α[R + γ V(S') - V(S)] S ← S' until S is terminal
The quantity δt=Rt+1+γV(St+1)−V(St) is the TD error. It measures the difference between the predicted value V(St) and the "better estimate" Rt+1+γV(St+1).
1.2.2 Worked Example 1: TD(0) on a Simple Chain
Consider a 5-state chain (A-B-C-D-E). Terminal state E (reward 0 when reached). All other transitions: reward 0. γ = 1. Random walk policy: move left or right with equal probability.
Initialize V(s) = 0 for all s. α = 0.1.
Episode 1: Start at C. Path: C → D → E (terminal).
Step 1: S=C, A=right (p=0.5), R=0, S'=D V(C) = 0 + 0.1[0 + 1(0) - 0] = 0 (no change)
Step 2: S=D, A=right, R=0, S'=E V(D) = 0 + 0.1[0 + 1(0) - 0] = 0 (no change)
Episode 1 produces no learning — all values are still 0.
Episode 2: Start at D. Path: D → E (terminal).
Step 1: S=D, A=right, R=0, S'=E V(D) = 0 + 0.1[0 + 1(0) - 0] = 0
Still no learning! The problem is that no one has reached E's terminal value (0) to propagate it backward.
Episode 3: Start at D. Path: D → C → B → A (left moves).
Step 1: S=D, A=left, R=0, S'=C V(D) = 0 + 0.1[0 + 1(0) - 0] = 0
Still nothing. Let's try an episode that reaches terminal with a reward...
Actually, in this chain with reward 0 everywhere and γ=1, the true value of all states is 0 (since total return is always 0). The TD algorithm correctly stays at 0 everywhere. Let's change the reward structure:
New reward: +1 when reaching E from D. γ = 0.9.
Episode 1: C → D(p=0.5 right) → E(p=0.5 right).
Step 1: S=C, R=0, S'=D V(C) = 0 + 0.1[0 + 0.9(0) - 0] = 0
Step 2: S=D, R=1 (rewards from D→E), S'=E (terminal) V(D) = 0 + 0.1[1 + 0.9(0) - 0] = 0.1
Now V(D) = 0.1. Good.
Episode 2: C → D → E again.
Step 1: S=C, R=0, S'=D V(C) = 0 + 0.1[0 + 0.9(0.1) - 0] = 0.009
Step 2: S=D, R=1, S'=E V(D) = 0.1 + 0.1[1 + 0 - 0.1] = 0.1 + 0.09 = 0.19
After many episodes, V(D) → 1 (true value: one step from terminal with reward 1, γ=0.9 → V(D) = 1). V(C) → γ² × 1 = 0.81.
1.3 MC vs TD: Bias-Variance Tradeoff
| Aspect | Monte Carlo | TD(0) |
|---|---|---|
| Update target | Gt (complete return) | Rt+1+γV(St+1) |
| Bias | 0 (unbiased) | Biased (uses current estimate) |
| Variance | High (sum of many random rewards) | Low (only one random reward + estimate) |
| Episode needed | Complete episode | Any single step |
| Continuing tasks | No (needs termination) | Yes |
| Convergence | To Vπ | To Vπ (with decreasing α) |
Worked Example 2: MC vs TD on a Random Walk
Consider a 7-state random walk. States A-G. Terminal states: A (left end, reward 0) and G (right end, reward 1). Starting from D. Actions: move left or right. γ = 1.
After 100 episodes:
MC: Starting value estimates 0. After first right-terminating episode: V(D)=1. After second left-terminating episode: V(D)=(1+0)/2=0.5. MC bounces between 0 and 1 for visited states until many episodes average out.
TD(0): After first episode (right to G): V(D) updated by α[0 + V(E) - V(D)]. If V(E)=0, V(D) increases by α×0 = 0. Wait — TD(0) needs V(E) to be non-zero first!
Actually, let me trace this more carefully.
Episode 1: D → E → F → G (right each time), γ=1, α=0.1, all V=0 initially.
Step 1: S=D, R=0, S'=E. V(D) += 0.1[0 + 1(0) - 0] = 0. Step 2: S=E, R=0, S'=F. V(E) += 0.1[0] = 0. Step 3: S=F, R=0, S'=G. V(F) += 0.1[0] = 0.
No learning! The reward hasn't reached any state yet. TD updates based on the next state's value, but all values are 0.
Episode 2: F → G (right).
Step 1: S=F, R=0, S'=G. V(F) += 0.1[0 + 1(0) - 0] = 0.
Episode 3: G (terminal). No update needed.
Episode 4: D → C → B → A (left each time). No reward (terminal A gives 0). No learning.
The problem is that in this random walk, the reward at terminal G is never propagated because TD only updates a state when it visits a successor. The reward needs to "propagate" backward one step at a time.
Episode 5: F → G. Step 1: S=F, R=0, S'=G. V(F) += 0.1[0 + 1(0) - 0] = 0. STILL ZERO!
Ah wait, the terminal state G has value V(G) = 0? No! Terminal states should have value equal to the immediate reward. If G gives reward +1, then V(G) should be 1 from the start.
Let me correct: Terminal states have value equal to their expected return. G is terminal with reward +1, so V(G) = 1. Similarly, A is terminal with reward 0, so V(A) = 0.
Now redo:
Episode 1: D → E → F → G. γ=1, α=0.1.
Step 1: S=D, R=0, S'=E. V(D) = 0 + 0.1[0 + 1(0) - 0] = 0. Step 2: S=E, R=0, S'=F. V(E) = 0 + 0.1[0 + 1(0) - 0] = 0. Step 3: S=F, R=0, S'=G (terminal). V(F) = 0 + 0.1[0 + 1(1) - 0] = 0.1.
Now V(F) = 0.1.
Episode 2: E → F → G.
Step 1: S=E, R=0, S'=F. V(E) = 0 + 0.1[0 + 1(0.1) - 0] = 0.01. Step 2: S=F, R=0, S'=G. V(F) = 0.1 + 0.1[0 + 1(1) - 0.1] = 0.1 + 0.09 = 0.19.
Episode 3: D → E → F → G.
Step 1: S=D, R=0, S'=E. V(D) = 0 + 0.1[0 + 1(0.01) - 0] = 0.001. Step 2: S=E, R=0, S'=F. V(E) = 0.01 + 0.1[0 + 1(0.19) - 0.01] = 0.01 + 0.018 = 0.028. Step 3: S=F, R=0, S'=G. V(F) = 0.19 + 0.1[1 - 0.19] = 0.19 + 0.081 = 0.271.
The reward slowly propagates backward from G. After many episodes, V(F) → 1, V(E) → 1, V(D) → 1, etc. (since γ=1 and reward is always 1 when reaching G).
The key difference with MC: MC would see the first complete episode (D→E→F→G) and update ALL states along that trajectory. TD updates only the state immediately preceding the terminal state on the first episode, then propagates backward over episodes.
TD is slower to propagate rewards but has lower variance per update.
1.4 Optimal TD Learning Rate
The TD error uses the current estimate V(S′), which is correlated with previous estimates. This means TD updates are not independent, requiring careful choice of α:
- α=1/n(s) gives the sample mean (as in MC) but TD's bootstrapping means this isn't optimal
- Constant α (e.g., 0.01-0.1) works well for non-stationary problems
- Decaying α: αt=1/t ensures convergence
1.5 N-Step TD
Instead of bootstrapping after 1 step or waiting for the full episode, we can bootstrap after n steps:
1-step TD (TD(0)): V(s)←V(s)+α[Rt+1+γV(St+1)−V(St)]
2-step TD: V(s)←V(s)+α[Rt+1+γRt+2+γ2V(St+2)−V(St)]
n-step TD: V(s)←V(s)+α[Gt:t+n−V(St)]
where Gt:t+n=Rt+1+γRt+2+...+γn−1Rt+n+γnV(St+n).
| n | Method | Bias | Variance |
|---|---|---|---|
| 1 | TD(0) | Highest bias | Lowest variance |
| n (intermediate) | n-step TD | Moderate | Moderate |
| ∞ | MC | Zero bias | Highest variance |
1.6 TD(λ): The λ-Return
TD(λ) unifies all n-step returns using a geometric weighting with parameter λ ∈ [0, 1]:
Interpretation:
- λ = 0: Only 1-step TD (TD(0)). Highest bias, lowest variance.
- λ = 1: MC (all returns equally weighted). Zero bias, highest variance.
- λ between 0 and 1: Mixture of all n-step returns.
1.6.1 Forward View (λ-Return Algorithm)
The forward view uses Gtλ as the update target:
This requires waiting for future rewards (forward in time). Computationally expensive, but theoretically clean.
1.6.2 Backward View (Eligibility Traces)
The backward view is implementable online. For each state, we maintain an eligibility trace e(s):
The eligibility trace says: "how recently and how frequently was state s visited?"
The TD update becomes:
where δt=Rt+1+γV(St+1)−V(St).
textInitialize V(s) = 0, e(s) = 0 for all s α ∈ (0, 1], λ ∈ [0, 1] loop for each episode: Initialize S for each step: Take action A, get R, S' δ = R + γ V(S') - V(S) e(S) ← e(S) + 1 # Accumulating trace for all s: V(s) ← V(s) + α δ e(s) e(s) ← γ λ e(s) # Decay trace S ← S' until S is terminal
1.6.3 Worked Example 3: Eligibility Traces in Action
Chain of 3 states: A → B → C (terminal with reward +1). γ = 1, λ = 0.5, α = 0.1.
Initialize V(A) = V(B) = V(C) = 0, e(A) = e(B) = e(C) = 0.
Episode: A → B → C (terminal)
Step 1: S=A, take action right, R=0, S'=B. δ = 0 + 1(0) - 0 = 0. e(A) = 0 + 1 = 1 (visited A). Update: V(A) += 0.1 × 0 × 1 = 0 (no change — TD error is 0). Decay: e(A) = 1 × 1 × 0.5 = 0.5. e(B) = 0.
Step 2: S=B, take action right, R=0, S'=C (terminal). δ = 0 + 1(0) - 0 = 0. (Wait — what is V(C)? If C is terminal with reward 1, then V(C) should be 1!)
Let me reconsider: the terminal state C gives reward +1 upon entering. So V(C) should represent the value of being in state C, which is 0 (you've reached the terminal, no further rewards). The reward +1 is received when transitioning TO C.
So for step 2: R=1 (reward for reaching C), S'=C. δ = 1 + 1(0) - 0 = 1. e(B) = 0 + 1 = 1 (visited B).
Update all states: V(A) += 0.1 × 1 × 0.5 = 0.05 (e(A)=0.5, the decaying trace) V(B) += 0.1 × 1 × 1 = 0.10 (e(B)=1) V(C) += 0.1 × 1 × 0 = 0 (e(C)=0)
Decay: e(A) = 0.5 × 1 × 0.5 = 0.25, e(B) = 1 × 1 × 0.5 = 0.5.
Now V(A) = 0.05, V(B) = 0.10.
With λ=0 (TD(0)): Only B would have been updated. V(A) would remain 0 after this episode. With λ=0.5: Both A and B get updated. A gets a smaller share (0.05 vs B's 0.10) because its trace is older. With λ=1 (MC): Both A and B would be updated equally (since the same TD error δ = 1 applies to both).
The eligibility trace distributes the TD error proportional to recency — more recent states get larger updates. This is how TD(λ) achieves the n-step return weighting without explicitly storing future rewards.
1.7 Edge Cases & Gotchas
- Trace type: Accumulating traces (add 1 each visit) can grow unbounded for frequently visited states. Replacing traces (set to 1 instead of add 1) work better in practice.
- λ = 0: Reduces to TD(0) — only the most recent state gets updated.
- λ = 1: Approximates MC — all states on the trajectory get equal credit for the TD error.
- Online λ-return: The theoretical TD(λ) with λ=1 converges to MC, but the backward-view implementation with λ=1 doesn't exactly match MC for finite episodes.
- Offline vs Online: The λ-return algorithm is an "offline" method (update at episode end). The backward view is "online" (update at each step).
1.8 Why This Matters
TD learning is the algorithmic backbone of modern RL:
| Algorithm | TD Variant |
|---|---|
| SARSA | On-policy TD(0) for Q-values |
| Q-learning | Off-policy TD(0) for Q-values |
| DQN | Q-learning + neural networks + experience replay |
| Actor-Critic | TD error for advantage estimation |
| TRPO/PPO | Generalized advantage estimation (GAE = TD(λ) for advantages) |
Understanding TD(λ) is essential for understanding Generalized Advantage Estimation (GAE), which is the standard way to compute advantages in policy gradient methods. GAE uses λ to trade off bias and variance in advantage estimates, exactly analogous to the λ-return for value estimation.
2. 📐 Key Formulas / Concepts
| Concept | Formula | Description |
|---|---|---|
| TD(0) update | V(s)←V(s)+α[R+γV(s′)−V(s)] | Bootstrapping with sampled reward |
| TD error | δt=Rt+1+γV(St+1)−V(St) | Prediction error driving learning |
| n-step return | Gt:t+n=∑k=0n−1γkRt+k+1+γnV(St+n) | Bootstrap after n steps |
| λ-return | Gtλ=(1−λ)∑n=1∞λn−1Gt:t+n | Weighted mixture of n-step returns |
| Eligibility trace | et(s)=γλet−1(s)+1(St=s) | Recency-weighted visitation record |
| TD(λ) update | V(s)←V(s)+αδtet(s) | Credit assignment via eligibility traces |
3. ⚠️ Common Pitfalls
Pitfall 1: Confusing TD and MC Targets
Mistake: Thinking TD and MC use the same update target.
Why: Both update value estimates, but TD uses R+γV(S′) (one actual reward + bootstrapped estimate) while MC uses Gt (complete return from that point).
Correct approach: MC is an unbiased estimate of the true return. TD is a biased estimate (because V(S′) is itself an estimate). TD has lower variance but is biased toward its initial estimates.
Pitfall 2: Setting λ Too High in TD(λ)
Mistake: Using λ = 0.99 when learning rate is small, expecting faster convergence.
Why: High λ means the eligibility trace decays slowly, keeping many states "eligible" for the current TD error. This leads to high variance updates (more like MC), which may slow or destabilize learning.
Correct approach: Start with λ = 0 (pure TD) for stable learning, then increase λ to 0.7-0.9 for faster propagation. Values of λ near 1 (0.99+) are rarely used in practice; GAE typically uses λ between 0.9 and 0.97.
Pitfall 3: Not Resetting Eligibility Traces Between Episodes
Mistake: Using the same eligibility trace array across episodes without resetting.
Why: Traces from a previous episode can affect the next episode's updates, causing cross-episode interference. States from the previous episode might still have positive eligibility when the new episode starts.
Correct approach: Reset eligibility traces to zero at the start of each episode (or at least set e(s) = 0 for all s).
Pitfall 4: Using Accumulating Traces in Large State Spaces
Mistake: Using accumulating traces in a setup with function approximation.
Why: Accumulating traces can cause instability with function approximation because they can grow without bound for frequently visited states. This leads to very large updates that drive the function approximator into unstable regions.
Correct approach: Use replacing traces (set e(s) = 1 instead of e(s) += 1 when revisiting a state) or Dutch traces. In neural network implementations, GAE typically handles credit assignment without explicit traces.
4. 📝 Practice Questions
Q1: For a 3-state chain (X→Y→Z, terminal Z with R=+1). Compare TD(0) and MC updates after one episode X→Y→Z. Use α=0.1, γ=0.9. Initial V=0.Both methods receive the same rewards: R(X→Y)=0, R(Y→Z)=0, R(Z→terminal)=0?Wait — in this formulation, the reward is received when entering Z. Let me assume: reward = +1 upon arriving at Z. So:R at step 1 (X→Y): 0 R at step 2 (Y→Z): +1MC: V(X) ← 0 + 0.1[(0 + 0.9×1 + 0.9²×0) - 0] = 0.09 V(Y) ← 0 + 0.1[(1 + 0) - 0] = 0.10 V(Z) ← 0 (terminal, no update)TD(0): Step 1: δ = 0 + 0.9(0) - 0 = 0. V(X) ← 0 + 0.1(0) = 0. Step 2: δ = 1 + 0.9(0) - 0 = 1. V(Y) ← 0 + 0.1(1) = 0.10.After one episode: MC updates both X and Y; TD(0) only updates Y. After many episodes: TD(0) will propagate value from Y to X gradually. Q2: In TD(0), the TD error δ = 0 on a non-terminal step. Does this mean V(s) is correct?No! δ = 0 means R+γV(s′)=V(s). This is the Bellman equation for the current value estimates — they satisfy the Bellman consistency condition. But the estimates could still be wrong.Example: In the random walk, after initializing all V=0, the first step from state C gives δ = 0 + 0×0 - 0 = 0. V(C) = 0, which is wrong (true V(C) for γ=1 should be 0.5 if probability of eventually reaching the right goal is 0.5).δ = 0 means there's no local improvement to make given the current estimates. But the estimates might be globally wrong because the reward hasn't propagated yet. Q3: For TD(λ), what happens to the eligibility trace of a state not visited for many steps? How does this relate to credit assignment?The eligibility trace decays exponentially: e(s)=(γλ)k⋅e0(s) after k steps since the last visit.For λ=0.9, γ=0.99: decay factor per step = 0.891. After 10 steps: 0.89110≈0.31 — still 31% of the original trace remains. After 30 steps: 0.89130≈0.03 — only 3% remains.This means recent states get more credit for current rewards. A state visited 30 steps ago receives only 3% of the TD error signal for a reward received now. This implements a recency-weighted credit assignment that's roughly exponential.By contrast, MC gives equal weight to all states on the trajectory. TD(0) gives weight only to the immediately preceding state. Q4: Explain the bias-variance tradeoff in terms of n-step TD returns. How does increasing n affect each?Bias: The n-step return uses V(St+n) which is a biased estimate of the true value of St+n. For small n, the bootstrap term V(St+n) dominates, leading to higher bias. For large n, the return is mostly composed of actual rewards, reducing bias toward zero (as n → ∞, the return is the MC return, which is unbiased).Variance: The n-step return contains the sum of n random rewards plus one bootstrapped estimate. For small n, few random variables contribute, so variance is low. For large n, many random rewards sum up, increasing variance.Tradeoff: Small n = high bias, low variance. Large n = low bias, high variance. The optimal n balances these based on the learning problem:
- Stochastic rewards → prefer smaller n (reduce variance)
- Poor value estimates → prefer larger n (reduce bias from bootstrapping)
- TD(λ) with λ ∈ [0,1] smoothly interpolates between these extremes Q5: Derive the relationship between TD error and Bellman error.
Bellman error for a state s: BE(s)=Vπ(s)−Eπ[R+γVπ(S′)∣S=s]This is the error between the true value Vπ(s) and the Bellman equation's expectation. At convergence (when learning is complete), Bellman error = 0 for all states.TD error (expected): E[δt∣St=s]=E[Rt+1+γV(St+1)∣St=s]−V(s)If V = Vπ, then the expected TD error equals the negative Bellman error (which is 0 at convergence). The TD error is a sample-based estimate of the Bellman error.The TD update reduces the expected TD error by moving V(s) toward R+γV(s′). This makes the value function more Bellman-consistent, reducing the Bellman error over time. Q6: Given a random walk with 10 states, γ=0.9, reward +1 at right terminal, 0 elsewhere. Compare TD(0) and TD(λ=0.8) learning speed. Which propagates rewards faster?TD(0) propagates the reward one state per episode:
- Episode 1: V(state 9) learns the reward (rightmost non-terminal)
- Episode 2: V(state 8) learns ≈ γ × V(9)
- ...
- Episode N: V(state 10-N) learns the reward
So it takes ~10 episodes for the reward to reach the leftmost state.TD(λ=0.8) propagates the reward to multiple states per episode:
- Episode 1: All states visited get some update. If the agent starts at state 10 (rightmost) and goes to terminal, then states 10, 9, 8... all get eligibility traces. The TD error near the terminal is distributed to all preceding states, with recency weighting.
- After episode 1: V(10) ≈ 1, V(9) ≈ 0.9λ=0.72, V(8) ≈ 0.9²λ²=0.518, etc.
TD(λ) propagates rewards much faster than TD(0) but with higher variance. In practice, TD(λ) with λ ≈ 0.8-0.9 offers a good speed-variance tradeoff. Q7: What happens to eligibility traces when γ=0? How does this affect learning?When γ=0, the eligibility trace decays according to e(s)←γλe(s)=0 for all s after each step. This means:
- At each step, only the current state S_t has e(S_t) = 1
- All other states have e(s) = 0
The TD(λ) update becomes identical to TD(0):
- Only the most recently visited state gets updated
- No credit assignment to earlier states
This makes sense: with γ=0, the agent only cares about immediate rewards. There's no need to assign credit to earlier states because future rewards don't matter. TD(λ) and TD(0) are equivalent when γ=0. Q8: In the backward view of TD(λ), explain why we update all states (not just the current state) at each step.The backward view uses eligibility traces to assign credit to past states. The update is:V(s)←V(s)+αδtet(s)At step t, the TD error δ_t reflects a prediction error about the current transition. States that were visited recently (high e_t(s)) contributed to the prediction that led to this error — they should share in the correction.If we only updated the current state, we would only correct the immediate predecessor. The eligibility trace mechanism distributes the correction backward along the trajectory, proportionate to recency.This is computationally efficient: instead of storing n-step returns for each state and updating at the end of the episode, we update every state at every step with a simple mechanism.The cost is O(∣S∣) per step (updating all states). For tabular settings this is fine. For function approximation, we update only the parameters that contribute to the value function gradient (typically proportional to the trace). Q9: Show that the sum of weights in the λ-return is 1.The λ-return is: Gtλ=(1−λ)∑n=1∞λn−1Gt:t+nThe sum of the weights: (1−λ)∑n=1∞λn−1=(1−λ)⋅1−λ1=1This is a geometric series with ratio λ. The factor (1-λ) normalizes the sum to 1 so that G_t^λ is a convex combination of all n-step returns.For λ=0: weight on 1-step return = 1. All other returns get weight 0. For λ=0.5: 1-step: 0.5, 2-step: 0.25, 3-step: 0.125, ... (sum = 0.5 + 0.25 + 0.125 + ... = 1) For λ=1: All returns weighted equally for an infinite horizon — but this limit requires care because the series becomes 0⋅∑n=1∞1⋅Gt:t+n, which is undefined. In practice, λ=1 means the λ-return converges to the MC return as n → ∞. Q10: Compare accumulating traces and replacing traces for a state visited 3 times in a row.Accumulating trace: Each visit adds 1 to the trace before decay.
- After 1st visit: e = 0 + 1 = 1
- Decay: e = γλ × 1
- After 2nd visit: e = γλ + 1
- Decay: e = (γλ + 1) × γλ = γ²λ² + γλ
- After 3rd visit: e = γ²λ² + γλ + 1
After 3 visits: e = 1 + γλ + γ²λ² (geometric sum). For γ=0.9, λ=0.8: e ≈ 1 + 0.72 + 0.518 = 2.238.Replacing trace: Each visit sets the trace to 1 (before decay).
- After 1st visit: e = 1
- Decay: e = γλ × 1
- After 2nd visit: e = γλ + 1? No — replacing: e = 1 (set to 1, then decay applies after update)
- Actually, the standard replacing trace: e(s) = 1 (set to 1, not add 1)
After 3 visits with replacing traces: e = 1 (the most recent visit dominates).Replacing traces prevent the trace from growing unbounded, which is especially important for frequently visited states. Accumulating traces can lead to "runaway" traces where a state visited many times accumulates a very large trace, causing huge updates and instability.
5. 🔗 Cross-References
- Previous: Monte Carlo Methods (Week 4) — MC as the λ=1 special case
- Next: Q-Learning & SARSA (Week 6) — TD control algorithms
- Related: DQN (Week 7) — Q-learning with neural networks
- External: Sutton & Barto, "Reinforcement Learning" — Chapter 6-7 on TD and eligibility traces Join Discord PreviousMonte Carlo MethodsNextQ-Learning & SARSA