An episode gives rewards r1=1, r2=0, r3=2, r4=3 and then ends. With γ=0.5, compute the returns G0,G1,G2,G3. Which recursion lets you compute them quickly?

Reinforcement learning, Returns and discounting
Level L2 Elementary. Length Short. Nature Mat Mathematical.

What's being asked

Whether you can compute discounted returns and use the recursion Gt=rt+1+γGt+1.

Key idea

The return is Gt=∑k≥0γkrt+k+1. It satisfies Gt=rt+1+γGt+1 with GT=0 at the end of the episode, so work backwards from the last reward.

Steps

  1. Write the recursion Gt=rt+1+γGt+1, and set G4=0 because the episode has ended.
  2. Work backwards for G3 and G2: G3=r4+γG4=3+0=3, and G2=r3+γG3=2+0.5×3=3.5.
  3. Continue backwards for G1 and G0: G1=r2+γG2=0+0.5×3.5=1.75, and G0=r1+γG1=1+0.5×1.75=1.875.
  4. Check G0 directly: 1+0.5×0+0.25×2+0.125×3=1+0.5+0.375=1.875. It matches.

Common mistakes

How long your answer should be

5–6 lines of arithmetic.

Read this

Previous in Reinforcement learning: Write the Q-learning update. With α=0.1, γ=0.9, Q(s,a)=2, reward r=1 and max⁡a′Q(s′,a′)=5, compute the new Q(s,a). Why is Q-learning called off-policy?
Next in Reinforcement learning: An agent receives reward +2 at every step forever, with γ=0.9. What is its return? How many steps does it take to collect at least 90% of that return, and what does this say about the "effective horizon" 1/(1−γ)?