Simple Algorithm
Reinforcement Learning · Fixed Point · 28 min

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 KK-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, ℓ2(ν1,ν2)=(∫(Fν1(x)−Fν2(x))2dx)1/2\ell_2(\nu_1,\nu_2)=\big(\int(F_{\nu_1}(x)-F_{\nu_2}(x))^2dx\big)^{1/2}. It is an L2L^2 distance, so it has angles and orthogonal projections, and the projection C51 uses turns out to be one of them. Fix atoms z1<⋯<zKz_1<\dots<z_K with gap Δz\Delta z and let ΠC\Pi_C be C51's categorical projection.

DerivationProof sketch
  1. FΠν∣(zi,zi+1)=1Δz∫zizi+1Fν(x) dxF_{\Pi\nu}\big|_{(z_i,z_{i+1})}=\frac{1}{\Delta z}\int_{z_i}^{z_{i+1}}F_\nu(x)\,dx

    A distribution on the atoms has a CDF that is constant on each cell. Outside [z1,zK][z_1,z_K] all the CDFs involved agree (0 to the left, 1 to the right), so ℓ2\ell_2 becomes an L2L^2 distance between functions on [z1,zK][z_1,z_K], and the closest cell-wise constant function to FνF_\nu is its average on each cell:

  2. 1Δz∫zizi+11[x≥y] dx=zi+1−yΔz\frac{1}{\Delta z}\int_{z_i}^{z_{i+1}}\mathbf 1[x\ge y]\,dx=\frac{z_{i+1}-y}{\Delta z}

    This is C51's projection. For a point mass at y∈[zi,zi+1]y\in[z_i,z_{i+1}], the average of 1[x≥y]\mathbf 1[x\ge y] over the cell is (zi+1−y)/Δz(z_{i+1}-y)/\Delta z, which is exactly the weight C51 gives ziz_i, and so exactly the projected CDF on that cell. Both maps are linear in ν\nu, so they agree for every ν\nu.

  3. ℓ22(ν,ΠCν) ≤ Δz4∑ihi2 ≤ Δz4■\ell_2^2(\nu,\Pi_C\nu)\ \le\ \frac{\Delta z}{4}\sum_ih_i^2\ \le\ \frac{\Delta z}{4}\qquad\blacksquare

    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 FνF_\nu is monotone, rising by some hih_i with ∑ihi≤1\sum_ih_i\le1, so its squared deviation from its cell average integrates to at most Δz hi2/4\Delta z\,h_i^2/4.

Predict before you look

Project a point mass δy\delta_y with yy between two atoms Δz\Delta z apart. As a fraction of Δz\Delta z, what is the largest possible error ℓ22(δy,ΠCδy)\ell_2^2(\delta_y,\Pi_C\delta_y) over all positions of yy?

Show the answer

0.25

With p=(zi+1−y)/Δzp=(z_{i+1}-y)/\Delta z on the lower atom, the CDFs differ by pp on [zi,y)[z_i,y) and by 1−p1-p on [y,zi+1)[y,z_{i+1}), so ℓ22=p2(1−p)Δz+(1−p)2p Δz=p(1−p)Δz\ell_2^2=p^2(1-p)\Delta z+(1-p)^2p\,\Delta z=p(1-p)\Delta z, largest at p=12p=\tfrac12: a point mass midway between atoms gives Δz/4\Delta z/4, the bound above.

