Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.More than an average
Two jobs both pay on average the same. One pays the same every month; the other pays nothing most months and a large bonus now and then. Knowing only the average, you cannot tell them apart. Distributional reinforcement learning learns the full spread of possible outcomes for each choice, so an agent can see the risk and, if asked, prefer the steady option.
Distributional agents set new records on Atari in 2017, and the same idea is used to make risk-aware decisions in finance and robotics.
- 1. Two options with the same average can differ in…
- 2. Distributional RL learns…
- 3. A risk-averse agent prefers…
Level 1: Beginner
★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.By hand
- Return distribution: Z^π(s, a) is the random return; Q^π(s, a) = E[Z^π(s, a)].
- Distributional Bellman equation: Z(s, a) has the same distribution as R + γZ(S’, A’), with S’ and A’ drawn from the dynamics and the policy.
- Categorical (C51) representation: probabilities on fixed atoms z_1 < … < z_N. The target r + γz_j lies off the grid, so it is projected onto the two neighbouring atoms, preserving its mean.
- Quantile representation (QR-DQN): N locations θ_i estimating the τ_i-quantiles, τ_i = (2i − 1)/(2N). Each moves by α(τ_i − share of target samples below θ_i), the gradient of the quantile (pinball) loss.
- Wasserstein-1 distance: the area between two CDFs, used to measure how close two distributions are.
- Risk measures: with the distribution one can act on its mean, on a quantile, or on the CVaR (the mean of the worst α share).
- 1. The categorical method projects targets because…
- 2. Quantile TD estimates…
- 3. CVaR at 30% is…
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.Learning a return distribution
Exercise 1.
- A two-step chain: from the start, reward 0 and then a final reward of 20 with probability 0.3, else 0; γ = 0.9. The start’s return is 18 with probability 0.3, else 0 (mean 5.4).
- Categorical TD with 31 atoms on [−5, 25] (step 0.01) and quantile TD with 10 quantiles (step 0.2), 5,000 episodes.
- The learned means, the Wasserstein distance to the true distribution and the learned quantiles.
Practice.
- Choose the support to cover all plausible returns for categorical methods; returns outside are clipped and the mean is biased.
- Quantile methods need no support, but quantile levels that fall exactly on a jump of the CDF are not unique and wander.
- Use the distribution for decisions only when risk matters; for maximising the mean, the learned distribution mostly helps as a richer training signal.
- Scale the step sizes: quantile updates move by α·τ regardless of the error size, so returns of large scale need larger α or normalised rewards.
- Tools: Dopamine (C51, QR-DQN, IQN), CleanRL’s C51, the distributional heads in Rainbow.
def categorical_td(P, s, r, s2, terminal, support, gamma, alpha):
if terminal: target = project(np.array([r]), np.array([1.0]), support)
else: target = project(r + gamma * support, P[s2], support)
P[s] += alpha * (target - P[s])
def quantile_td(Q, s, r, s2, terminal, taus, gamma, alpha):
tgt = np.array([r]) if terminal else r + gamma * Q[s2]
Q[s] += alpha * (taus - (tgt[None, :] < Q[s][:, None]).mean(1))- 1. Returns outside a categorical support are…
- 2. A quantile level exactly on a CDF jump…
- 3. Quantile updates move by α·τ regardless of…
Level 3: Advanced
★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.Theory
Contraction. The distributional Bellman operator for a fixed policy is a γ-contraction in the maximal Wasserstein metric (Bellemare, Dabney and Munos 2017), so repeated application converges to Z^π. For control, the optimality operator is not a contraction in any metric, though the means still converge.
Categorical projection preserves the mean. Splitting mass p at z between atoms z_l ≤ z ≤ z_h with weights (z_h − z)/Δ and (z − z_l)/Δ keeps the expectation: p[(z_h − z)z_l + (z − z_l)z_h]/Δ = pz. Since the categorical update is a linear mixture, its mean follows expected TD exactly as long as no mass is clipped.
Quantile regression. The τ-quantile minimises E[ρ_τ(X − θ)], with ρ_τ(u) = u(τ − 1[u < 0]). Its subgradient in θ is P(X < θ) − τ, so stochastic descent moves θ by α(τ − 1[x < θ]). A quantile projection is the Wasserstein-1 best approximation by N equally weighted points, and the quantile Bellman update is a contraction in the ∞-Wasserstein metric (Dabney et al. 2018).
- 1. For a fixed policy, the distributional Bellman operator is a contraction in…
- 2. The categorical projection preserves…
- 3. The τ-quantile minimises…
Level 4: Expert
★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.How do the support, the number of atoms and the quantile levels affect the distributions, means and risk measures learned by categorical and quantile TD, and can they distinguish a safe from a risky action of equal mean?
History.
- Distributions of returns were studied for risk-sensitive MDPs since the 1970s and 1980s (Sobel 1982).
- M. G. Bellemare, W. Dabney and R. Munos (2017) introduced the categorical algorithm C51 and its theory.
- W. Dabney, M. Rowland, M. G. Bellemare and R. Munos (2018) introduced quantile-regression DQN; Dabney and colleagues (2018) extended it to implicit quantile networks.
- W. Dabney and colleagues (2020) reported evidence for distributional reward coding in dopamine neurons.
Exercise 2.
- From a start state, ‘safe’ leads to a state paying 6; ‘risky’ to a state paying 20 with probability 0.3, else 0. γ = 0.9, so both are worth 5.4. A behaviour policy picks each half the time; 5,000 episodes.
- Expected TD (step 0.01); categorical TD (step 0.01) with 11, 31 or 101 atoms on [−5, 25] and with 31 atoms on a too narrow [−5, 10]; quantile TD (step 0.2) with 5, 10 or 50 quantiles. Expected TD starts at 10, the mean of the categorical methods’ uniform start.
- Measured: the means; the Wasserstein-1 distance of the risky action’s learned distribution to the truth (18 with probability 0.3, else 0); the CVaR at 30% of both actions.
Seed 0:
| method | mean safe | mean risky | W1, risky | CVaR safe | CVaR risky |
|---|---|---|---|---|---|
| expected TD | 5.400 | 5.585 | — | — | — |
| categorical, 11 atoms | 5.400 | 5.585 | 1.587 | 3.556 | −1.299 |
| categorical, 31 atoms | 5.400 | 5.585 | 0.185 | 5.000 | 0.000 |
| categorical, 101 atoms | 5.400 | 5.585 | 0.325 | 5.200 | −0.130 |
| categorical, 31 atoms on [−5, 10] | 5.400 | 2.792 | 2.792 | 5.167 | 0.000 |
| quantile, 5 | 5.420 | 4.252 | 1.872 | 5.300 | −0.033 |
| quantile, 10 | 5.400 | 5.520 | 0.150 | 5.290 | 0.003 |
| quantile, 50 | 5.377 | 4.805 | 0.924 | 5.237 | −0.018 |
- Categorical TD’s means equalled expected TD’s to 1e-14 with any number of atoms, as long as the support covered the returns: the projection preserves the mean and the update is linear.
- A too narrow support halved the risky mean (2.792 instead of about 5.4), because returns of 18 were clipped to 10.
- Every distributional method saw the risk: the CVaR at 30% was 3.6 to 5.3 for the safe action and about 0 or below for the risky one, so a CVaR-maximising agent would pick ‘safe’. Expected TD rated ‘risky’ slightly higher (5.585 against 5.400) because of sampling noise.
- More atoms or quantiles were not automatically better. With 11 atoms (spacing 3) the projections smeared the certain return 5.4 into a spread (CVaR 3.556). 31 atoms (spacing 1) contained 0, 18 and 20 exactly and fitted best among the categorical methods. With 5 quantiles the level 0.7 sat exactly on the CDF’s jump and wandered, biasing the mean to 4.252. With 50 quantiles, levels close to the jump moved slowly, giving 4.805 after 5,000 episodes.
- Seeds 1 and 2: expected TD and categorical means for ‘risky’ 5.149 and 5.151; W1 of quantile TD with 10 quantiles 0.072 and 0.128, of categorical with 31 atoms 0.251 and 0.249; the narrow support gave 2.575 and 2.576.
Distributional RL in practice
- Deep versions: C51 (51 atoms), QR-DQN (quantiles), IQN (a network that takes τ as input) and FQF; all add a distributional head to DQN.
- Why it helps even for the mean: learning the full distribution gives a richer training signal for the shared network; the size of this effect depends on the task.
- Risk-sensitive control: acting on CVaR or a lower quantile makes agents avoid rare catastrophic outcomes, relevant for safe RL (topic L5-6).
- Neuroscience: dopamine neurons appear to encode a range of optimistic and pessimistic reward predictions, as quantile TD does.
References
- M. G. Bellemare, W. Dabney and R. Munos (2017). “A distributional perspective on reinforcement learning.” ICML.
- W. Dabney, M. Rowland, M. G. Bellemare and R. Munos (2018). “Distributional reinforcement learning with quantile regression.” AAAI.
- W. Dabney, G. Ostrovski, D. Silver and R. Munos (2018). “Implicit quantile networks for distributional reinforcement learning.” ICML.
- M. G. Bellemare, W. Dabney and M. Rowland (2023). Distributional Reinforcement Learning. MIT Press.
- W. Dabney et al. (2020). “A distributional code for value in dopamine-based reinforcement learning.” Nature.