Modern Deep Reinforcement Learning/Sharpening DQN: Improvements and the Distributional Idea

Lesson 5.12,433 words

Sharpening DQN: Improvements and the Distributional Idea

In the years after the 2015 DQN paper, a stream of focused improvements each fixed one weakness of the baseline without disturbing its frame. This lesson recaps five that keep the scalar QQ-value — Double DQN, multi-step returns, dueling networks, prioritized replay, and NoisyNets, each changing a different slot of the same Q-learning loop — then develops the sixth, distributional RL, which changes the objective itself: learn the whole return distribution Z(s,a)Z(s,a).

╌╌╌╌

Deep Q-networks made value-based deep RL work: approximate with a neural network, train it by bootstrapped semi-gradient regression, and stabilize the deadly triad with a replay buffer and a frozen target network. In the five years after the 2015 Nature paper, a stream of focused papers each fixed one weakness of that baseline without disturbing the frame. Six of them proved to matter enough to keep, and one — distributional reinforcement learning — turned out to be less a patch than a change of objective: instead of predicting the average return, predict the whole distribution of returns and act on its mean.

This lesson takes five of the six improvements — the ones that keep the scalar -value and adjust the target, the network, the data, or the exploration — and then the sixth and deepest, distributional RL, which changes what the value head predicts. We stop after the C51 algorithm and its projection; the quantile methods, the Rainbow agent that folds all six together, and the modern distributional line continue in a companion lesson.1 The through-line is that every fix changes one slot of the same Q-learning loop, so they compose.

Six ways to sharpen DQN

Think of the DQN agent as a machine with a few interchangeable slots: which data it learns from, what its network looks like, what target it regresses toward, and how it explores. Each of the six improvements swaps out one slot and leaves the rest alone. Three of the six were introduced alongside the baseline in the DQN lesson and are recapped here only as a checklist; the other three are new. Each changes one slot of the agent, and — this is the point Rainbow rests on — they change different slots, so they compose.

ImprovementSlot it changesOne-line fix
Double DQNthe targetselect the greedy action with the online net, evaluate it with the target net, removing the max-overestimation bias
Dueling networksthe networksplit into a state-value stream and an advantage stream
Prioritized replaywhich datasample transitions in proportion to their absolute TD error
Multi-step returnsthe targetbootstrap after real rewards instead of one
Distributional (C51)what is predictedlearn the return distribution , not just its mean
NoisyNetsexplorationlearnable noise on the weights replaces -greedy

Double DQN (van Hasselt et al., 2016) decouples action selection from action evaluation so that noise which inflates an action's estimate is not both chosen and trusted; the target becomes .2Dueling networks (Wang et al., 2016) restructure the head into a scalar and a per-action advantage recombined with the mean advantage subtracted, so the state value is trained by every action's update.3Prioritized experience replay (Schaul et al., 2016) draws transition with probability , , and corrects the induced bias with importance-sampling weights .4 Those three were covered in full earlier. The remaining three deserve a paragraph each.

Multi-step returns

One-step Q-learning bootstraps immediately: the target uses one real reward and then trusts the network for everything after. Waiting for real rewards before bootstrapping trades a little variance for much less bias early in training, exactly as in -step TD. The -step target replaces the single reward with a truncated -step return:

Reward information propagates times faster along a trajectory, so credit reaches early states in far fewer updates. Rainbow uses . In principle a multi-step target off-policy needs importance-sampling corrections; in practice, with short and a replay buffer of recent-ish data, the uncorrected version works well and is what Rainbow ships.5

