Skip to content

Returns and Episodes

A return combines the rewards after a particular time into one score. An episode is a sequence of interactions that ends, such as one game or one trip to Goal.

Task typeWhat happensExamples
EpisodicThe task reaches a terminal state.A maze attempt, a game, balancing a pole until it falls
ContinuingThe task has no natural ending.Thermostat control, ongoing server scheduling

For an episode ending at time TT, STS_T is terminal and RTR_T is the last reward. The undiscounted return is:

Gt=Rt+1+Rt+2+⋯+RT.G_t = R_{t+1} + R_{t+2} + \cdots + R_T.

If rewards continue forever, simply adding them may not produce a finite number. Discounting provides one useful objective for continuing tasks and can also be used in episodic tasks.

With discount factor γ\gamma:

Gt=∑k=0∞γkRt+k+1=Rt+1+γRt+2+γ2Rt+3+⋯ .G_t = \sum_{k=0}^{\infty} \gamma^k R_{t+k+1} = R_{t+1} + \gamma R_{t+2} + \gamma^2 R_{t+3} + \cdots.
  • γ=0\gamma=0: only the next reward counts.
  • 0<γ<10<\gamma<1: later rewards count, but receive progressively less weight.
  • γ=1\gamma=1: all rewards count equally, provided the return is well-defined, such as an episode with bounded rewards and a bounded number of steps.

For an infinite discounted sum, bounded rewards and 0≤γ<10\leq\gamma<1 ensure a finite return. The next section explains how the infinite-sum notation also handles episodes.

The timing is easy to misread: Rt+1R_{t+1} has weight 1, Rt+2R_{t+2} has weight γ\gamma, and Rt+3R_{t+3} has weight γ2\gamma^2. With γ=0.5\gamma=0.5, the third upcoming reward receives weight 0.52=0.250.5^2=0.25.

For Start → Hall → Goal, the rewards are −1 and +5. At γ=0.9\gamma=0.9:

G0=−1+0.9(5)=3.5.G_0 = -1 + 0.9(5) = 3.5.

The first reward is −1, but the return is 3.5. A longer route, Start → B → C → D → Goal, has return:

G0=−1−0.9−0.92+0.93(5)=0.935.G_0 = -1 - 0.9 - 0.9^2 + 0.9^3(5) = 0.935.

Both routes reach the same goal. The longer one pays more movement costs and receives the positive reward later.

Separate the next reward from the remaining return:

Gt=Rt+1+γGt+1.G_t = R_{t+1} + \gamma G_{t+1}.

Suppose γ=0.5\gamma=0.5, the rewards are R1=−1R_1=-1, R2=2R_2=2, R3=6R_3=6, R4=3R_4=3, and R5=2R_5=2, and the episode ends at T=5T=5. Start with terminal return G5=0G_5=0 and work backward:

Time ttCalculationReturn GtG_t
5No rewards remain.00
42+0.5(0)2 + 0.5(0)22
33+0.5(2)3 + 0.5(2)44
26+0.5(4)6 + 0.5(4)88
12+0.5(8)2 + 0.5(8)66
0−1+0.5(6)-1 + 0.5(6)22

This recursion avoids repeatedly summing the same future rewards. It also provides the idea behind the Bellman equations in section 3.5.

Suppose R1=2R_1=2, every reward after that equals 7, and γ=0.9\gamma=0.9. The geometric-series identity ∑k=0∞xk=1/(1−x)\sum_{k=0}^{\infty}x^k=1/(1-x) applies for ∣x∣<1|x|<1:

G0=2+0.9(7)+0.92(7)+⋯=2+7(0.9)1−0.9=65.G_0 = 2 + 0.9(7) + 0.9^2(7) + \cdots = 2 + \frac{7(0.9)}{1-0.9} = 65.

One step later, the return includes only the sequence of sevens:

G1=7+0.9(7)+⋯=71−0.9=70.G_1 = 7 + 0.9(7) + \cdots = \frac{7}{1-0.9} = 70.

The recursion checks the result: G0=2+0.9(70)=65G_0=2+0.9(70)=65.

For the two-step gridworld route, change γ\gamma to 0.5. Its return becomes −1+0.5(5)=1.5-1+0.5(5)=1.5. Then set γ=0\gamma=0: the future goal reward disappears from the objective, leaving return −1.

Sutton, R. S. & Barto, A. G. Reinforcement Learning: An Introduction, 2nd ed., chapter 3, section 3.3. The explanations and small worked examples here are written for these notes.


Previous: 3.2 Goals and Rewards · Next: 3.4 Unified Notation for Episodic and Continuing Tasks