n-Step Bootstrapping: Off-Policy Methods
Taking the n-step family off-policy raises the same importance-sampling questions Monte Carlo did, now over a window of exactly n actions. We reweight n-step returns by the policy ratio, watch the ratio product inflate variance on real numbers, then build the tree-backup algorithm that learns off-policy with no ratios at all — and finally n-step Q(sigma), one algorithm whose per-step switch recovers Sarsa, tree backup, and Expected Sarsa as special cases.
╌╌╌╌
This builds on n-Step Bootstrapping, which developed the -step return, -step TD prediction, and -step Sarsa for control — all on-policy. Here the target and behavior policies come apart, and the question is how to reuse one policy's data to learn about another over a multi-step window.
Off-policy learning with importance sampling
Off-policy learning estimates values for a target policy while generating data from a different behavior policy — typically is greedy and is more exploratory, say -greedy. To reuse 's data as if it came from , we reweight it by the relative probability of the actions actually taken under the two policies. Since an -step return is built from exactly actions, only those probabilities matter.1 The importance-sampling ratio over steps through is
A simple off-policy -step TD update just scales the whole -step error by the ratio spanning the actions of the return:
The logic is direct. If some action in the window would never be taken under (its -probability is ), the whole -step return gets weight and is ignored — it is not data would ever have produced. If an action is far likelier under than under , its return is up-weighted, because that action is characteristic of yet rare in the data. When (the on-policy case) every ratio is and the update collapses back to plain -step TD, so this generalizes rather than replaces the earlier rule.
For the action-value version, the ratio starts and ends one step later. Because -step Sarsa updates a state–action pair, the first action is the one being learned about — it is a given, not something to correct for — so importance sampling applies only to the actions that follow:
for . We do not care how likely we were to select ; having selected it, we want to learn fully from whatever followed, correcting only the subsequent actions.
The importance-sampling ratios are what make off-policy training statistically sound, but they are also its weakness. A product of ratios can swing widely, inflating the variance of the update and forcing a small step size — which is why off-policy learning is generally slower than on-policy. This variance is the motivation for the final method, which achieves off-policy learning with no importance-sampling ratios at all.
The ratio product on real numbers
The variance problem is easiest to see by multiplying an actual product out. Let the target be greedy and the behavior be -greedy with over four actions, so on any step where takes 's greedy action, assigns probability and assigns , giving a per-step ratio of
For a -step state-value update whose window happens to follow greedy actions throughout, the ratio is — a mild up-weighting, since greedy actions are only slightly rarer under than under . But suppose at just one of those four steps the behavior took a non-greedy action, which gives probability . Then that factor is , the whole product collapses to , and the entire -step return is thrown away. The update fires only when every one of the actions in the window was greedy; the longer the window, the rarer that is. With and four actions, the chance all steps are greedy is , so more than a quarter of -step windows are discarded outright — and at , nearly half. Longer lookahead spends more of its data on windows that end up weighted , and concentrates its learning on the few that remain, which is precisely the variance that forces a smaller .
For the action-value version the ratio runs from , not : having already chosen , we keep its return whatever it was, and correct only the following actions. So over three following greedy steps is — the first action contributes no factor, which is one reason -step Sarsa tolerates off-policy data slightly better than the state-value update does.
The tree-backup algorithm
Is off-policy learning possible without importance sampling? For the one-step case yes — Expected Sarsa and Q-learning already do it, by taking an expectation over next actions instead of sampling one. The -step tree-backup algorithm is the multi-step generalization.
The name comes from its backup diagram. Down the central spine hang the sampled states, rewards, and actions actually experienced. But off each state, to the sides, dangle the actions that were not selected. We have no sampled data for those, so we bootstrap from their current estimated action values and fold them into the target. The update is thus from the entire tree of estimated action values — the sampled spine plus every unselected action hanging off it — not just from the states along the spine.
The target is built from action values only, so no ratios appear. The one-step tree-backup return equals the Expected Sarsa target,
and the general return is defined recursively: at each level the sampled action passes its -weight down to the return of the subtree below it, while every unselected action contributes its own bootstrapped value,
for . Read the two terms: the sum handles the unselected actions , each weighted by and evaluated at its current estimate; the last term recurses into the next level, carrying the weight of the action that was taken. Unfolding the recursion, each leaf deep in the tree is weighted by the product of the target-policy probabilities of the sampled actions on the path down to it. The update rule is the usual -step Sarsa one, .
Tree backup and -step Sarsa sit at two poles of a broader design space — sample every action (Sarsa, with importance-sampling corrections off-policy) or take an expectation over every action (tree backup, no corrections). The next section builds the algorithm that spans the whole space between them.
The unifying algorithm: n-step Q(σ)
Three action-value methods now sit side by side, and they differ only in how each transition down the spine is treated. -step Sarsa samples every action: each step follows the one action actually taken. The tree-backup algorithm samples none: at every step it branches over all actions and takes an expectation. -step Expected Sarsa samples every step except the last, where it branches. Reading them this way, the choice is made anew at each step — sample this transition, or take the expectation over it — and the three algorithms are just three fixed patterns of that choice.2
Let a per-step switch record it: means sample the action at step (as in Sarsa), means take the expectation over actions (as in tree backup). Nothing forbids mixing them within a single backup, or even letting vary continuously as a function of the state or action. The algorithm that carries this switch is -step Q(), and it contains all three predecessors as the constant or almost-constant settings of .
The backup diagram shows the unification. Where Sarsa's spine is all sampled transitions and tree backup's is all branched ones, Q() mixes them: each state-to-action transition is either sampled or fully branched according to at that level.
The Q(σ) return
The formula below has one moving part: a per-step coefficient that interpolates between the sampled action's correction and the expectation over all actions. Everything else is the ordinary -step return. The single return that yields all four cases comes from writing the tree-backup return with a control variate and then sliding between two forms. Recall the tree-backup return branches at every step, weighting the sampled action by ; the importance-sampling Sarsa return instead reweights the same sampled action by the ratio . Q() blends the two weights linearly. Writing the horizon as and the expected approximate value as ,
for . The recursion terminates with when , and with when . The middle factor distinguishes the cases: at it is the importance-sampling ratio , so the bracket becomes the sampled-action correction of -step Sarsa; at it is the target probability , so the bracket becomes the tree-backup weight. In both cases the trailing supplies the expectation over all actions, and the bracket only corrects it toward the sampled action to the degree set by .
Reading the special cases off this one line:
- (Sarsa). Every factor is ; the expected value and the term combine into the ordinary sampled bootstrap, reweighted for off-policy by the importance ratios.
- (tree backup). Every factor is , and the return is the recursive tree-backup return of the previous section — no ratios anywhere.
- only at the last step (Expected Sarsa). The final transition branches into ; the earlier steps sample. On-policy this is -step Expected Sarsa.
The algorithm
Because Q() uses the general off-policy -step Sarsa update, it needs the behavior policy , the importance ratios , and the per-step stored alongside the states, actions, and rewards. As with every method in this chapter, the update for time fires only at wall-clock time , and all storage can be indexed modulo . The return is built by the recursion above, unrolled from the horizon back to .
- 1input: a behavior policy with for all
- 2initialize arbitrarily for all
- 3initialize to be -greedy wrt , or a fixed given policy
- 4input: step size ; a positive integer
- 5for each episode do
- 6initialize and store terminal
- 7choose and store
- 8
- 9for do
- 10if then
- 11take action ; observe and store and
- 12if is terminal then
- 13
- 14else:
- 15choose and store
- 16select and store
- 17
- 18time whose estimate is updated now
- 19if then
- 20if then
- 21
- 22else:
- 23
- 24for down to do
- 25if then
- 26
- 27else:
- 28
- 29
- 30
- 31if is being learned then
- 32ensure is greedy wrt
- 33until
Q() unifies the chapter: -step Sarsa, -step tree backup, and -step Expected Sarsa all fall out of one return by the setting of a single switch. The practical hope is that an intermediate — mostly sampling, but branching where the target and behavior policies diverge — could keep tree backup's low variance where it matters while retaining Sarsa's cheap, sample-based updates elsewhere.
n-step returns in deep reinforcement learning
The integer became a standard hyperparameter in deep reinforcement learning, where its bias–variance tradeoff is tuned as routinely as a learning rate. Every system below uses a multi-step return in place of a one-step target for exactly the reason the random walk gave: an intermediate propagates reward faster than one-step bootstrapping without inheriting Monte Carlo's variance.
Multi-step returns in value-based and actor–critic deep RL. The asynchronous
actor–critic A3C (Mnih et al., 2016, ICML) computes an -step return (up to a
rollout length, typically or ) as the target for both its value and
policy updates, so a reward reaches the states that led to it within a single rollout
rather than trickling back one bootstrap at a time. Rainbow (Hessel et al., 2018,
AAAI), the study that combined the strongest DQN improvements, found multi-step
returns (an -step target inside Q-learning, usually ) to be one of the
components contributing most to its gains — a direct transplant of -step Sarsa's
target into a deep off-policy learner. R2D2 (Kapturowski et al., 2019, ICLR)
runs an -step () recurrent Q-learner over stored sequences and set records
on the Atari benchmark. In each case the is the same : how many real rewards
to accumulate before bootstrapping from the value estimate.
Interpolating over all , and safe off-policy corrections. The tree-backup and importance-sampling machinery of this chapter also has deep-RL descendants. Generalized advantage estimation (Schulman et al., 2016, ICLR) does not commit to a single at all: it forms an exponentially-weighted average of every -step return with a parameter , so recovers the one-step estimate and the Monte Carlo one — the eligibility-trace idea the next lesson builds, applied to the advantage used by policy-gradient methods like PPO. On the off-policy side, the variance of the -step ratio product described above is controlled in practice exactly as tree backup suggested — by replacing raw ratios with bounded corrections. Retrace() (Munos et al., 2016, NeurIPS) clips each per-step ratio at , yielding a multi-step off-policy return that is low-variance and provably convergent, and the V-trace target of IMPALA (Espeholt et al., 2018, ICML) truncates the ratios to correct for the lag between distributed actors and the learner. Sutton and Barto's own tree-backup construction is the tabular ancestor of these: an off-policy multi-step return whose correction is an expectation over actions, so its variance stays controlled where a product of ratios would explode.3
What n unified
The whole chapter turns on one integer. Set and every method here is its one-step ancestor — TD(0), Sarsa(0), Expected Sarsa, Q-learning. Let grow and the same equations reach further into the future, trading the bias of a raw bootstrap for the variance of longer reward sequences, until at they become Monte Carlo. The random walk showed that an intermediate usually performs best, and the tree-backup construction showed that even the off-policy machinery fits the same -step frame.
One question remains for the next lesson: all of these methods commit to a fixed chosen in advance. The eligibility-trace view shows how to average over all at once, smoothly and with bounded memory — but this lesson already laid the conceptual groundwork: a return that looks steps ahead and then bootstraps, with one-step TD and Monte Carlo as its two extremes.
Footnotes
- Sutton & Barto, §7.3 — n-step Off-policy Learning: the importance-sampling ratio (7.10) and the reweighted updates (7.9), (7.11); and §7.5 — the n-step Tree Backup Algorithm: the recursive tree-backup return (7.15)–(7.16), off-policy without importance sampling. ↩
- Sutton & Barto, §7.6 — A Unifying Algorithm: -step Q(). A per-step degree of sampling blends the tree-backup weight and the importance ratio in the return (7.17), unifying -step Sarsa (), -step tree backup (), and -step Expected Sarsa ( on the last step only); the complete off-policy algorithm uses the general -step Sarsa update (7.11). The algorithm is new to the second edition (related work by De Asis, Hernandez-Garcia, Holland, and Sutton, 2017). ↩
- Multi-step returns in deep reinforcement learning, past Sutton and Barto's tabular treatment. A3C: V. Mnih et al.,
Asynchronous methods for deep reinforcement learning,
ICML (2016) — -step returns as targets for an actor–critic. Rainbow: M. Hessel et al.,Rainbow: Combining improvements in deep reinforcement learning,
AAAI (2018) — multi-step (-step) returns among the components driving its gains. R2D2: S. Kapturowski et al.,Recurrent experience replay in distributed reinforcement learning,
ICLR (2019) — -step recurrent Q-learning. GAE: J. Schulman et al.,High-dimensional continuous control using generalized advantage estimation,
ICLR (2016) — a -weighted average over all -step returns for the advantage. Retrace: R. Munos, T. Stepleton, A. Harutyunyan, M. Bellemare,Safe and efficient off-policy reinforcement learning,
NeurIPS (2016) — per-step ratios clipped at for a convergent multi-step off-policy return. V-trace/IMPALA: L. Espeholt et al.,IMPALA: Scalable distributed deep-RL with importance weighted actor-learner architectures,
ICML (2018) — truncated importance ratios for lagged distributed data. ↩
╌╌ END ╌╌