Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.A reward now or a bigger one later?
Would you take one sweet now or ten sweets next week? It depends on how patient you are. Reinforcement learning has a patience dial called the discount factor. With a low setting the agent grabs whatever is close; with a high setting it is willing to walk further for a bigger prize. The value of a place is how much reward the agent can expect to collect from there, counting future rewards with this patience.
Economists use the same idea: money next year is worth a little less than money today, so future payments are discounted.
- 1. A high discount factor makes the agent…
- 2. The value of a state is…
- 3. Discounting makes far-away rewards count…
Level 1: Beginner
★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.By hand
- Discounted return: G_t = r_(t+1) + γ r_(t+2) + γ² r_(t+3) + … with discount factor 0 ≤ γ ≤ 1.
- Recursion: G_t = r_(t+1) + γ G_(t+1), which lets you compute returns backwards from the end of an episode.
- State value: V^π(s) = E_π[G_t | s_t = s]. Action value: Q^π(s, a) = E_π[G_t | s_t = s, a_t = a].
- Link: Q^π(s, a) = R(s, a) + γ Σ_s’ P(s’|s, a) V^π(s’) and V^π(s) = Σ_a π(a|s) Q^π(s, a).
- Effective horizon: 1/(1 − γ), roughly how many steps ahead the agent looks.
- Exact values: for a fixed policy, V = r_π + γ P_π V, a linear system.
- Monte Carlo estimate: average the returns of many episodes started in s.
- 1. G_t can be computed as…
- 2. The effective horizon of γ = 0.9 is about…
- 3. Q^π(s, a) is the expected return after…
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.Computing returns and values
Exercise 1.
- Discounted returns of short reward lists, computed backwards.
- A corridor of 11 states with +1 at the left end and +10 at the right end, starting in state 2.
- The exact values of ‘always right’ and ‘always left’ from the linear system (I − γP_π)V = r_π.
Practice.
- Pick γ from the task: the effective horizon 1/(1 − γ) should cover the time from action to its consequence.
- γ = 0.99 is a common default for long tasks, with episodes truncated at a time limit.
- For small MDPs, solve for V exactly; for large ones, estimate it from samples.
- Report Monte Carlo estimates with standard errors, since returns are noisy.
- Do not discount across a truncation as if the episode had ended: bootstrap from the value of the last state instead.
- Tools: NumPy linear algebra for tabular values, Gymnasium time-limit wrappers.
def discounted_return(rewards, gamma):
G = 0.0
for r in reversed(rewards):
G = r + gamma * G
return G- 1. A common default discount for long tasks is…
- 2. For small MDPs, V^π can be found by…
- 3. At a time-limit truncation you should…
Level 3: Advanced
★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.Theory
Values solve a linear system. Taking expectations of G_t = r_(t+1) + γ G_(t+1) under π gives V^π = r_π + γ P_π V^π. For γ < 1, or for episodic chains that end with probability 1, I − γP_π is invertible and V^π = (I − γP_π)^(−1) r_π.
Near versus far. With no randomness, a reward r_1 reached after d_1 steps is worth γ^(d_1 − 1) r_1, and r_2 after d_2 steps is worth γ^(d_2 − 1) r_2. The far reward wins when γ^(d_2 − d_1) > r_1 / r_2. For +1 after 2 steps and +10 after 8 steps the threshold is 10^(−1/6) ≈ 0.681. Randomness in the moves makes the far reward less certain and raises the threshold.
Why discount at all? It keeps infinite sums finite (a reward r forever is worth r/(1 − γ)), expresses uncertainty about the future, and makes the Bellman operator of the next topic a contraction. The price is that the agent may undervalue distant goals.
- 1. V^π = (I − γP_π)^(−1) r_π requires…
- 2. Randomness in the moves makes the far reward…
- 3. A reward r received forever is worth…
Level 4: Expert
★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.At what discount factor does an agent prefer a large distant reward to a small nearby one, how does randomness move that point, and how accurate are Monte Carlo value estimates at different discounts?
History.
- Discounting comes from economics (P. Samuelson, 1937) and was built into dynamic programming by R. Bellman (1957).
- R. A. Howard (1960) and D. Blackwell (1962, 1965) developed the theory of discounted MDPs.
- R. S. Sutton and A. G. Barto (2018) give the modern treatment of returns and value functions; S. Kakade (2003) linked 1/(1 − γ) to the sample complexity of learning.
Exercise 2.
- The 11-state corridor: +1 on reaching state 0, +10 on reaching state 10, start in state 2.
- The smallest γ on a grid of step 0.001 for which ‘always right’ has higher exact value than ‘always left’, without slip and with slip 0.2.
- The uniformly random policy’s value from state 2: exact, and Monte Carlo from 400 episodes.
Seed 0:
| setting | γ at which the far +10 wins |
|---|---|
| no slip | 0.682 (theory 10^(−1/6) = 0.6813) |
| slip 0.2 | 0.758 |
| γ | effective horizon | exact value | Monte Carlo (400 episodes) |
|---|---|---|---|
| 0.5 | 2 | 0.144 | 0.132 ± 0.010 |
| 0.9 | 10 | 0.660 | 0.605 ± 0.027 |
| 0.99 | 100 | 2.217 | 2.048 ± 0.128 |
| 1 | ∞ | 2.800 | 3.025 ± 0.188 |
- The grid search found the theoretical threshold; a slip of 0.2 raised it to 0.758, because slipping makes the long walk slower and less certain.
- Higher γ made the value larger and its Monte Carlo error bar larger, from 0.010 to 0.188 with the same 400 episodes; relative to the value, the error stayed between 4% and 7%. All estimates were within 2 standard errors of the exact values.
- At γ = 1 the value is the expected undiscounted payoff: 0.8 × 1 + 0.2 × 10 = 2.8, since a random walk from 2 reaches 10 before 0 with probability 0.2.
- Seeds 1 and 2 (the thresholds do not depend on the seed): Monte Carlo at γ = 0.99 gave 2.408 ± 0.141 and 2.238 ± 0.136, at γ = 1 2.733 ± 0.178 and 2.688 ± 0.176.
Discounting in practice
- Average reward: for tasks that never end, maximising the long-run reward per step is an alternative to discounting.
- Large γ and variance: policy-gradient methods use γ around 0.99 and reduce variance with value baselines, a later topic.
- Hyperbolic discounting: humans and animals discount the near future more steeply than the far future; some agents learn several γ at once.
- Next: values satisfy the Bellman equations, which turn this linear system into algorithms.
References
- R. Bellman (1957). Dynamic Programming. Princeton University Press.
- D. Blackwell (1962). “Discrete dynamic programming.” Annals of Mathematical Statistics.
- R. S. Sutton and A. G. Barto (2018). Reinforcement Learning: An Introduction, 2nd edition. MIT Press.
- S. M. Kakade (2003). “On the sample complexity of reinforcement learning.” PhD thesis, University College London.
- W. Fedus, C. Gelada, Y. Bengio, M. G. Bellemare and H. Larochelle (2019). “Hyperbolic discounting and learning over multiple horizons.” arXiv:1902.06865.