Search

Search papers and lessons

Distributional Reinforcement Learning

Level 4 · 12 min read

Distributional reinforcement learning learns the whole distribution of possible returns from each state and action, not just their average, which gives richer learning signals and tells an agent about risk.

On this page

  • Colour = topic mix
  • Probability
  • Discrete math
  • Reinforcement learning
  • Calculus
  • Linear algebra
  • Stochastic processes
  • ReadReady to readNot yet

TL;DR

Most reinforcement learning methods learn only the average of the future reward from a state, which is the value function. Distributional reinforcement learning learns the full spread of possible returns: the chance of each total the agent might collect. The mean is still there, so nothing is lost, and the extra detail gives a stronger learning signal and a direct view of risk.

Builds on: Bellman Equation, Discounted Return, Probability Mass Function, Softmax · Leads to: risk-aware control and the categorical and quantile families of return models

Where it's used

Playing video games from pixels. The 2017 C51 agent, named for its 51 fixed support points, learned the return distribution with a deep network and reached strong results on the Atari suite. It extended the Deep Q-Network design by replacing a single output per action with a distribution over 51 values.

Robots and self-driving decisions. A controller that must avoid rare disasters cares about the lower tail of the return, not only the average. A learned distribution lets the designer ask for the chance that a plan ends badly, which an average hides. The worked example below uses this case.

Trading and resource control. A strategy that is good on average may still have a long bad tail. Distributional models let a practitioner compare two strategies by their risk profile, for example by the probability of losing more than a set amount.

How it works

Take one state xx with one action. The agent receives a reward and then moves to a state yy. From yy it always collects a fixed reward of 2 and then the episode ends. Use discount factor γ=0.5\gamma = 0.5. At xx the reward is 0 or 4, each with probability one half.

  1. Look at the immediate reward at xx. It is 0 with probability one half and 4 with probability one half. Check: the two probabilities add to 1.
  2. Look at the next state yy. Its return is always 2, because the reward is fixed and nothing follows. Check: a state with no randomness has a one-point distribution.
  3. Combine them with the discount. The return from xx is the reward plus 0.50.5 times the return from yy. If the reward is 0, the return is 0+0.5×2=10 + 0.5 \times 2 = 1. If the reward is 4, the return is 4+0.5×2=54 + 0.5 \times 2 = 5. Each case has probability one half. Check: the two outcomes 1 and 5 come from the two rewards.
  4. Check the mean. The average of the return is 0.5×1+0.5×5=30.5 \times 1 + 0.5 \times 5 = 3. The ordinary Bellman equation gives the same answer: the average immediate reward is 0.5×0+0.5×4=20.5 \times 0 + 0.5 \times 4 = 2, and the discounted value of yy adds 0.5×2=10.5 \times 2 = 1, so the value of xx is 2+1=32 + 1 = 3. Check: both routes give 3.
  5. Read the result. The return from xx is 1 or 5, each with probability one half. The mean is 3, but the average alone does not show that the return is always one of two values.
flowchart LR
  x["state x"] -->|"prob 1/2, reward 0"| o1["return 1"]
  x -->|"prob 1/2, reward 4"| o5["return 5"]

Distributional RL keeps the whole picture: at xx the two possible returns and their probabilities.

The math

Definition

The return from time tt is Gt=∑k≥0γkRt+k+1G_t = \sum_{k \ge 0} \gamma^k R_{t+k+1}, a random variable because the rewards and transitions are random. The return distribution of a policy π\pi in state ss is the distribution of GG when the episode starts in ss and actions follow π\pi. Write it Zπ(s)Z^\pi(s), a random variable whose law is the return distribution.

Definition: Return distribution

Zπ(s)Z^\pi(s) is the random variable GG that results from starting in ss and following π\pi. Its probability law is the distribution over possible returns. Its expected value is the ordinary value function:

vπ(s)=E[Zπ(s)].v_\pi(s) = \mathbb{E}\big[Z^\pi(s)\big].

Step 3 in symbols: the distributional Bellman equation

