Chapter 7: n-step Bootstrapping

第七章:n步自举法

📑 目录 / Table of Contents

引言 / Introduction

This chapter unifies MC methods and one-step TD methods. n-step TD methods generalize both so one can smoothly shift between them. n-step methods span a spectrum with MC at one end and one-step TD at the other. The best methods are often intermediate between the two extremes.
本章统一MC方法和单步TD方法。n步TD方法泛化了两者,使人们可以平滑地在它们之间切换。n步方法构成了一个谱系,一端是MC,另一端是单步TD。最好的方法通常在两个极端之间取中间值。
1步TD
TD(0)
2步TD
3步TD
···
n步TD
···
∞步TD
= MC
n-step methods free you from the tyranny of the time step. With one-step TD, the same time step determines how often actions change and the bootstrapping interval. n-step methods enable bootstrapping over multiple steps.
n步方法将您从时间步的束缚中解放出来。在单步TD中,同一时间步既决定了动作改变的频率,也决定了自举的间隔。n步方法允许跨多步进行自举。

7.1 n步TD预测 / n-step TD Prediction

MC uses the complete return Gt. One-step TD uses Gt:t+1 = Rt+1 + γV(St+1). The n-step return interpolates between them:
MC使用完整回报Gt。单步TD使用Gt:t+1 = Rt+1 + γV(St+1)。n步回报在两者之间插值:
Gt:t+n = Rt+1 + γRt+2 + ··· + γn-1Rt+n + γnVt+n-1(St+n)
The n-step TD update is:
n步TD更新为:
Vt+n(St) = Vt+n-1(St) + α [ Gt:t+n − Vt+n-1(St) ]
💡 误差缩减性质:n步回报的期望保证比Vt+n-1更好地估计vπ(在最差状态意义上):max|E[Gt:t+n|St=s] − vπ(s)| ≤ γn max|Vt+n-1(s) − vπ(s)|
Example 7.1: On a 19-state random walk, n-step TD with intermediate n values (e.g., n=4 or 8) outperforms both one-step TD (n=1) and MC (n→∞), illustrating the benefit of intermediate bootstrapping.
例7.1:在19状态随机游走中,中等n值的n步TD(如n=4或8)优于单步TD(n=1)和MC(n→∞),说明了中间自举的优势。

7.2 n步Sarsa

n-step Sarsa extends Sarsa by switching states for state–action pairs. The n-step return for action values:
n步Sarsa通过将状态替换为状态-动作对来扩展Sarsa。动作价值的n步回报:
Gt:t+n = Rt+1 + γRt+2 + ··· + γn-1Rt+n + γnQt+n-1(St+n, At+n)
Qt+n(St, At) = Qt+n-1(St, At) + α [ Gt:t+n − Qt+n-1(St, At) ]
Figure 7.4 shows that one-step Sarsa only strengthens the last action before a high reward, while n-step Sarsa strengthens the last n actions — dramatically speeding up learning from a single episode.
图7.4显示,单步Sarsa仅强化高奖励前的最后一个动作,而n步Sarsa强化最后n个动作——从单个回合中学习的速度显著提高。
n-step Expected Sarsa replaces the last state–action pair with a branch over all actions weighted by π, using V̄t(s) = Σa π(a|s)Qt(s,a).
n步Expected Sarsa将最后一个状态-动作对替换为由π加权的所有动作分支,使用V̄t(s) = Σa π(a|s)Qt(s,a)。

7.3 n步Off-policy学习 / n-step Off-policy Learning

For off-policy n-step methods, we weight returns by the importance sampling ratio ρt:h for the n actions from At to Ah:
对于off-policy n步方法,我们用从At到Ah的n个动作的重要性采样比率ρt:h来加权回报:
ρt:h = ∏k=tmin(h,T-1) π(Ak|Sk) / b(Ak|Sk)
For n-step TD prediction: V(St) ← V(St) + αρt:t+n-1[Gt:t+n − V(St)]. For n-step Sarsa control: Q(St,At) ← Q(St,At) + αρt+1:t+n[Gt:t+n − Q(St,At)]. Note the ratio starts one step later for action values.
对于n步TD预测:V(St) ← V(St) + αρt:t+n-1[Gt:t+n − V(St)]。对于n步Sarsa控制:Q(St,At) ← Q(St,At) + αρt+1:t+n[Gt:t+n − Q(St,At)]。注意对于动作价值,比率晚一步开始。

