Search

Search papers and lessons

Discounted Return

Level 3 · 10 min read

The discounted return is the total reward an agent collects from now on, with each later reward shrunk by a factor gamma per step so that near rewards count more than distant ones.

On this page

  • Colour = topic mix
  • Probability
  • Discrete math
  • Calculus
  • Linear algebra
  • Reinforcement learning
  • Stochastic processes
  • ReadReady to readNot yet

TL;DR

An agent acting in a Markov Decision Process receives a reward after each step, and the question is how much those future rewards are worth now. The discounted return is the sum of all future rewards, where each reward is multiplied by a discount factor γ\gamma raised to the number of steps until it arrives. With γ\gamma below 11, a reward soon is worth more than the same reward later, and the infinite sum stays finite.

Builds on: Markov Decision Process, Geometric Series · Leads to: Value Function

Where it's used

Game-playing agents. An agent that learns to play Atari games from the screen, such as the deep Q-network of 2015, is trained to maximise a return built from the in-game score, discounted by a factor close to 11, such as 0.990.99. Board-game agents often use a single final reward, a win or a loss, and discount it lightly or not at all, because the outcome is what matters.

Warehouse and charging robots. A robot that must drive to a charger pays a small cost at every step and gets a large reward on arrival. The discounted return tells the planner whether a long route to the charger is worth its accumulated cost, and a discount factor sets how much an early cost matters compared with a distant reward.

Choosing a discount in practice. Engineers use the discount to set the planning horizon. A factor of 0.990.99 makes rewards about 100100 steps away still count for roughly a third of their value, while a factor of 0.50.5 makes the agent look only a few steps ahead. The choice changes which behaviour the agent learns, so it is set on purpose, not left at a default.

How it works

Take an episode in which an agent receives rewards r1=1r_1 = 1, r2=0r_2 = 0 and r3=2r_3 = 2, after which the episode ends. Use discount γ=0.5\gamma = 0.5, and compute the return from the start, time 00.

  1. List the rewards in the order they arrive. The reward after the first step is 11, after the second is 00, and after the third is 22. Check: three rewards, one per step.
  2. Assign each reward a weight. The first reward is one step away, so its weight is γ0=1\gamma^0 = 1. The second is one step later, weight γ1=0.5\gamma^1 = 0.5. The third is two steps later, weight γ2=0.25\gamma^2 = 0.25.
024681000.20.40.60.81steps into the futureweight on the reward
  • gamma = 0.9
  • gamma = 0.5
The weight on a reward falls geometrically with how many steps away it is. The point marks 3 steps at gamma = 0.9, where the weight is 0.729.
  1. Multiply and add. The return is 1×1+0.5×0+0.25×2=1.51 \times 1 + 0.5 \times 0 + 0.25 \times 2 = 1.5. Check: the two nonzero contributions are 11 and 0.50.5, which add to 1.51.5.
  2. Check with the recursion. The return from time 22 is just its one reward, G2=2G_2 = 2. The return from time 11 is the next reward plus the discounted return after it, G1=0+0.5×2=1G_1 = 0 + 0.5 \times 2 = 1. Then G0=1+0.5×G1=1+0.5=1.5G_0 = 1 + 0.5 \times G_1 = 1 + 0.5 = 1.5. Check: the recursion gives the same 1.51.5 as the direct sum.
  3. Read the answer. The return of 1.51.5 is smaller than the undiscounted total of 33, because the reward of 22 arrives two steps away and counts only a quarter as much.
flowchart LR
  A[Rewards r1, r2, r3 in order] --> B[Weights 1, gamma, gamma squared]
  B --> C[Multiply each reward by its weight]
  C --> D[Sum to get G0]
  D --> E[Check: G0 = r1 + gamma times G1]

The math

Definition

Definition: Discounted return

Let Rt+1,Rt+2,…R_{t+1}, R_{t+2}, \dots be the rewards received after time tt, and let γ∈[0,1)\gamma \in [0, 1) be the discount factor. The discounted return from time tt is

Gt=∑k=0∞γk Rt+k+1.G_t = \sum_{k=0}^{\infty} \gamma^{k}\, R_{t+k+1}.