Why the bound holds. At each (s,a)(s,a) apply Pythagoras with μ=ηπ(s,a)=Tπηπ(s,a)\mu=\eta^\pi(s,a)=\mathcal T^\pi\eta^\pi(s,a) and ν=ηC(s,a)=ΠCTπηC(s,a)\nu=\eta_C(s,a)=\Pi_C\mathcal T^\pi\eta_C(s,a): ℓ22(μ,ν)=ℓ22(μ,ΠCμ)+ℓ22(ΠCTπηπ,ΠCTπηC)≤Δz4+γ ℓˉ2 2(ηπ,ηC)\ell_2^2(\mu,\nu)=\ell_2^2(\mu,\Pi_C\mu)+\ell_2^2(\Pi_C\mathcal T^\pi\eta^\pi,\Pi_C\mathcal T^\pi\eta_C)\le\frac{\Delta z}{4}+\gamma\,\bar\ell_2^{\,2}(\eta^\pi,\eta_C). Taking the supremum gives ℓˉ2 2≤Δz4(1−γ)\bar\ell_2^{\,2}\le\frac{\Delta z}{4(1-\gamma)}, inside the stated bound with room to spare. Two caveats. ΠCTπ\Pi_C\mathcal T^\pi is in general not a contraction in the Wasserstein distances dˉp\bar d_p for p>1p>1, 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 U=1K∑iδθiU=\frac1K\sum_i\delta_{\theta_i} with θ1≤⋯≤θK\theta_1\le\dots\le\theta_K, the Wasserstein-1 distance to ν\nu couples the two quantile functions: with τi=i/K\tau_i=i/K, W1(ν,U)=∑i=1K∫τi−1τi∣Fν−1(ω)−θi∣ dω.W_1(\nu,U)=\sum_{i=1}^{K}\int_{\tau_{i-1}}^{\tau_i}\big|F_\nu^{-1}(\omega)-\theta_i\big|\,d\omega. Each θi\theta_i appears in one term only, so the best atoms can be found one slice at a time.