7.4 *逐决策方法与控制变量 / Per-decision Methods with Control Variates

A more sophisticated off-policy approach uses per-decision importance sampling with control variates. The n-step return is defined recursively:
更复杂的off-policy方法使用逐决策重要性采样配合控制变量。n步回报递归定义为:
Gt:h = ρt(Rt+1 + γGt+1:h) + (1 − ρt)Vh-1(St)
If ρt=0 (action never selected by π), the target equals the current estimate (no update), rather than zero (which would shrink the estimate). The control variate (1−ρt)Vh-1(St) doesn't change the expected update but reduces variance.
如果ρt=0(π永远不会选择的动作),目标等于当前估计(不更新),而非零(会缩小估计)。控制变量(1−ρt)Vh-1(St)不改变期望更新,但减少了方差。

7.5 无重要性采样的Off-policy:n步树备份 / Tree Backup Algorithm

The tree-backup algorithm enables off-policy learning without importance sampling. The target includes the estimated values of all "dangling" action nodes not selected, weighted by their probability under π.
树备份算法实现了无需重要性采样的off-policy学习。目标包含所有未被选择的"悬空"动作节点的估计值,按其π概率加权。
Gt:t+n = Rt+1 + γ Σa≠At+1 π(a|St+1)Q(St+1,a) + γπ(At+1|St+1)Gt+1:t+n
The tree backup can be viewed as alternating sample half-steps and expected half-steps. It generalizes Q-learning to multi-step with stochastic target policies. However, if π is substantially different from b, bootstrapping may span only a few steps even if n is large (because π(Ak|Sk) can be small).
树备份可以看作交替的采样半步和期望半步。它将Q-learning泛化到具有随机目标策略的多步情况。然而,如果π与b差异很大,即使n很大,自举可能只跨几步(因为π(Ak|Sk)可能很小)。

7.6 *统一算法:n步Q(σ) / n-step Q(σ)

n-step Q(σ) unifies Sarsa, tree-backup, and Expected Sarsa by introducing a parameter σt ∈ [0,1] that controls the degree of sampling vs. expectation on each step:
n步Q(σ)通过引入参数σt ∈ [0,1]来统一Sarsa、树备份和Expected Sarsa,控制每一步的采样与期望程度:
Gt:h = Rt+1 + γ [ σt+1ρt+1 + (1−σt+1)π(At+1|St+1) ] [ Gt+1:h − Q(St+1,At+1) ] + γV̄(St+1)
σ=1 → Sarsa (full sampling), σ=0 → tree backup (pure expectation), Expected Sarsa → σ=1 for all steps except the last (σ=0).
σ=1 → Sarsa(完全采样),σ=0 → 树备份(纯期望),Expected Sarsa → 除最后一步(σ=0)外所有步骤σ=1。

7.7 小结 / Summary

n-step methods with intermediate bootstrapping typically outperform both extremes (1-step TD and MC). They involve a delay of n steps before updating and require more memory/computation. Two off-policy approaches: (1) importance sampling (high variance), (2) tree backup (no IS but limited effective horizon). In Chapter 12, eligibility traces will implement multi-step TD with minimal overhead.
具有中间自举的n步方法通常优于两个极端(1步TD和MC)。它们需要n步延迟才能更新,并需要更多内存/计算。两种off-policy方法:(1) 重要性采样(高方差),(2) 树备份(无IS但有效视野有限)。在第12章,资格迹将以最小开销实现多步TD。

核心概念速查 / Key Concepts

术语 / Term英文 / English含义 / Meaning
n步回报n-step Returnn个真实奖励+折扣的n步后估计值
n步TDn-step TD使用n步回报更新状态价值
n步Sarsan-step Sarsa使用n步回报更新动作价值(on-policy)
误差缩减Error Reduction Propertyn步回报期望误差 ≤ γn × 估计值误差
控制变量Control Variate(1-ρ)V项,减少off-policy方差但不改变期望
树备份Tree Backup无需重要性采样的off-policy n步方法
Q(σ)Q(σ)统一Sarsa/树备份/Expected Sarsa的参数化算法