Categorical & Quantile Methods: C51, QR-DQN & IQN
Representing return distributions, and projecting the Bellman update onto them.
Every distributional agent makes two choices: how to describe a distribution with finitely many numbers, and how to pull the Bellman target back into that description. C51 fixes locations and learns probabilities; QR-DQN fixes probabilities and learns locations; IQN learns the whole quantile function; FQF learns where the quantile levels go; expectile and moment-matching methods learn other statistics altogether. This lesson identifies the distance each projection minimizes, proves the projection lemmas behind C51 and QR-DQN with their consequences for convergence and bias, and maps the family by what it represents and what can go wrong.
What you’ll learn
- Prove that C51's projection is the orthogonal projection in the Cramér distance, and use the Pythagorean identity to bound the distance from the categorical fixed point to the true return distribution.
- Prove that the Wasserstein-1-closest equally weighted -atom distribution sits at the quantile midpoints, and explain why quantile regression can learn it from samples when Wasserstein loss cannot.
- Describe IQN's sampled quantile levels and cosine embedding, and how a distortion risk measure changes its policy.
- Compare FQF, expectile-based and moment-matching methods by what they represent, how they back up targets, and what can go wrong.
C51’s projection is a Cramér projection
The Cramér distance compares two distributions on the real line through their CDFs, . It is an distance, so it has angles and orthogonal projections, and the projection C51 uses turns out to be one of them. Fix atoms with gap and let be C51's categorical projection.
A distribution on the atoms has a CDF that is constant on each cell. Outside all the CDFs involved agree (0 to the left, 1 to the right), so becomes an distance between functions on , and the closest cell-wise constant function to is its average on each cell:
This is C51's projection. For a point mass at , the average of over the cell is , which is exactly the weight C51 gives , and so exactly the projected CDF on that cell. Both maps are linear in , so they agree for every .
An orthogonal projection onto an affine subspace is a non-expansion and satisfies Pythagoras' theorem. The same picture shows the projection error: on each cell is monotone, rising by some with , so its squared deviation from its cell average integrates to at most .
Project a point mass with between two atoms apart. As a fraction of , what is the largest possible error over all positions of ?
Show the answer
0.25
With on the lower atom, the CDFs differ by on and by on , so , largest at : a point mass midway between atoms gives , the bound above.
Why the bound holds. At each apply Pythagoras with and : . Taking the supremum gives , inside the stated bound with room to spare. Two caveats. is in general not a contraction in the Wasserstein distances for , so Cramér is the natural metric here. And C51 itself trains by cross-entropy on network logits, not by mixture updates; the theory covers the tabular algorithm that the course's widget runs.
Quantiles: the Wasserstein-1 projection and quantile regression
For an equally weighted distribution with , the Wasserstein-1 distance to couples the two quantile functions: with , Each appears in one term only, so the best atoms can be found one slice at a time.
Proof. Increasing increases for the with , a set of length about , and decreases it for the rest, of length about . The derivative vanishes at : the best atom for a slice is the median of the quantile function on that slice. A direct consequence bounds the mean error of this representation: for on , half of each slice lies on either side of its midpoint, so each slice contributes at most its range of divided by , and For the lottery with 21 quantiles the bound is ; the actual error is .
QR-DQN's goal is the projection of the target distribution. Why does it minimize the quantile loss instead of the distance itself?
- The quantile loss is cheaper to evaluate
- The two have different minimizers, and the quantile loss's is better
- Gradients of estimated from sampled targets are biased, while the quantile loss's sample gradients are unbiased and lead to the same minimizers
- is undefined for discrete distributions
Show the answer
C. Gradients of estimated from sampled targets are biased, while the quantile loss's sample gradients are unbiased and lead to the same minimizers
Targets arrive as samples, . The C51 paper showed that the Wasserstein loss against a sample is biased, and Bellemare, Danihelka et al. (2017) proved that its sample gradients are biased and can lead to the wrong minimizer. The expected quantile loss has derivative , whose single-sample estimate is unbiased, and its minimizers are the quantiles that Lemma 2 asks for.
Implicit quantiles and distortion risk measures
IQN (Dabney, Ostrovski, Silver & Munos, 2018) stops fixing the levels at all. It learns the quantile function itself, for any , as : the convolutional features are multiplied elementwise by an embedding of the level,
Sampling levels makes risk-sensitive control nearly free. For a distortion , nondecreasing, with the identity meaning risk-neutral (it need not reach 1: the CVaR distortion below does not), the distorted expectation is estimated by averaging over sampled levels, and the policy maximizes it. IQN tried several distortions: Wang's (risk-averse for ), the cumulative probability weighting of prospect theory with , a power family, and CVaR:
In its risk-neutral form (), IQN on 57 Atari games matched QR-DQN's 200-million-frame performance after 100 million frames, and under human starts reached a median human-normalized score of 162%, against Rainbow's 153%, without Rainbow's other components. Risk-sensitive versions, tested on six games and scored by the ordinary return, gave mixed results: risk-averse distortions helped markedly on Asterix and Assault, the strongly averse CVaR(0.1) lost ground on Qbert and Space Invaders, and a risk-seeking distortion did clearly worse on three of the six. Why risk aversion helped is open; the authors suggest it may encode a heuristic to stay alive longer, which in many games correlates with reward.
Note what optimizes: it maximizes a distorted expectation of at every step, and the target uses too. That is not the same as maximizing the distortion risk of the whole return, a distinction Risk-Sensitive RL makes precise.
Learning the levels, and other statistics
FQF (Yang et al., 2019) parameterizes both axes. A fraction proposal network outputs, for each state–action pair, the levels , trained so that the staircase they define is as close as possible to the true distribution in ; an IQN-like quantile value network supplies the values at the midpoints of consecutive levels, trained by quantile regression. Where the return distribution has structure, the levels can crowd there.
Expectiles replace quantiles in a different direction. Expectile regression, an asymmetric squared loss, learns expectiles, statistics that generalize the mean as quantiles generalize the median. Rowland et al. (2019) found a trap: backing expectiles up as if they were samples of the distribution gives the wrong target expectiles, and in their chain example the learned distribution collapsed as the updates propagated. Their remedy, imputation, finds at each backup a distribution whose expectiles match the current estimates, backs up samples from it, and regresses the new expectiles on those (EDRL, and ER-DQN on Atari). The same framework recasts C51 and QR-DQN: a set of learned statistics plus an imputation strategy, which for categorical and quantile statistics is trivial, the distribution being read off directly.
Moment matching drops predefined statistics altogether. MMDQN (Nguyen-Tang, Gupta & Venkatesh, 2021) learns a set of unconstrained "particles" per state–action pair and trains them so that their empirical distribution matches the particles of the Bellman target under the maximum mean discrepancy, a kernel distance between distributions.
| Method | What is learned | How the target is fitted | What is known |
|---|---|---|---|
| C51 | Probabilities on fixed atoms | Categorical projection, then cross-entropy | is a -contraction in ; mean exact inside the support |
| QR-DQN | Locations at fixed midpoint levels | Quantile (Huber) regression | contracts in ; tabular QTD converges to a set of fixed points |
| IQN | The quantile function at sampled levels | Quantile regression at random levels | Supports distortion risk measures directly |
| FQF | Levels and locations | for the levels, quantile regression for the values | Adapts the resolution to the distribution |
| EDRL / ER-DQN | Expectiles | Expectile regression on imputed samples | Naive backups collapse; imputation restores consistency |
| MMDQN | Unconstrained particles | Maximum mean discrepancy to the target's particles | No predefined statistic |
Key takeaways
- C51's projection is the (Cramér) orthogonal projection onto distributions on the atoms: on each cell the projected CDF is the cell average. Hence a non-expansion, Pythagoras, a -contraction of in , and a fixed point within of the truth when returns lie in the support.
- The -best equally weighted atoms are the quantiles at the midpoint levels ; quantile regression learns them with unbiased sample gradients, contracts in , and the representation's mean is off by at most .
- IQN learns the quantile function at sampled levels through a cosine embedding; distortion risk measures, CVaR among them, become a change in how levels are sampled, but acting on them step by step does not optimize the risk of the whole return.
- FQF learns the levels as well, EDRL learns expectiles through imputation (naive expectile backups collapse), and MMDQN learns unconstrained particles; each representation is exact for different statistics, and convergence with networks is open for all of them.
Check yourself
In the interactive lesson these are scored with your confidence, and what you miss comes back for review.
In which distance is C51's categorical projection an orthogonal projection?
- The Cramér distance, the distance between CDFs
- The Wasserstein-1 distance
- The Kullback–Leibler divergence
- The total variation distance
Show the answer
A. The Cramér distance, the distance between CDFs
On each cell between atoms the projected CDF is the average of the original CDF, which is the projection onto cell-wise constant functions. That gives the Pythagorean identity, the non-expansion, and with the -contraction of in , convergence of categorical TD.
Why do QR-DQN's atoms target the levels rather than ?
- To avoid the levels 0 and 1, where quantiles may be infinite
- Because the -best location for the probability slice is the median of the quantile function on that slice, at its midpoint level
- Because the midpoints make the representation's mean exact
- It is an arbitrary convention with no effect on the fixed point
Show the answer
B. Because the -best location for the probability slice is the median of the quantile function on that slice, at its midpoint level
to an equally weighted distribution splits into one term per slice, and each term is minimized at the slice's median level. Avoiding 0 and 1 is a side benefit, not the reason.
Rowland et al. bound the categorical fixed point's error by . What does halving the atom gap do to the bound, and what assumption does it need?
- It quarters the bound; no assumption is needed
- Nothing: the bound depends only on
- It halves the bound, provided every true return distribution lies inside
- It halves the bound for the mean only
Show the answer
C. It halves the bound, provided every true return distribution lies inside
The squared distance scales linearly with the gap, so the bound halves (the distance itself shrinks by ). The proof needs the true returns inside the support; otherwise the clipped mass adds a term, which Rowland et al. bound separately.
IQN acts with the CVaR distortion . Which part of each return distribution does its policy average?
- The best quarter of outcomes
- All outcomes, reweighted toward the mean
- Only the median
- The worst quarter: levels sampled uniformly from
Show the answer
D. The worst quarter: levels sampled uniformly from
, the mean of the lowest quarter of returns; in practice IQN samples its levels from . A risk-seeking distortion would push the levels upward instead.
Further reading
- M. Rowland, M. G. Bellemare, W. Dabney, R. Munos & Y. W. Teh, "An analysis of categorical distributional reinforcement learning", AISTATS (2018).
- W. Dabney, M. Rowland, M. G. Bellemare & R. Munos, "Distributional reinforcement learning with quantile regression", AAAI (2018).
- W. Dabney, G. Ostrovski, D. Silver & R. Munos, "Implicit quantile networks for distributional reinforcement learning", ICML (2018).
- M. Rowland, R. Dadashi, S. Kumar, R. Munos, M. G. Bellemare & W. Dabney, "Statistics and samples in distributional reinforcement learning", ICML (2019).
- M. Rowland, R. Munos, M. G. Azar, Y. Tang, G. Ostrovski, A. Harutyunyan, K. Tuyls, M. G. Bellemare & W. Dabney, "An analysis of quantile temporal-difference learning", Journal of Machine Learning Research 25(163) (2024).