The definition holds for a process that never ends. For an episode that stops at a fixed time TT, the sum runs only up to k=T−t−1k = T - t - 1, and γ=1\gamma = 1 is allowed because the sum is finite.

Step 1 in symbols: the rewards

The reward Rt+1R_{t+1} is the one received after the action taken at time tt. The index t+k+1t + k + 1 says that the reward kk steps after that is Rt+k+1R_{t+k+1}. Rewards are random because the environment is random, so GtG_t is a random variable.

Step 2 in symbols: the weights

The weight on the reward kk steps away is γk\gamma^k. Weights decline geometrically, which is why the sum has a closed form. The plot above shows the two weights in the walkthrough, as curves of kk.

Step 3 in symbols: the recursion

Split off the first term of the sum and shift the index in the rest:

Gt=Rt+1+∑k=1∞γkRt+k+1=Rt+1+γ∑j=0∞γjRt+j+2=Rt+1+γ Gt+1.G_t = R_{t+1} + \sum_{k=1}^{\infty} \gamma^{k} R_{t+k+1} = R_{t+1} + \gamma \sum_{j=0}^{\infty} \gamma^{j} R_{t+j+2} = R_{t+1} + \gamma\, G_{t+1}.

This is the identity used in step 4 of the walkthrough. It says that the return now is the next reward plus γ\gamma times the return one step later, so an algorithm can compute returns backwards from the end of an episode.

Step 4 in symbols: a constant reward

If every reward equals rr, the geometric series gives ∑k=0∞γk=11−γ\sum_{k=0}^{\infty} \gamma^k = \dfrac{1}{1-\gamma} (see Geometric Series), so

Gt=r1−γ.G_t = \frac{r}{1 - \gamma}.

For a finite horizon of nn rewards, the same argument gives r 1−γn1−γr\,\dfrac{1 - \gamma^{n}}{1 - \gamma}.

Worked examples

Example
Example 1: three equal rewards (tiny)

Three rewards of 11 each, with γ=0.5\gamma = 0.5.

  1. The weights are 11, 0.50.5 and 0.250.25.
  2. The return is 1+0.5+0.25=1.751 + 0.5 + 0.25 = 1.75.
  3. Check with the finite closed form: 1−0.531−0.5=0.8750.5=1.75\dfrac{1 - 0.5^{3}}{1 - 0.5} = \dfrac{0.875}{0.5} = 1.75.
  4. Interpretation: three rewards of 11 are worth 1.751.75 today, because the later two are shrunk.
Example
Example 2: a reward three steps away (standard)

Rewards of 00, 00 and 1010 at steps 1, 2 and 3, then nothing. The discount is γ=0.9\gamma = 0.9.

  1. The weight on the reward at step 3 is γ2=0.81\gamma^{2} = 0.81. Its contribution is 0.81×10=8.10.81 \times 10 = 8.1.
  2. The zero rewards contribute nothing, whatever their weights.
  3. The return is G0=8.1G_0 = 8.1. Check: the undiscounted total is 1010, and 8.1<108.1 < 10, as expected.
  4. Compare: with γ=0\gamma = 0 the return would be 00, because the agent cares only about the immediate reward. With γ=1\gamma = 1 it would be 1010.
Example
Example 3: a charging run (realistic)

A robot pays a cost of 11 at each of the first four steps while driving to a charger, then receives a reward of 1010 on the fifth step, when it plugs in. The discount is γ=0.95\gamma = 0.95. The rewards are −1-1, −1-1, −1-1, −1-1, +10+10.

  1. Weights: 11, 0.950.95, 0.90250.9025, 0.8573750.857375 for the four costs, and 0.954=0.814506250.95^{4} = 0.81450625 for the reward.
  2. Discounted costs: −1−0.95−0.9025−0.857375=−3.709875-1 - 0.95 - 0.9025 - 0.857375 = -3.709875.
  3. Discounted reward: 0.81450625×10=8.14506250.81450625 \times 10 = 8.1450625.
  4. Return: G0=8.1450625−3.709875=4.4351875G_0 = 8.1450625 - 3.709875 = 4.4351875, about 4.43524.4352.
  5. Interpretation: the trip is worth doing, because the reward outweighs the discounted costs.
  6. Try it: suppose γ\gamma is 0.50.5 instead, with the same rewards. What is G0G_0? Work the weights the same way, with 0.54=0.06250.5^{4} = 0.0625 for the reward. Answer: the costs sum to −(1+0.5+0.25+0.125)=−1.875-(1 + 0.5 + 0.25 + 0.125) = -1.875, the reward gives 0.6250.625, so G0=0.625−1.875=−1.25G_0 = 0.625 - 1.875 = -1.25. With heavy discounting the robot's future charging is not worth its early costs.

