Skip to main content
TD(0) builds its target from one step of experience and the estimate at the next state. Monte Carlo waits for the whole return. MC vs TD(0) showed that the two trade bias against variance. n-step TD sits between them: its target uses nn steps of experience and then bootstraps from the estimate at the state reached after nn steps. Backup trees of n-step TD for increasing nn. The leftmost tree is TD(0), and the rightmost, which runs to the end of the episode, is MC.

The n-step return

The n-step return adds nn rewards and the discounted estimate at St+nS_{t+n}: Gt:t+n=Rt+1+γRt+2+⋯+γn−1Rt+n+γnVt+n−1(St+n),G_{t:t+n} = R_{t+1} + \gamma R_{t+2} + \dots + \gamma^{n-1} R_{t+n} + \gamma^{n} V_{t+n-1}(S_{t+n}), where Vt+n−1V_{t+n-1} is the estimate available at time t+nt+n. If the episode ends before t+nt+n, the n-step return is the full return, Gt:t+n=GtG_{t:t+n} = G_t. The update of StS_t moves its estimate toward the n-step return: Vt+n(St)=Vt+n−1(St)+α[Gt:t+n−Vt+n−1(St)].V_{t+n}(S_t) = V_{t+n-1}(S_t) + \alpha \bigl[ G_{t:t+n} - V_{t+n-1}(S_t) \bigr]. The estimates of all other states stay the same. The update for StS_t has to wait until time t+nt+n, when Rt+nR_{t+n} and St+nS_{t+n} are known. With n=1n = 1 this is TD(0), and with nn at least as long as the rest of the episode it is constant-α\alpha MC (Sutton & Barto, 2018).

Choosing n

The n-step return has the error reduction property. If VV has a worst-case error of ϵ\epsilon, the expected n-step return has a worst-case error of at most γnϵ\gamma^n \epsilon: max⁡s∣Eπ[Gt:t+n∣St=s]−vπ(s)∣≤γnmax⁡s∣Vt+n−1(s)−vπ(s)∣.\max_s \bigl| \mathbb{E}_\pi[G_{t:t+n} \mid S_t = s] - v_\pi(s) \bigr| \le \gamma^n \max_s \bigl| V_{t+n-1}(s) - v_\pi(s) \bigr|. A larger nn therefore reduces the bias that comes from the estimate. It also adds more random rewards to the target, which increases its variance. On random-walk tasks, intermediate values of nn learn faster than either end, TD(0) or MC (Sutton & Barto, 2018). The best nn depends on the task and on the step size.

Optional: the λ-return

This section is optional. The rest of the chapter does not use it. Instead of choosing one nn, you can average the n-step returns for all nn. The λ-return weights the n-step return by (1−λ)λn−1(1-\lambda)\lambda^{n-1}, with λ∈[0,1]\lambda \in [0, 1]: Backup diagram of the λ-return: the n-step returns for every nn, each with its weight. Gtλ=(1−λ)∑n=1T−t−1λn−1Gt:t+n+λT−t−1Gt.G_t^{\lambda} = (1-\lambda) \sum_{n=1}^{T-t-1} \lambda^{n-1} G_{t:t+n} + \lambda^{T-t-1} G_t. All n-step returns that reach the end of the episode equal GtG_t, so their weights are collected in the last term. The weights sum to 1: (1−λ)∑n=1T−t−1λn−1=1−λT−t−1(1-\lambda)\sum_{n=1}^{T-t-1}\lambda^{n-1} = 1 - \lambda^{T-t-1}. lambda-weighting-function Weight of each n-step return in the λ-return. The weight falls by a factor of λ\lambda with every extra step, and the full return gets the remaining weight. The offline λ-return algorithm waits until the end of the episode and then updates every visited state toward its λ-return: V(St)←V(St)+α[Gtλ−V(St)].V(S_t) \leftarrow V(S_t) + \alpha \bigl[ G^{\lambda}_t - V(S_t) \bigr]. With λ=0\lambda = 0 the target is the one-step return of TD(0), and with λ=1\lambda = 1 it is the full return of MC. TD(λ\lambda) reaches a close approximation of the same updates online, one step at a time, with eligibility traces. Chapter 12 of Sutton and Barto covers them (Sutton & Barto, 2018). Key references: (Sutton & Barto, 2018)

References

  • Sutton, R., Barto, A. (2018). Reinforcement Learning: An Introduction. Link

Found an error on this page? Report an issue.