Proof. Increasing θ\theta increases ∣F−1(ω)−θ∣\abs{F^{-1}(\omega)-\theta} for the ω\omega with F−1(ω)<θF^{-1}(\omega)<\theta, a set of length about F(θ)−τF(\theta)-\tau, and decreases it for the rest, of length about τ′−F(θ)\tau'-F(\theta). The derivative 2F(θ)−τ−τ′2F(\theta)-\tau-\tau' vanishes at F(θ)=τ+τ′2F(\theta)=\frac{\tau+\tau'}2: the best atom for a slice is the median of the quantile function on that slice. ■\blacksquare A direct consequence bounds the mean error of this representation: for ν\nu on [a,b][a,b], half of each slice lies on either side of its midpoint, so each slice contributes at most its range of F−1F^{-1} divided by 2K2K, and ∣EνZ−EΠW1νZ∣≤W1(ν,ΠW1ν)≤b−a2K.\big|\E_\nu Z-\E_{\Pi_{W_1}\nu}Z\big|\le W_1(\nu,\Pi_{W_1}\nu)\le\frac{b-a}{2K}. For the lottery with 21 quantiles the bound is 10/42≈0.2410/42\approx0.24; the actual error is 1.9−1.852=0.0481.9-1.852=0.048.

Check your understanding

QR-DQN's goal is the W1W_1 projection of the target distribution. Why does it minimize the quantile loss instead of the W1W_1 distance itself?

  1. The quantile loss is cheaper to evaluate
  2. The two have different minimizers, and the quantile loss's is better
  3. Gradients of W1W_1 estimated from sampled targets are biased, while the quantile loss's sample gradients are unbiased and lead to the same minimizers
  4. W1W_1 is undefined for discrete distributions
Show the answer

C. Gradients of W1W_1 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, r+γθj(s′,a⋆)r+\gamma\theta_j(s',a^\star). 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 F(θ)−τF(\theta)-\tau, whose single-sample estimate 1[Z<θ]−τ\mathbf 1[Z<\theta]-\tau 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, Zτ(s,a)≈FZ(s,a)−1(τ)Z_\tau(s,a)\approx F^{-1}_{Z(s,a)}(\tau) for any τ∈[0,1]\tau\in[0,1], as Zτ(s,a)=f(ψ(s)⊙ϕ(τ))aZ_\tau(s,a)=f\big(\psi(s)\odot\phi(\tau)\big)_a: the convolutional features ψ(s)\psi(s) are multiplied elementwise by an embedding of the level,

ϕj(τ)=ReLU⁡(∑i=0n−1cos⁡(πiτ) wij+bj),n=64;L=1N′∑i=1N∑j=1N′ρτiκ(r+γZτj′(s′,πβ(s′))−Zτi(s,a))\phi_j(\tau)=\operatorname{ReLU}\Big(\sum_{i=0}^{n-1}\cos(\pi i\tau)\,w_{ij}+b_j\Big),\quad n=64;\qquad\loss=\frac{1}{N'}\sum_{i=1}^{N}\sum_{j=1}^{N'}\rho^\kappa_{\tau_i}\Big(r+\gamma Z_{\tau'_j}\big(s',\pi_\beta(s')\big)-Z_{\tau_i}(s,a)\Big)
Each update samples fresh levels τ1,…,τN\tau_1,\dots,\tau_N and τ1′,…,τN′′\tau'_1,\dots,\tau'_{N'} uniformly from [0,1][0,1]; N=N′=8N=N'=8 sufficed. Because the levels are sampled, the network is trained at all of them, and its capacity, not a fixed KK, limits how finely the distribution is resolved.

Sampling levels makes risk-sensitive control nearly free. For a distortion β:[0,1]→[0,1]\beta:[0,1]\to[0,1], nondecreasing, with the identity meaning risk-neutral (it need not reach 1: the CVaR distortion below does not), the distorted expectation Qβ(s,a)=∫01FZ(s,a)−1(β(τ)) dτ=Eτ∼U[0,1][Zβ(τ)(s,a)]Q_\beta(s,a)=\int_0^1F^{-1}_{Z(s,a)}(\beta(\tau))\,d\tau=\E_{\tau\sim U[0,1]}\big[Z_{\beta(\tau)}(s,a)\big] is estimated by averaging Zβ(τ)Z_{\beta(\tau)} over K=32K=32 sampled levels, and the policy πβ\pi_\beta maximizes it. IQN tried several distortions: Wang's β(τ)=Φ(Φ−1(τ)+η)\beta(\tau)=\Phi(\Phi^{-1}(\tau)+\eta) (risk-averse for η<0\eta<0), the cumulative probability weighting of prospect theory with η=0.71\eta=0.71, a power family, and CVaR:

β(τ)=η τ⟹Qβ(s,a)=∫01F−1(ητ) dτ=1η∫0ηF−1(u) du=CVaR⁡η(Z(s,a))\beta(\tau)=\eta\,\tau\quad\Longrightarrow\quad Q_\beta(s,a)=\int_0^1F^{-1}(\eta\tau)\,d\tau=\frac1\eta\int_0^\eta F^{-1}(u)\,du=\operatorname{CVaR}_\eta\big(Z(s,a)\big)
Substitute u=ητu=\eta\tau. In practice the CVaR policy simply samples its levels from U[0,η]U[0,\eta] instead of U[0,1]U[0,1].

In its risk-neutral form (β(τ)=τ\beta(\tau)=\tau), 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 πβ\pi_\beta optimizes: it maximizes a distorted expectation of Z(s,a)Z(s,a) at every step, and the target uses πβ\pi_\beta 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 0=τ0<τ1<⋯<τN=10=\tau_0<\tau_1<\dots<\tau_N=1, trained so that the staircase they define is as close as possible to the true distribution in W1W_1; 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.

MethodWhat is learnedHow the target is fittedWhat is known
C51Probabilities on fixed atomsCategorical projection, then cross-entropyΠCTπ\Pi_C\mathcal T^\pi is a γ\sqrt\gamma-contraction in ℓˉ2\bar\ell_2; mean exact inside the support
QR-DQNLocations at fixed midpoint levelsQuantile (Huber) regressionΠW1Tπ\Pi_{W_1}\mathcal T^\pi contracts in dˉ∞\bar d_\infty; tabular QTD converges to a set of fixed points
IQNThe quantile function at sampled levelsQuantile regression at random levelsSupports distortion risk measures directly
FQFLevels and locationsW1W_1 for the levels, quantile regression for the valuesAdapts the resolution to the distribution
EDRL / ER-DQNExpectilesExpectile regression on imputed samplesNaive backups collapse; imputation restores consistency
MMDQNUnconstrained particlesMaximum mean discrepancy to the target's particlesNo predefined statistic
A map of the main families, as of the mid-2020s. The contraction results are for tabular dynamic programming; with networks, convergence is not established for any of them.

Key takeaways

  • C51's projection is the ℓ2\ell_2 (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 γ\sqrt\gamma-contraction of ΠCTπ\Pi_C\mathcal T^\pi in ℓˉ2\bar\ell_2, and a fixed point within ℓˉ2 2≤Δz/(1−γ)\bar\ell_2^{\,2}\le\Delta z/(1-\gamma) of the truth when returns lie in the support.
  • The W1W_1-best equally weighted atoms are the quantiles at the midpoint levels 2i−12K\frac{2i-1}{2K}; quantile regression learns them with unbiased sample gradients, ΠW1Tπ\Pi_{W_1}\mathcal T^\pi contracts in dˉ∞\bar d_\infty, and the representation's mean is off by at most (b−a)/(2K)(b-a)/(2K).
  • 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.

Question 1

In which distance is C51's categorical projection an orthogonal projection?

  1. The Cramér distance, the L2L^2 distance between CDFs
  2. The Wasserstein-1 distance
  3. The Kullback–Leibler divergence
  4. The total variation distance
Show the answer

A. The Cramér distance, the L2L^2 distance between CDFs

On each cell between atoms the projected CDF is the average of the original CDF, which is the L2L^2 projection onto cell-wise constant functions. That gives the Pythagorean identity, the non-expansion, and with the γ\sqrt\gamma-contraction of Tπ\mathcal T^\pi in ℓˉ2\bar\ell_2, convergence of categorical TD.

Question 2

Why do QR-DQN's atoms target the levels τ^i=2i−12K\hat\tau_i=\frac{2i-1}{2K} rather than i/Ki/K?

  1. To avoid the levels 0 and 1, where quantiles may be infinite
  2. Because the W1W_1-best location for the probability slice [i−1K,iK][\frac{i-1}{K},\frac iK] is the median of the quantile function on that slice, at its midpoint level
  3. Because the midpoints make the representation's mean exact
  4. It is an arbitrary convention with no effect on the fixed point
Show the answer

B. Because the W1W_1-best location for the probability slice [i−1K,iK][\frac{i-1}{K},\frac iK] is the median of the quantile function on that slice, at its midpoint level

W1W_1 to an equally weighted distribution splits into one term per slice, and each term ∫∣F−1(ω)−θi∣dω\int\abs{F^{-1}(\omega)-\theta_i}d\omega is minimized at the slice's median level. Avoiding 0 and 1 is a side benefit, not the reason.

Question 3

Rowland et al. bound the categorical fixed point's error by ℓˉ2 2(ηC,ηπ)≤11−γmax⁡i(zi+1−zi)\bar\ell_2^{\,2}(\eta_C,\eta^\pi)\le\frac{1}{1-\gamma}\max_i(z_{i+1}-z_i). What does halving the atom gap do to the bound, and what assumption does it need?

  1. It quarters the bound; no assumption is needed
  2. Nothing: the bound depends only on γ\gamma
  3. It halves the bound, provided every true return distribution lies inside [z1,zK][z_1,z_K]
  4. It halves the bound for the mean only
Show the answer

C. It halves the bound, provided every true return distribution lies inside [z1,zK][z_1,z_K]

The squared distance scales linearly with the gap, so the bound halves (the distance itself shrinks by 2\sqrt2). The proof needs the true returns inside the support; otherwise the clipped mass adds a term, which Rowland et al. bound separately.

Question 4

IQN acts with the CVaR distortion β(τ)=0.25 τ\beta(\tau)=0.25\,\tau. Which part of each return distribution does its policy average?

  1. The best quarter of outcomes
  2. All outcomes, reweighted toward the mean
  3. Only the median
  4. The worst quarter: levels sampled uniformly from [0,0.25][0,0.25]
Show the answer

D. The worst quarter: levels sampled uniformly from [0,0.25][0,0.25]

∫01F−1(0.25τ) dτ=4∫00.25F−1(u) du=CVaR⁡0.25\int_0^1F^{-1}(0.25\tau)\,d\tau=4\int_0^{0.25}F^{-1}(u)\,du=\operatorname{CVaR}_{0.25}, the mean of the lowest quarter of returns; in practice IQN samples its levels from U[0,0.25]U[0,0.25]. 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).