Advanced Tabular Methods
TD and Monte Carlo are two ends of one dial, not two rival families. Turning the backup depth from 1 step toward the full episode trades bootstrapping bias for sampling variance.
Why Does This Exist?
Textbooks introduce dynamic programming, Monte Carlo methods and temporal-difference learning as three separate tribes. That split is handy for teaching. It misleads when you have to pick an update.
The extremes both hurt. One-step TD bootstraps after a single transition, so it learns online with low variance. But it leans hard on its own guesses, and a bad initial table poisons early updates while distant rewards crawl backward one state per episode. Monte Carlo waits for the full return, so it uses real outcomes with zero bootstrapping bias. But it stacks the noise of every step into one target, needs far more episodes, and cannot update at all inside a continuing task.
This page covers the bridge: n-step returns and the lambda mixture that turn that either-or choice into a dial. You will see the two axes the field uses (depth and width), the one formula that recovers both extremes, and a four-step chain worked by hand. The deep treatments of each endpoint live on their own pages. Start with tabular solution methods if the table setup itself is new.
Think of It Like This
Checking a road trip at gas stations
You drive 400 kilometers to a wedding and want to know if you are on schedule.
One-step TD checks the dashboard at the first gas station, 50 kilometers in, and re-estimates the whole arrival time from that one reading plus the old plan for the rest. Fast feedback. If the old plan was wrong, the new estimate inherits the error.
Monte Carlo refuses to update until you park at the venue, then scores the entire trip at once. Honest. You drove four hours before learning anything.
N-step methods stop at every second or third gas station and re-estimate from the road actually covered plus the old plan for what remains. The lambda mixture blends all those checkpoints with weights that sum to one. Depth is how many stations you cover before each re-estimate. Width is whether you drove one road or averaged over every possible road on a map.
Where it stops: a road trip ends at a fixed place, so waiting works. Many RL tasks never end, and only the bootstrapping side of the dial can learn inside them.
How It Actually Works
Symbols for this page: is the state at time , the reward after leaving it, the discount factor in , the table estimate, the backup depth, and the mixture weight in . Depth counts how many real rewards enter the target before bootstrapping. Width counts whether the backup follows one sampled transition or averages over a full model.
Sample backups follow the single transition the environment dealt you. Full-width backups average over every outcome a model says is possible. Dynamic programming sits at depth 1 with full width. One-step TD sits at depth 1 with width 1. Monte Carlo sits at full depth with width 1. Everything else fills the space between.
The n-step return
Accumulate real rewards, then bootstrap from the table:
When the horizon runs past termination there is nothing left to bootstrap from, so the tail term drops and the return becomes the plain Monte Carlo return . The update waits steps, then moves the table toward the target with step size :
Set and you get the TD target . Stretch past the episode end and you get Monte Carlo. Depth is a slider, not a school of thought.
The lambda mixture
Instead of picking one , blend every horizon with geometric weights. With in :
The weights sum to one by construction. At all weight lands on the one-step return. At all weight lands on Monte Carlo. In between you get a compound target that trusts real rewards for a few steps and cuts off the noisy tail with a bootstrap. Eligibility traces compute this same blend online, one step at a time, and n-step TD prediction treats the fixed-depth case in full.
Worked example with four rewards
A short chain ends after four rewards. Discount , step size :
Table values are , , , , terminal . Targets for :
One step uses one reward plus the table:
Two steps use two rewards plus the table at :
Three steps reach :
Four steps run past termination, so no bootstrap remains:
That last number is the Monte Carlo return . Now mix with . Weights are , , and , which sum to :
With from , TD moves to , two-step to , three-step to , the mixture moves to , and Monte Carlo moves to . TD under-reacts because the table entry is pessimistic. Monte Carlo grabs the directly but would swing wildly if that last reward were noisy. The mixture sits between them, which is the whole point of the dial.
Code
A short check of the four targets and the lambda blend, with type hints throughout:
from typing import List
def n_step_return(rewards: List[float], values: List[float], gamma: float, start: int, n: int) -> float: horizon = len(rewards) end = min(start + n, horizon) total = 0.0 for k in range(start, end): total += (gamma ** (k - start)) * rewards[k] if start + n < horizon: total += (gamma ** n) * values[start + n] return total
rewards = [2.0, 1.0, 4.0, 10.0]values = [0.0, 3.0, 5.0, 8.0, 0.0]gamma = 0.9alpha = 0.2
targets = [n_step_return(rewards, values, gamma, 0, n) for n in [1, 2, 3, 4]]print([round(t, 2) for t in targets])# -> [4.7, 6.95, 11.97, 13.43]
weights = [0.5, 0.25, 0.125, 0.125]mixed = sum(w * t for w, t in zip(weights, targets))print(round(mixed, 2))# -> 7.26
print([round(alpha * t, 2) for t in [targets[0], mixed, targets[3]]])# -> [0.94, 1.45, 2.69]# -> expected output:[4.7, 6.95, 11.97, 13.43]7.26[0.94, 1.45, 2.69]Watch Out For
Leaving the dial at an extreme by default
Newcomers run TD with everywhere or Monte Carlo everywhere, then blame the algorithm family when training stalls. The symptom is slow credit flow on one side (a 100-step maze takes hundreds of episodes to move the start value) or wild swings on the other (values jump with every lucky rollout).
Treat and as hyperparameters. Try in or around to before rewriting anything. The intermediate settings exist for exactly this reason.
Reading the lambda target as low variance for free
The mixture still bootstraps, so early in training it inherits table error just like TD does. If your initial values are far off, a high trusts real rewards sooner but also imports more sampling noise. The symptom is fast early movement followed by chatter that never settles.
Start near the TD end while the table is crude, then raise as estimates mature. Watch the TD error magnitude: shrinking error means the bootstrap is becoming trustworthy.
The Quick Version
- Tabular methods live on two axes: backup depth (how many rewards before bootstrapping) and backup width (one sampled transition or a full model average).
- The n-step return recovers TD at and Monte Carlo when covers the episode.
- The lambda mixture blends every horizon with weights that sum to one, with giving TD and giving Monte Carlo.
- On rewards with , targets run , , , , and lands at .
- Deeper backups cut bootstrapping bias but add sampling variance, so tune and instead of switching families.