Distributional RL
Learning the whole distribution of returns, not just its average.
Two policies can have the same expected return while one pays a steady salary and the other buys lottery tickets. Distributional RL learns the whole probability distribution of the return, through a Bellman equation for distributions. This lesson derives that equation and the equations its mean and variance obey, works one categorical backup by hand on a lottery, builds the two standard representations, C51's atoms and QR-DQN's quantiles, and uses the learned distributions to measure risk.
What you’ll learn
- State the distributional Bellman equation as an equality in distribution, and derive the Bellman equations obeyed by the mean and the variance of the return.
- Compute a categorical projection by hand, and explain C51's cross-entropy loss and why the projection preserves the mean inside its support.
- Derive why the minimizer of the quantile loss is a quantile, and find QR-DQN's fixed points on a two-outcome return.
- Compute CVaR from a learned distribution, and explain how coarse representations bias it.
Returns are random, and they obey a Bellman equation
Even for a fixed policy the return is a random variable: rewards are random, transitions are random, and the policy may randomize. Write for the return from under ; its probability distribution is the return distribution, and its mean is . A running example: from a lottery pays with probability 0.1 and 0 otherwise, then state pays , then the episode ends. With the return from is with probability 0.9 and with probability 0.1. Its mean, 1.9, is a return that never happens.
The return satisfies a Bellman equation of its own, the distributional Bellman equation:
Condition on what happens in the first step. Given , the return is plus times an independent draw of , so
The tower property gives the ordinary Bellman equation for the mean:
The law of total variance (variance = mean of the conditional variance + variance of the conditional mean) gives a Bellman equation for the variance, with "reward" and discount (Sobel, 1982):
Use the variance equation on the lottery at : the return from is always 1 (variance 0, mean 1). What is the standard deviation of the return from ?
Show the answer
3
The second term vanishes, and has the variance of : , so the standard deviation is 3. Directly: and .
Why learn the whole distribution? First, risk: anyone who cares about more than the average, an investor or a robot near a cliff, needs the spread and the tails (step 4, and Risk-Sensitive RL). Second, a richer training signal: predicting many properties of the return gives a deep network more to learn its features from. Third, it worked: on 57 Atari games, the first deep distributional agent, C51 (Bellemare, Dabney & Munos, 2017), raised DQN's median human-normalized score from 79% to 178%, although it still chose actions by the mean. Why it helps a mean-maximizing agent is still debated (Distributional Bellman Operators). Neuroscience has taken note too: there is evidence that dopamine neurons encode a distribution of reward predictions rather than a single one (TD Learning in the Brain).
Categorical returns: C51’s atoms and projection
C51 represents each as a categorical distribution on fixed atoms , evenly spaced on with gap . The network outputs logits per action, a softmax turns them into probabilities , and the value is . On Atari, with rewards clipped to , C51 used atoms on , hence its name. For a sampled transition with , each atom of moves to ; these points fall between atoms, so the categorical projection splits each one's probability between its two nearest atoms, in proportion to closeness:
Here . From the return is exactly 1, which lies between the atoms 0.96 and 1.20, so the learned is the projection of the point mass at 1, with weights and :
Back up with the draw . Scaling by moves the two atoms; shifting by 0 leaves them:
Project: 0.864 lies between 0.72 and 0.96 (weights 0.4 and 0.6), and 1.08 halfway between 0.96 and 1.20:
Its mean is , exactly this branch's return: inside the support, every split is a linear interpolation, so the projection preserves the mean. It does not preserve the shape: a point mass at 0.9 has become three atoms.
At the fixed point, mixes this branch (probability 0.9) with the jackpot branch (probability 0.1), whose atoms land near 10.9. How much total probability does the learned put on the atom at 0.72?
Show the answer
0.3
; the jackpot branch adds nothing that low. The true return is never below 0.9, yet the learned distribution puts 30% of its mass at 0.72. This smearing is harmless for the mean and costly for the tails, as step 4 shows.
C51 trains by cross-entropy between the projected target and its prediction, , with the target computed by a target network as in DQN. With softmax logits , the gradient is simply : prediction minus target. Actions are still chosen -greedily by the mean.
Quantile returns: QR-DQN
QR-DQN (Dabney, Rowland, Bellemare & Munos, 2018) flips the parameterization: atoms, each with probability , whose locations are learned. There is no support to choose in advance and no projection step: the targets for are just the points . Where should go? To the quantile of the return at level , the midpoint of the -th slice of probability (the Fixed Point lessons prove this is the best equally weighted -atom approximation in the Wasserstein-1 distance). A loss whose minimizer is a quantile does the job.
The quantile regression loss (Koenker & Bassett, 1978) charges a residual asymmetrically: if the target is above the estimate, if below.
For a target with a continuous CDF , differentiate the expected loss in : raising costs for every target above it and saves for every target below it.
The expected loss is convex in and its derivative vanishes where : the minimizer is the -quantile. The single-sample gradient gives the update, an unbiased estimate of the expected gradient, which the Wasserstein distance itself does not offer.
QR-DQN minimizes with the quantile Huber loss , where is the Huber loss with threshold : quadratic near zero, which smooths the kink at zero that the authors suspected could limit performance with networks. On 57 Atari games it reached a median human-normalized score of 211%, against C51's 178%. On the lottery the fixed points are easy to find: a quantile at a level below 0.9 settles at 0.9, one above 0.9 at 10.9. With , the levels and exceed 0.9, so 19 quantiles sit at 0.9 and 2 at 10.9, and the representation's mean is , not 1.9: unlike the categorical projection, the quantile representation does not preserve the mean.
Use only quantiles on the lottery, at levels . What mean does the learned representation report at its fixed point?
Show the answer
0.9
All three levels are below 0.9, so all three quantiles settle at 0.9 and the mean reads 0.9. The jackpot, which contributes 1.0 of the true mean 1.9, is invisible: a 10% event is resolved only when some level exceeds 0.9.
Using the distribution: risk
A learned distribution supports decisions that the mean cannot. The most common risk measure in RL is the conditional value at risk, the mean of the worst fraction of outcomes:
which for a continuous distribution is ; is the mean. For the lottery, every gives 0.9: the worst 90% of outcomes are all 0.9. From a categorical distribution, add up the lowest atoms' probabilities until they reach , taking a fraction of the last one; from quantiles, average the lowest of them.
Think first What is of the categorical fixed point computed in step 2, where the atom at 0.72 carries probability 0.3? And with 11 atoms on ?
With 51 atoms the lowest atom, 0.72, already carries 0.3 > 0.1 of the mass, so , below the true 0.9: the projection's smearing biases the tail low. With 11 atoms () the point mass at 0.9 is split between the atoms at 0 and 1.2, and 22.5% of the mass ends up on the atom at 0, so the learned is 0. With 101 atoms it is 0.84. The mean stays exactly 1.9 in all three cases (for 11 atoms or more).
An agent can use such numbers to act: choose actions by of instead of its mean, to avoid catastrophes. Doing this greedily at every step is, however, not the same as maximizing the CVaR of the whole return, because CVaR is not time-consistent; Risk-Sensitive RL works out what each approach really optimizes.
Key takeaways
- The return is a random variable whose law obeys : shrink by , shift by the reward, mix over transitions. Its mean and its variance obey Bellman equations with discounts and .
- C51 learns probabilities on fixed atoms; the categorical projection splits each shifted atom between its neighbors, which preserves the mean inside the support but smears point masses, and training minimizes cross-entropy to the projected target.
- QR-DQN learns the locations of equally likely atoms at the quantile midpoints by quantile regression, whose minimizer is the -quantile; it needs no support or projection, but its mean is not exactly the true mean (1.852 against 1.9 on the lottery with 21 quantiles).
- CVaR averages the worst of outcomes; coarse representations bias it badly (0.72 instead of 0.9 with 51 atoms, 0 with 11) while barely moving the mean, and acting on it step by step is not the same as optimizing the CVaR of the return.
Check yourself
In the interactive lesson these are scored with your confidence, and what you miss comes back for review.
Which statistic of the return obeys a Bellman equation whose discount is ?
- The mean
- The variance
- The median
- The probability that the return is positive
Show the answer
B. The variance
By the law of total variance, : scaling a random variable by scales its variance by . The mean obeys the ordinary equation with discount .
The categorical projection is applied to a distribution lying entirely inside . What happens to the mean?
- It is unchanged, because each point is split between its two neighboring atoms by linear interpolation
- It moves to the nearest atom
- It drops by half an atom gap
- It can change by up to in either direction
Show the answer
A. It is unchanged, because each point is split between its two neighboring atoms by linear interpolation
A point between and goes to with weight and to with weight , and the weighted average of the two atoms is again. By linearity the mean of any distribution inside the support is preserved. Mass outside the support is clipped to the end atoms, which does change the mean.
For a target with continuous CDF , which minimizes with ?
- The mean of
- The median of , whatever is
- The mode of
- The -quantile,
Show the answer
D. The -quantile,
The derivative of the expected loss is , which vanishes at , and the expected loss is convex. Each QR-DQN atom uses its own level , so together they learn quantiles.
The lottery returns 0.9 with probability 0.9 and 10.9 with probability 0.1. What is ?
- 0.9
- About 1.43
- 1.9
- 10.9
Show the answer
B. About 1.43
The worst 95% consist of all the 0.9 outcomes (probability 0.9) and 0.05 of the 10.9 outcomes: .
Go deeper
- Categorical & Quantile Methods: C51, QR-DQN & IQN · Representing return distributions, and projecting the Bellman update onto them.
- Distributional Bellman Operators · Wasserstein contraction for evaluation, its failure for control, and Cramér projections.
- Risk-Sensitive RL · CVaR, exponential utility and acting under risk preferences.
Further reading
- M. G. Bellemare, W. Dabney & R. Munos, "A distributional perspective on reinforcement learning", ICML (2017).
- W. Dabney, M. Rowland, M. G. Bellemare & R. Munos, "Distributional reinforcement learning with quantile regression", AAAI (2018).
- M. G. Bellemare, W. Dabney & M. Rowland, Distributional Reinforcement Learning (MIT Press, 2023).
- M. J. Sobel, "The variance of discounted Markov decision processes", Journal of Applied Probability 19(4), 794–802 (1982).