n-Step TD
Imagine learning a route through a maze: updating after every step is quick but short-sighted, while waiting until the exit gives a complete answer but delays learning. n-Step TD sits between those choices. It learns from several real rewards in a row, then uses its current value estimate to fill in the rest of the future.
How the update works
For a state visited at time t, n-step TD waits for n transitions. Its target is the discounted sum of the next n rewards, plus a bootstrapped estimate of the state reached after those transitions:
Gₜ:t+n = Rₜ₊₁ + γRₜ₊₂ + ... + γⁿ⁻¹Rₜ₊ₙ + γⁿ V(Sₜ₊ₙ)
V(Sₜ) ← V(Sₜ) + α [Gₜ:t+n − V(Sₜ)]
Here, n controls the trade-off:
- n = 1 gives ordinary TD(0): immediate updates, but heavily reliant on current—and possibly wrong—value estimates.
- A larger n incorporates more actual rewards before bootstrapping, so credit travels farther along a trajectory.
- If n reaches the episode’s end, the method becomes a Monte Carlo update: no bootstrap, but a delayed and noisier full return.
Why this matters in practice
In a sparse-reward task such as a Gymnasium maze, a goal reward can influence states several moves away much sooner than with one-step TD. Yet n-step TD still updates before an episode finishes, unlike Monte Carlo learning. The cost is that longer returns have more randomness: an unlucky sequence of rewards can move an estimate in the wrong direction, while short returns can perpetuate a bad estimate through repeated bootstrapping. Deep-RL algorithms use the same idea: n-step DQN stores short reward sequences in replay data so useful reward information reaches earlier decisions faster. TD(λ) extends this idea by blending many n-step returns rather than choosing one fixed horizon.
n-Step TD is a temporal-difference method that updates a state-value estimate using the next n rewards, then bootstraps from the estimated value of the state reached after n steps. It bridges one-step TD and Monte Carlo learning: larger n incorporates more observed reward before relying on an estimate. This controls the bias–variance trade-off and speeds credit assignment for delayed rewards.
Imagine learning a new hiking route. After each step, you could judge it only by what happens immediately—or wait until you have walked a few steps and see whether the path is leading somewhere good. n-Step TD uses that second idea.
It helps a learning system judge a choice by looking ahead a short, fixed number of steps—“n” steps—at the rewards it receives along the way. It then makes an educated guess about what may happen after that. This gives richer feedback than judging only the next moment, without needing to wait until the entire journey ends. It is useful when good or bad consequences take a little time to appear.