Deep Q-Networks
Replay buffers, target networks and Atari.
In 2015 one network architecture, with one set of hyperparameters, learned to play 49 Atari games from raw pixels and the score. Its algorithm was Q-learning, run inside the deadly triad and kept stable by two engineering ideas. The decade of fixes that followed, from Double DQN to distributional RL, each repaired a flaw that theory can name.
What you’ll learn
- Write the DQN loss and algorithm, and explain how experience replay and a target network turn Q-learning into a sequence of regression problems.
- Prove and van Hasselt's lower bound on overestimation, and show why Double DQN's decoupled estimator removes the upward bias.
- Explain dueling networks, prioritized replay with importance weights, multi-step targets and noisy nets, and what Rainbow's ablations say about them.
- State the distributional Bellman equation, prove that its evaluation operator contracts in the Wasserstein metric, and describe C51's categorical projection.
DQN: Q-learning as repeated regression
DQN (Mnih et al., 2015) represents by a convolutional network that reads the last four 84 × 84 grayscale frames and outputs one value per action. It minimizes a squared TD error against a target network with frozen parameters , on minibatches drawn uniformly from a replay buffer of recent transitions:
initialize Q_θ; target θ⁻ ← θ; replay buffer D with capacity N
for each environment step t:
a_t ← random action with probability ε, else argmax_a Q_θ(s_t, a)
execute a_t; observe r_t, s_{t+1}, done_t; store the transition in D
every 4 steps:
sample a minibatch of B transitions (s, a, r, s', d) uniformly from D
y ← r + γ·(1 − d)·max_a' Q_θ⁻(s', a') # no gradient through y
θ ← θ − η·∇_θ mean Huber(y − Q_θ(s, a))
every C updates: θ⁻ ← θThe Nature DQN used transitions, , updates, RMSProp, annealed from 1 to 0.1 over the first million frames, rewards clipped to , and 50 million frames of play per game.
Each ingredient answers a failure of naive online Q-learning with a network. Consecutive frames are highly correlated, so a network trained on them in order chases the recent past; uniform replay over a million transitions makes minibatches closer to i.i.d. and reuses each transition many times (experience replay, Lin, 1992). A bootstrapped target that moves with every gradient step chases itself; freezing it for updates makes each phase an ordinary supervised regression. DQN is thus close to fitted Q-iteration (Ernst, Geurts & Wehenkel, 2005; Riedmiller, 2005):
Across the 49 games, DQN outperformed the best earlier reinforcement-learning methods on 43 and reached at least 75% of a professional human tester's score on 29, with the same architecture and hyperparameters throughout. Scores in this literature are usually human-normalized, . Five years later Agent57 (Badia et al., 2020) became the first agent to exceed the human benchmark on all 57 games of the standard suite.
Overestimation and Double DQN
(a) For each , pointwise, so ; take the maximum over . Equivalently, Jensen's inequality for the convex function .
(b) Let and . The errors sum to zero, so the positive ones and the negative ones have the same total size ; at most are positive, so . Then:
Hence , with equality when errors equal and one equals . Errors that are unbiased on average still produce a biased maximum.
Two actions both have true value 0, and their estimates carry independent standard normal errors. What is the expected value of the larger estimate?
Show the answer
0.56
, and has . So : more than half a standard deviation of bias, from noise alone. With 10 actions it is about 1.54.
Q-learning bootstraps from exactly this maximum, so the bias feeds the next targets. Double Q-learning (van Hasselt, 2010) keeps two estimates and lets one choose while the other evaluates. If and is unbiased and independent of , then : in general an underestimate rather than an overestimate. Double DQN (van Hasselt, Guez & Silver, 2016) reuses the two networks DQN already has: the online network selects, the target network evaluates.
Dueling heads, prioritized replay and Rainbow
Many states are good or bad whatever you do there. A dueling network (Wang et al., 2016) splits its head into a state value and action advantages, recombined with a centering term that makes the split identifiable:
Uniform replay spends most updates on transitions the network already predicts well. Prioritized replay (Schaul et al., 2016) samples transition with probability , where the priority comes from its last TD error. That changes the distribution the expected update averages over, so each update is weighted by , with annealed to 1 so that the correction is exact by the end of training.
| Extension | Flaw it addresses | Change |
|---|---|---|
| Double Q-learning (van Hasselt et al., 2016) | maximization bias | online network selects, target network evaluates |
| Prioritized replay (Schaul et al., 2016) | uniform replay wastes updates | sample by TD error; correct with importance weights |
| Dueling heads (Wang et al., 2016) | values learned one action at a time | separate and centered |
| Multi-step targets | slow propagation of reward | -step returns ( in Rainbow) |
| Distributional RL (Bellemare et al., 2017) | only the mean return is learned | learn the whole return distribution (C51) |
| Noisy nets (Fortunato et al., 2018) | ε-greedy explores blindly | learned parameter noise in the linear layers |
Why does prioritized replay weight each update by ?
- To make high-error transitions count even more
- To keep the replay buffer from overflowing
- To decorrelate consecutive transitions
- Prioritized sampling changes the distribution the expected update averages over, which would shift the fixed point unless corrected
Show the answer
D. Prioritized sampling changes the distribution the expected update averages over, which would shift the fixed point unless corrected
The expected update under uniform replay is an average over the buffer with weights . Sampling with probability reweights transition by ; multiplying by , i.e. , undoes this exactly. Annealing from about 0.4 accepts some bias early, while the targets are moving anyway, in exchange for lower variance.
Distributional reinforcement learning
Q-learning learns the mean of the return. Distributional RL learns its whole distribution , a random variable whose mean is , through the distributional Bellman equation, an equality in distribution:
is the smallest value of over couplings of and . Two properties follow directly, for a scalar and a random variable independent of and :
Couple and optimally for each next pair, and let both targets share the reward and the transition. Under this coupling the two targets differ by times the coupled difference:
Averaging over cannot exceed the worst pair: . Take the supremum over :
C51 represents each as a categorical distribution on 51 fixed atoms evenly spaced on . The shifted atoms of the target fall between grid points, so the target is projected back onto the support, each shifted atom's mass split between its two neighbors in proportion to proximity, and the network minimizes the cross-entropy to the projected target. This trains well but does not match the theory, because KL is not a metric in which contracts. The projected categorical operator turns out to be a contraction in the Cramér distance (Rowland et al., 2018), and QR-DQN (Dabney et al., 2018) learns quantiles with a quantile-regression loss, whose projected operator contracts in the maximal -Wasserstein metric.
Why should learning a distribution help a greedy policy that uses only its mean? In tabular and linear settings, distributional and expected methods produce the same means (Lyle, Bellemare & Castro, 2019), so the gains with deep networks are usually attributed to a richer training signal for the shared representation, an explanation that is plausible but not settled. Distributions are directly useful for risk-sensitive control, where the policy cares about more than the mean.
Key takeaways
- DQN is Q-learning with a convolutional network, uniform replay and a periodically frozen target network; each target period is a regression, so DQN approximates fitted Q-iteration.
- ; with errors unbiased on average and mean square , the maximum overestimates by at least . Double DQN selects with the online network and evaluates with the target network.
- Dueling heads, prioritized replay with importance weights annealed to , multi-step targets, distributional learning and noisy nets each fix a named flaw; Rainbow's ablations ranked prioritization and multi-step targets highest.
- The distributional evaluation operator is a -contraction in the maximal Wasserstein metric, while the control operator is not; C51 projects onto 51 atoms and minimizes cross-entropy, and QR-DQN learns quantiles.
- Open problems include data efficiency, loss of plasticity, scaling value-based RL to large networks, and a theory of why the stabilizers work.
Check yourself
In the interactive lesson these are scored with your confidence, and what you miss comes back for review.
What does holding the target network fixed for updates achieve?
- It decorrelates consecutive training samples
- It makes each phase an ordinary regression toward fixed targets, so the network is not chasing a target that moves with every step
- It removes the overestimation bias of the max
- It turns the semi-gradient into the true gradient of the squared Bellman error
Show the answer
B. It makes each phase an ordinary regression toward fixed targets, so the network is not chasing a target that moves with every step
With frozen, is a fixed label for each transition, and minimizing the loss is supervised regression: one step of approximate fitted Q-iteration per target period.
Which target does Double DQN use?
Show the answer
C.
The online network selects the action and the target network evaluates it. Selection and evaluation use different noise, so the selected action's estimate is no longer systematically the luckiest one.
Why does a dueling head subtract the mean advantage, ?
- To make the network's output nonnegative
- To reduce overestimation
- To normalize the rewards
- Without it, a constant could be shifted between and without changing , so the split would be arbitrary
Show the answer
D. Without it, a constant could be shifted between and without changing , so the split would be arbitrary
and give the same for every . Centering the advantages pins the decomposition down, so that really estimates the state's value, which every transition through the state then helps to learn.
In which metric is the distributional Bellman evaluation operator a -contraction?
- The maximal Wasserstein metric
- The Kullback–Leibler divergence
- The total variation distance
- It contracts only in expectation, not in distribution
Show the answer
A. The maximal Wasserstein metric
Scaling a random return by scales Wasserstein distances by , and adding a shared reward or mixing over next states does not increase them. KL and total variation do not shrink under scaling: two distinct point masses stay at total-variation distance 1, and infinite KL divergence, however close together they move. It is the control operator that fails to contract.
Further reading
- V. Mnih et al., "Human-level control through deep reinforcement learning," Nature 518, 529–533 (2015).
- H. van Hasselt, A. Guez & D. Silver, "Deep reinforcement learning with double Q-learning," AAAI (2016).
- M. Hessel et al., "Rainbow: Combining improvements in deep reinforcement learning," AAAI (2018).
- M. G. Bellemare, W. Dabney & R. Munos, "A distributional perspective on reinforcement learning," ICML (2017).
- M. G. Bellemare, W. Dabney & M. Rowland, Distributional Reinforcement Learning (MIT Press, 2023).