The return satisfies a one-step recursion: the immediate reward plus γ\gamma times the return from the next state. Write A∼π(⋅∣s)A \sim \pi(\cdot \mid s), R=R(s,A)R = R(s, A) and S′∼P(⋅∣s,A)S' \sim P(\cdot \mid s, A). Then

Zπ(s)=DR+γ Zπ(S′),Z^\pi(s) \overset{\mathcal{D}}{=} R + \gamma\, Z^\pi(S'),

where =D\overset{\mathcal{D}}{=} means equal in distribution: the two sides have the same probability law, though they need not be equal sample by sample. In the walkthrough, the left side is the return from xx, and the right side is the reward plus half the return from yy.

Step 4 in symbols: the mean recovers the Bellman equation

Take the expectation of both sides of the equation above. The expectation of a sum is the sum of expectations, so vπ(s)=E[R]+γ E[vπ(S′)]v_\pi(s) = \mathbb{E}[R] + \gamma\, \mathbb{E}[v_\pi(S')], which is the ordinary Bellman expectation equation. So a distributional method contains the usual one. This is why the mean in step 4 of the walkthrough matched the value 3.

The distributional operator behind the equation

Define the operator Tπ\mathcal{T}^\pi that maps a return distribution to the distribution of R+γZ(S′)R + \gamma Z(S'). Under the maximal Wasserstein distance dˉp\bar d_p between distributions, Tπ\mathcal{T}^\pi is a contraction with factor γ\gamma, the same rate as the ordinary Bellman operator. The argument in the 2017 paper uses the Wasserstein distance, and it guarantees that repeated application converges to a unique return distribution. This is the distributional counterpart of the convergence in Dynamic Programming.

Step 5 in symbols: the categorical model

A computer cannot represent an arbitrary distribution, so C51 fixes NN support points, or atoms, z1<⋯<zNz_1 \lt \dots \lt z_N evenly spaced from Vmin⁡V_{\min} to Vmax⁡V_{\max}, with spacing Δz=(Vmax⁡−Vmin⁡)/(N−1)\Delta z = (V_{\max} - V_{\min})/(N - 1). A network outputs NN scores for each action, and a Softmax turns them into probabilities pi(s,a)p_i(s, a) that sum to 1. The model is

Z(s,a)≈∑i=1Npi(s,a) δzi,Z(s, a) \approx \sum_{i=1}^{N} p_i(s, a)\, \delta_{z_i},

a probability mass function over the atoms, where δzi\delta_{z_i} puts all its mass on ziz_i. Only the probabilities are learned; the atoms are fixed.

Projecting the target onto the atoms

After a Bellman step, the shifted atoms r+γzjr + \gamma z_j may fall between grid points or outside [Vmin⁡,Vmax⁡][V_{\min}, V_{\max}]. The projection moves each piece of probability to the two nearest atoms. Clip z^j=min⁡(Vmax⁡,max⁡(Vmin⁡,r+γzj))\hat z_j = \min(V_{\max}, \max(V_{\min}, r + \gamma z_j)), and let bj=(z^j−Vmin⁡)/Δzb_j = (\hat z_j - V_{\min})/\Delta z, with lj=⌊bj⌋l_j = \lfloor b_j \rfloor and uj=⌈bj⌉u_j = \lceil b_j \rceil. Then each target atom with mass pjp_j adds

mlj+=pj (uj−bj),muj+=pj (bj−lj).m_{l_j} \mathrel{+}= p_j\,(u_j - b_j), \qquad m_{u_j} \mathrel{+}= p_j\,(b_j - l_j).

If bjb_j is a whole number, then lj=ujl_j = u_j and all the mass pjp_j goes to that atom. The result mm is a distribution over the atoms, and the network is trained to match it, usually with the cross-entropy loss between mm and the predicted pp.

Worked examples

Example
1. Tiny: one-step reward, no future
  1. From state ss the agent gets reward 1 with probability one half, and reward 0 with probability one half. Then the episode ends.
  2. The return from ss is just the reward. So it is 1 with probability one half and 0 with probability one half.
  3. The mean is 0.5×1+0.5×0=0.50.5 \times 1 + 0.5 \times 0 = 0.5, which is the value of ss.
  4. The variance is 0.5×(1−0.5)2+0.5×(0−0.5)2=0.250.5 \times (1 - 0.5)^2 + 0.5 \times (0 - 0.5)^2 = 0.25. Check: each deviation from the mean is 0.5, so its square is 0.25.
  5. Interpretation: the mean 0.5 is the value, and the variance 0.25 is the spread that the value alone does not show.
Example
2. Standard: projecting a target onto five atoms

Use atoms z={0,1,2,3,4}z = \{0, 1, 2, 3, 4\}, so Vmin⁡=0V_{\min} = 0, Vmax⁡=4V_{\max} = 4 and Δz=1\Delta z = 1. Let the next-state distribution be p=(0.1,0.2,0.4,0.2,0.1)p = (0.1, 0.2, 0.4, 0.2, 0.1). The reward is r=1r = 1 and γ=0.5\gamma = 0.5.

  1. Compute the shifted atoms 1+0.5zj1 + 0.5 z_j: they are 1,1.5,2,2.5,31, 1.5, 2, 2.5, 3. All lie inside [0,4][0, 4], so no clipping is needed.
  2. Convert to grid positions bj=z^j/Δzb_j = \hat z_j / \Delta z. These are 1,1.5,2,2.5,31, 1.5, 2, 2.5, 3.
  3. Atom z=0z = 0 has p=0.1p = 0.1 and b=1b = 1. It is a whole number, so all 0.10.1 goes to atom 1.
  4. Atom z=1z = 1 has p=0.2p = 0.2 and b=1.5b = 1.5. It splits between atoms 1 and 2: 0.2×(2−1.5)=0.10.2 \times (2 - 1.5) = 0.1 to atom 1 and 0.2×(1.5−1)=0.10.2 \times (1.5 - 1) = 0.1 to atom 2.
  5. Atom z=2z = 2 has p=0.4p = 0.4 and b=2b = 2. All 0.40.4 goes to atom 2.
  6. Atom z=3z = 3 has p=0.2p = 0.2 and b=2.5b = 2.5. It splits: 0.10.1 to atom 2 and 0.10.1 to atom 3.
  7. Atom z=4z = 4 has p=0.1p = 0.1 and b=3b = 3. All 0.10.1 goes to atom 3.
  8. Add up the masses by location: the atom at position 1 gets 0.1+0.1=0.20.1 + 0.1 = 0.2; the atom at position 2 gets 0.1+0.4+0.1=0.60.1 + 0.4 + 0.1 = 0.6; the atom at position 3 gets 0.1+0.1=0.20.1 + 0.1 = 0.2. The total is 1.0. Check: the masses add to 1, as they must.
  9. Check the mean. Before projection, the next-state mean is 0×0.1+1×0.2+2×0.4+3×0.2+4×0.1=2.00 \times 0.1 + 1 \times 0.2 + 2 \times 0.4 + 3 \times 0.2 + 4 \times 0.1 = 2.0, so the target mean is 1+0.5×2.0=2.01 + 0.5 \times 2.0 = 2.0. After projection, the mean is 1×0.2+2×0.6+3×0.2=2.01 \times 0.2 + 2 \times 0.6 + 3 \times 0.2 = 2.0. Check: the mean is preserved here because no clipping happened.
Example
3. Realistic: a car choosing when to merge

An autonomous car at a junction can merge now or wait. The return for each action, in reward points, has this distribution.

  • Merge: a return of 10 with probability 0.8, and a return of −6-6 with probability 0.2.
  • Wait: a return of 3 with probability 1.
  1. Compute the mean of merging: 0.8×10+0.2×(−6)=8−1.2=6.80.8 \times 10 + 0.2 \times (-6) = 8 - 1.2 = 6.8.
  2. Compute the mean of waiting: it is 3.
  3. Compare the means: 6.8 is larger than 3, so a mean-only agent merges.
  4. Look at the distribution of merging instead: one outcome in five is a negative return.
  5. Check the risk: merging has a negative return with probability 0.20.2, and waiting has a negative return with probability 00.
  6. Interpretation: the mean prefers merging, but the distribution shows a one-in-five chance of a loss. A designer who weights losses more than gains can choose waiting, and only the distributional model makes this trade-off visible.

Try it: for each action, what is the probability that the return is at least 5? Answer: merging gives 0.8, since only the return of 10 reaches 5. Waiting gives 0, since its return is 3.

Common mistakes and tradeoffs

It is tempting to think a distributional agent learns a different optimal policy; in fact its mean still satisfies the ordinary Bellman equation, so the value of each action is unchanged. What changes is the information the agent learns, and the way the network is trained. Risk-aware decisions use the extra information; mean-only decisions do not need it.

It is tempting to think the return distribution is the same as the reward distribution; in fact the return adds up discounted rewards across many steps, so its spread is usually larger and its shape can differ a great deal from any single reward.

It is tempting to read =D\overset{\mathcal{D}}{=} as equality of values; in fact it says the two sides have the same probability law. The random values on each side can differ on any single sample.

It is tempting to think the atoms are learned locations; in fact the atoms are a fixed grid chosen in advance, and only their probabilities change. A poor choice of Vmin⁡V_{\min} and Vmax⁡V_{\max} clips real returns and loses information, so the bounds need a rough guess of the return range.

Use distributional learning when the spread matters: risk, rare large losses, or when the extra signal helps a deep network learn. Do not use it when only the average return matters and compute is tight, because it needs NN outputs per action and a projection step. Alternatives include a single value per state, which is cheapest, and quantile models, which learn points on the return's cumulative distribution instead of a fixed grid.

History

Before 2017 most deep reinforcement learning used single values, as in Q-Learning and the Deep Q-Network of 2015, and the return distribution was mostly studied in theory. In 2017 Marc Bellemare, Will Dabney and Rémi Munos published "A Distributional Perspective on Reinforcement Learning", which proved that the distributional Bellman operator is a contraction and introduced the categorical C51 agent with its projection step. C51 showed large gains on Atari games, and the paper made the distribution a practical object for deep networks. The idea caught on because it gives the agent more to learn from at no loss to the mean, and because it provides a direct handle on risk.

Recap

  • The return from a state is a random variable, and its distribution is the return distribution.
  • Its mean is the ordinary value, so the usual Bellman equation is still inside the distributional one.
  • The distributional Bellman equation holds in distribution, and it is a contraction under the Wasserstein distance.
  • C51 approximates the distribution on a fixed grid of atoms and projects each Bellman target back onto that grid.
  • The distribution shows risk that the mean hides, which is why it matters for control.

Read next: Deep Q-Network for the network that C51 extends, Temporal-Difference Learning for the bootstrapped updates that the projected target builds on, and Kullback–Leibler Divergence for the divergence sometimes used to compare distributions.

Check yourself

QuestionA state's return is 2 with probability 0.5 and 6 with probability 0.5. What is its value?Show answer

The value is the mean, 0.5×2+0.5×6=40.5 \times 2 + 0.5 \times 6 = 4.

QuestionWith atoms at 0, 1 and 2, a target atom has mass 0.6 and shifted position 1.25. How much mass goes to the atoms at 1 and 2?Show answer

The position 1.25 lies between atoms 1 and 2, so the mass splits. Atom 1 gets 0.6×(2−1.25)=0.450.6 \times (2 - 1.25) = 0.45 and atom 2 gets 0.6×(1.25−1)=0.150.6 \times (1.25 - 1) = 0.15. Together they make 0.6, as they must.

QuestionWhy does the distributional Bellman equation use =D\overset{\mathcal{D}}{=} rather than an ordinary equals sign?Show answer

The two sides are random variables that have the same probability law but generally take different values on each sample. Only the distributions must agree, so equality in distribution is the correct statement.

QuestionTwo actions have the same mean return, but one has a much wider spread. Why might a distributional agent prefer the narrower one in a safety-critical task?Show answer

The wider action has more probability in its bad outcomes, so its chance of a harmful return is higher even though the mean is the same. A distributional agent can see that tail and prefer the narrower action, while a mean-only agent cannot tell them apart.

QuestionIn C51, why are the atom locations fixed while the probabilities are learned?Show answer

Fixing the atoms gives a common grid on which every return distribution can be represented and compared, so the network only has to learn how much probability goes to each location. Learning the locations too would make the representation harder to train and compare.

Sources