Skip to content
AI360Xpert
Beta

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.

One dial runs from the TD target 4.70 through the lambda mixture 7.26 to the Monte Carlo return 13.43 as backup depth grows
One dial runs from the TD target 4.70 through the lambda mixture 7.26 to the Monte Carlo return 13.43 as backup depth grows

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: StS_t is the state at time tt, Rt+1R_{t+1} the reward after leaving it, γ\gamma the discount factor in [0,1][0, 1], V(s)V(s) the table estimate, nn the backup depth, and λ\lambda the mixture weight in [0,1][0, 1]. 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 nn real rewards, then bootstrap from the table:

Gt:t+n=Rt+1+γRt+2+⋯+γn−1Rt+n+γnV(St+n)G_{t:t+n} = R_{t+1} + \gamma R_{t+2} + \dots + \gamma^{n-1} R_{t+n} + \gamma^n V(S_{t+n})

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 GtG_t. The update waits nn steps, then moves the table toward the target with step size α\alpha:

V(St)←V(St)+α [Gt:t+n−V(St)]V(S_t) \leftarrow V(S_t) + \alpha\, [G_{t:t+n} - V(S_t)]

Set n=1n = 1 and you get the TD target Rt+1+γV(St+1)R_{t+1} + \gamma V(S_{t+1}). Stretch nn 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 nn, blend every horizon with geometric weights. With λ\lambda in [0,1][0, 1]:

Gtλ=(1−λ)∑n=1T−t−1λn−1Gt:t+n+λT−t−1GtG_t^\lambda = (1 - \lambda) \sum_{n=1}^{T-t-1} \lambda^{n-1} G_{t:t+n} + \lambda^{T-t-1} G_t

The weights sum to one by construction. At λ=0\lambda = 0 all weight lands on the one-step return. At λ=1\lambda = 1 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 γ=0.9\gamma = 0.9, step size α=0.2\alpha = 0.2:

S0→+2.0S1→+1.0S2→+4.0S3→+10.0terminalS_0 \xrightarrow{+2.0} S_1 \xrightarrow{+1.0} S_2 \xrightarrow{+4.0} S_3 \xrightarrow{+10.0} \text{terminal}

Table values are V(S0)=0.0V(S_0) = 0.0, V(S1)=3.0V(S_1) = 3.0, V(S2)=5.0V(S_2) = 5.0, V(S3)=8.0V(S_3) = 8.0, terminal 0.00.0. Targets for S0S_0:

One step uses one reward plus the table:

G0:1=2.0+0.9×3.0=4.70G_{0:1} = 2.0 + 0.9 \times 3.0 = 4.70

Two steps use two rewards plus the table at S2S_2:

G0:2=2.0+0.9×1.0+0.81×5.0=2.0+0.90+4.05=6.95G_{0:2} = 2.0 + 0.9 \times 1.0 + 0.81 \times 5.0 = 2.0 + 0.90 + 4.05 = 6.95

Three steps reach S3S_3:

G0:3=2.0+0.90+0.81×4.0+0.729×8.0=2.0+0.90+3.24+5.832=11.972G_{0:3} = 2.0 + 0.90 + 0.81 \times 4.0 + 0.729 \times 8.0 = 2.0 + 0.90 + 3.24 + 5.832 = 11.972

Four steps run past termination, so no bootstrap remains:

G0:4=2.0+0.90+3.24+0.729×10.0=13.43G_{0:4} = 2.0 + 0.90 + 3.24 + 0.729 \times 10.0 = 13.43

That last number is the Monte Carlo return G0G_0. Now mix with λ=0.5\lambda = 0.5. Weights are 0.5000.500, 0.2500.250, 0.1250.125 and 0.1250.125, which sum to 1.0001.000:

G00.5=0.500×4.70+0.250×6.95+0.125×11.972+0.125×13.43=7.26275≈7.26G_0^{0.5} = 0.500 \times 4.70 + 0.250 \times 6.95 + 0.125 \times 11.972 + 0.125 \times 13.43 = 7.26275 \approx 7.26

With α=0.2\alpha = 0.2 from V(S0)=0.0V(S_0) = 0.0, TD moves to 0.940.94, two-step to 1.391.39, three-step to 2.392.39, the mixture moves to 1.451.45, and Monte Carlo moves to 2.692.69. TD under-reacts because the table entry 3.03.0 is pessimistic. Monte Carlo grabs the +10.0+10.0 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 n=1n = 1 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 nn and λ\lambda as hyperparameters. Try nn in {2,4,8}\{2, 4, 8\} or λ\lambda around 0.80.8 to 0.90.9 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 λ\lambda 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 λ\lambda 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 Gt:t+nG_{t:t+n} recovers TD at n=1n = 1 and Monte Carlo when nn covers the episode.
  • The lambda mixture blends every horizon with weights that sum to one, with λ=0\lambda = 0 giving TD and λ=1\lambda = 1 giving Monte Carlo.
  • On rewards [2.0,1.0,4.0,10.0][2.0, 1.0, 4.0, 10.0] with γ=0.9\gamma = 0.9, targets run 4.704.70, 6.956.95, 11.9711.97, 13.4313.43, and λ=0.5\lambda = 0.5 lands at 7.267.26.
  • Deeper backups cut bootstrapping bias but add sampling variance, so tune nn and λ\lambda instead of switching families.