Common mistakes and tradeoffs

It is tempting to think that the return is the reward at the next step. In fact it is the whole future stream of rewards, each one weighted by its distance. An agent that optimises only the next reward ignores the long-run cost of a bad move.

It is tempting to think that discounting is only for money. In fact γ\gamma is a modelling choice about the agent's horizon. It also makes an infinite sum finite when rewards are bounded, which is why the definition uses γ<1\gamma < 1.

It is tempting to think that two runs starting in the same state have the same return. In fact the return is random, because the environment and the agent's own choices are random. The Value Function is the expected return, and that is the quantity that the agent learns.

Use a discounted return when the task has no natural end, or when near rewards really are worth more than distant ones. A discount near 11 values long-term consequences but makes learning slower and the estimates noisier. A small discount makes the agent short-sighted. For episodic tasks with a natural end, an undiscounted sum (γ=1\gamma = 1) is often the honest choice, and for tasks measured by long-run rate, an average-reward objective is used instead.

History

The idea of a discounted sum of future values is old. Economists used it to value future income and utility long before computers existed. In the 1950s Richard Bellman showed that the recursion above, now called the Bellman equation, lets a sequential decision problem be solved by working backwards through time, and he described this approach in his 1957 book on dynamic programming. Reinforcement learning joined the two ideas in the 1980s, and Sutton and Barto's 1998 textbook made the discounted return the standard objective for learning agents. Deep reinforcement learning from pixels, such as the 2015 Atari agent, kept the same definition and combined it with neural networks.

Recap

  • An agent collects a stream of rewards, and the discounted return GtG_t adds them with weights γk\gamma^k.
  • The return satisfies Gt=Rt+1+γGt+1G_t = R_{t+1} + \gamma G_{t+1}, so it can be computed backwards.
  • A constant reward rr has return r/(1−γ)r/(1 - \gamma), from the geometric series.
  • The discount sets how far ahead the agent looks, and it changes the behaviour the agent learns.
  • Read next: Value Function, which is the expected return from each state, and Discount Rate, the economic idea this factor borrows its name from.

Check yourself

QuestionRecall: what is the weight on a reward that arrives four steps after the current time, in terms of the discount factor γ\gamma?Show answer

It is γ3\gamma^{3}. The reward Rt+4R_{t+4} has index k+1=4k + 1 = 4, so k=3k = 3, and it is weighted by γk\gamma^{k}. The first reward after the current action, Rt+1R_{t+1}, has weight γ0=1\gamma^{0} = 1.

QuestionComputation: rewards of 22 on every step for three steps, then nothing, with γ=0.5\gamma = 0.5. What is G0G_0?Show answer

The weights are 11, 0.50.5 and 0.250.25, so G0=2+1+0.5=3.5G_0 = 2 + 1 + 0.5 = 3.5. Check: the closed form for three equal rewards is 2×(1−0.53)/(1−0.5)=2×1.75=3.52 \times (1 - 0.5^{3}) / (1 - 0.5) = 2 \times 1.75 = 3.5.

QuestionWhy: why must γ\gamma be less than 11 when the process never ends?Show answer

With γ=1\gamma = 1 and a constant positive reward, the sum of the rewards grows without bound, so GtG_t is infinite and cannot be compared or learned from. With γ<1\gamma < 1 and bounded rewards, the weights decay fast enough for the sum to converge.

QuestionApplied: an agent has γ=0.99\gamma = 0.99 and a reward of 11 every step forever. What is its return, and why does that number matter?Show answer

The return is 1/(1−0.99)=1001 / (1 - 0.99) = 100. It matters because it shows that a discount of 0.990.99 gives the agent an effective horizon of about 100 steps, so the agent behaves as if it looks about that far ahead.

Sources