For example, suppose a transition earns rewards , , before the agent bootstraps, with , and the current network badly misestimates the state at horizon as when the true continuation value is . The one-step target is , dominated by the wrong bootstrap: almost the entire target is the network's own error. The three-step target is , and the true three-step value is . The absolute bootstrap error has shrunk from in the one-step target to — modest here, but the deeper point is that the two real rewards now anchor the target, so the network's mistake is diluted by real reward signal. The cost is variance: a three-step return sums three stochastic rewards, so its spread across episodes is larger. Short (Rainbow's ) sits near the sweet spot for Atari — enough real reward to cut early bias, not so many steps that variance swamps it.

The n-step bias-variance trade. A one-step target (top) is almost all bootstrap, so a wrong network value passes straight through; an n-step target (bottom) anchors on n real rewards first, diluting the bootstrap error, at the price of summing more stochastic rewards (higher variance). Rainbow uses n=3.

NoisyNets for exploration

-greedy explores by flipping a coin at every state and, with probability , ignoring everything the network has learned. It is state-independent and clumsy: on games needing a long, specific sequence of actions to reach the first reward — Montezuma's Revenge is the standing example — uniform random jitter almost never stumbles onto that sequence. NoisyNets (Fortunato et al., 2018) replace the schedule with learnable noise injected into the network's linear layers.6 A noisy linear layer replaces the ordinary weight and bias with

where and are learned parameters and is sampled noise resampled each forward pass. The network learns how much noise to add, and where: in states where exploration still pays it can keep large, and in states it has mastered it can drive toward zero, annealing its own exploration per state rather than on a global clock. The extra parameters are trained by the ordinary gradient — no new loss term — and at evaluation the noise is switched off.

For a layer with inputs and outputs, independent noise would need samples of per forward pass — expensive for the large linear layers of a value network. Fortunato et al. use factorized Gaussian noise to cut that to : sample one vector and one , pass each through , and set the weight noise to the outer product with bias noise . The rank-one structure trades a little noise diversity for a large saving in sampling cost, and it is what Rainbow ships. The initialization matters: starts near (with ), so early training is noticeably stochastic and shrinks only where the return gradient indicates exploration no longer pays.

A NoisyNet linear layer. Each weight is a learned mean plus a learned scale times fresh noise; the layer learns per-weight sigma, so exploration becomes state-dependent and self-annealing. Factorized noise samples one input vector and one output vector and forms their outer product, needing p+q samples not p*q.

The distributional idea

The other five improvements adjust the target, the network, the data, or the exploration; distributional RL changes what the value head predicts. It is the central idea of this lesson, so we state the shift precisely before any algorithm.

The return from a state-action pair,

is a random variable. Reward is stochastic, transitions are stochastic, and the policy may be stochastic, so the same produces a spread of returns across episodes. The action-value function throws that spread away and keeps only its mean:

Distributional RL keeps the whole random variable and learns its distribution. A state where an action is a coin flip between a big win and a big loss and a state where it reliably yields the average of the two can share the same -value while having very different return distributions; the distributional agent distinguishes them.7

Two actions with the same expected return but very different return distributions . The value function (dashed line) sees only the shared mean; the distributional view sees the bimodal gamble on the left and the tight single mode on the right.

The distributional Bellman equation

The ordinary Bellman equation relates expected values: . The distributional version relates the random variables themselves, before any expectation is taken:

where means equal in distribution and are drawn from the transition and the policy. Read the right-hand side as an operation on distributions: sampling a next state-action pair selects one of the distributions ; multiplying by scales it toward zero; adding the reward shifts it along the return axis; and mixing over the stochastic superposes the results into a new distribution. That composite map is the distributional Bellman operator , and its fixed point is .7 Taking expectations of both sides collapses it back to the familiar scalar Bellman equation, which is why any solution to the distributional problem also solves the ordinary one — distributional RL loses nothing and carries strictly more information.

The distributional Bellman operator acting on a return distribution: discounting by scales the distribution toward the origin, adding the reward shifts it right, and mixing over next-states superposes the pieces. The result is the new distribution for the current pair.

C51: a categorical distribution on fixed atoms

To learn with a network, you must choose how to represent a distribution. C51 (Bellemare, Dabney & Munos, 2017) takes the most direct route: fix a finite grid of possible return values — the atoms — and let the network output a probability for each.7 The atoms are spaced evenly on ,

and for each state-action pair the network emits a softmax over the atoms, giving probabilities that sum to one. The approximate return distribution is the categorical

with a point mass at atom . The mean used to act greedily is just the atom values weighted by their probabilities. The 51 is the atom count the paper found best; was standard for Atari with reward clipping.

The projection step

Fixing the atoms creates one difficulty, and resolving it is the whole technical content of C51. Apply the distributional Bellman operator to a categorical distribution and the atoms move: each atom of the next-state distribution maps to , and in general that value is not one of the atoms. The scaled-and-shifted distribution lives on a displaced grid that no longer lines up with the fixed support the network can represent.

The fix is a projection that redistributes each shifted atom's probability mass onto the two nearest fixed atoms, splitting it in inverse proportion to distance (and clipping to at the ends). Formally, the mass that the Bellman update places at is spread onto atom by the amount

where clips to and is the greedy next action. The inner bracket is the linear how close is the shifted atom to weight — one when they coincide, zero a full away — so each shifted atom's mass lands entirely within the grid. The result is a valid categorical distribution on the fixed atoms, and it becomes the regression target.

The C51 projection. A next-state atom's mass at is scaled and shifted to , which falls between two fixed atoms; the projection splits that mass onto the two neighbors in inverse proportion to distance, so the target lives on the same grid the network predicts.

C51 then minimizes the cross-entropy between the network's predicted categorical and the projected target — a classification-style loss over atoms, not a squared TD error. Everything else is DQN: replay buffer, target network , -greedy (or NoisyNet) behavior, and greedy action selection by the mean . On the Atari suite C51 beat every prior single-improvement variant, and it did so while still acting on the mean — the richer target simply produces a better-shaped mean.7

Algorithm:Categorical-Update\textsc{Categorical-Update} (C51) — one gradient step on a sampled transition
  1. 1
    input: transition (s,a,r,s)(s, a, r, s'), atoms z1,,zNz_1, \ldots, z_N, target weights θ\theta^-
  2. 2
    aargmaxaizipi(s,a;θ)a^{\ast} \gets \arg\max_{a'} \sum_i z_i\, p_i(s', a'; \theta^{-})
    greedy next action by mean
  3. 3
    mi0m_i \gets 0 for i=1,,Ni = 1, \ldots, N
    projected target, per atom
  4. 4
    for j=1,,Nj = 1, \ldots, N do
  5. 5
    T^zj[r+γzj]VminVmax\hat{T} z_j \gets [\,r + \gamma z_j\,]_{V_{\min}}^{V_{\max}}
    scale, shift, clip
  6. 6
    b(T^zjVmin)/Δzb \gets (\hat{T} z_j - V_{\min}) / \Delta z
    fractional atom index
  7. 7
    lbl \gets \lfloor b \rfloor
  8. 8
    ubu \gets \lceil b \rceil
  9. 9
    mlml+pj(s,a;θ)(ub)m_l \gets m_l + p_j(s', a^{\ast}; \theta^{-})\,(u - b)
    mass to lower neighbor
  10. 10
    mumu+pj(s,a;θ)(bl)m_u \gets m_u + p_j(s', a^{\ast}; \theta^{-})\,(b - l)
    mass to upper neighbor
  11. 11
    take a gradient step on the cross-entropy imilogpi(s,a;θ)-\sum_i m_i \log p_i(s, a; \theta)

A projection worked end to end

For example, take a small grid to keep the arithmetic legible: atoms on , so and the atoms are . Suppose the greedy next-state distribution puts its mass on just two atoms, — probability at and at . Let the reward be and the discount .

Each atom is scaled and shifted by , then clipped to :

Neither nor is a grid atom, so each must be split. The fractional index of a shifted value is ; here and . For the first, and (atoms and in index terms — indices and in the zero-based atom array). The mass splits by distance: to the lower neighbor and to the upper. So atom index (value ) receives and atom index (value ) receives . For the second, gives , , splitting into at atom index and at atom index . Collecting per atom:

The masses sum to , as they must, and this vector — a valid categorical on the fixed grid — is the cross-entropy target for the current pair. Its mean is , which equals exactly. The projection moves mass around but preserves the mean — the scalar Bellman backup is a by-product of the distributional one.

The worked projection. Two source atoms at z=2 (mass 0.6) and z=3 (mass 0.4) are scaled-shifted to 2.3 and 3.2, each landing between grid atoms; the mass splits by inverse distance onto neighbors, giving the target (0, 0, 0.42, 0.50, 0.08) whose mean 2.66 matches the scalar Bellman backup.

Where this leaves us

Two threads are now in hand. Five improvements — Double DQN, multi-step returns, dueling networks, prioritized replay, and NoisyNets — each sharpen one slot of the Q-learning loop without touching the others, which is what lets them stack. And distributional RL reframes the objective: predict the whole return distribution , act on its mean , and get a richer, better-shaped estimate for free. C51 realizes that idea with a fixed grid of atoms and a projection that snaps each Bellman-updated distribution back onto the grid.

C51 fixes the return values and learns their probabilities. The natural complement — fix the probabilities and learn the values — gives QR-DQN, which drops the projection entirely. That method, the reasons the distribution helps even when you act on the mean, and the Rainbow agent that assembles all six improvements at once (with its component ablation) continue in Distributional RL and Rainbow.

Footnotes

  1. Hessel et al. (2018), Rainbow: Combining Improvements in Deep Reinforcement Learning, AAAI — the integrated agent combining Double DQN, dueling networks, prioritized replay, multi-step returns, distributional (C51) learning, and NoisyNets; new state of the art on the 57-game Atari benchmark with markedly better sample efficiency; and the component ablation showing prioritized replay and multi-step returns most important, the distributional head growing in importance over training, and Double DQN largely redundant given the distributional target.
  2. van Hasselt, Guez & Silver (2016), Deep Reinforcement Learning with Double Q-learning, AAAI — decoupling action selection (online weights) from evaluation (target weights) to correct the maximization overestimation bias inherited from tabular Q-learning; target .
  3. Wang et al. (2016), Dueling Network Architectures for Deep Reinforcement Learning, ICML — the two-stream network with a scalar state-value and a per-action advantage recombined with the mean advantage subtracted for identifiability, giving lower-variance, more sample-efficient learning of .
  4. Schaul et al. (2016), Prioritized Experience Replay, ICLR — sampling transitions with probability , priority the absolute TD error, and importance-sampling weights (with annealed to 1) correcting the bias from non-uniform sampling.
  5. Sutton & Barto, Reinforcement Learning: An Introduction (2nd ed.), Ch. 7 — -step bootstrapping and the -step return ; Rainbow (Hessel et al., 2018) adopts the uncorrected multi-step target with .
  6. Fortunato et al. (2018), Noisy Networks for Exploration, ICLR — replacing -greedy with learnable parametric noise on the network's linear layers, so the agent learns a state-dependent amount of exploration trained by the ordinary gradient.
  7. Bellemare, Dabney & Munos (2017), A Distributional Perspective on Reinforcement Learning, ICML — the return distribution with , the distributional Bellman equation , and the C51 algorithm: fixed atoms on , a softmax over atoms, the categorical projection of the scaled-shifted target onto the fixed grid, and a cross-entropy loss; state of the art on Atari while acting on the mean. 2 3 4

╌╌ END ╌╌