What You'll Learn
- Explain why naive Q-learning with neural networks fails
- Describe how experience replay breaks correlation
- Explain target networks and why they stabilize training
- Implement DQN from scratch
- Understand frame stacking and preprocessing for visual inputs
In 2013, a paper from DeepMind shook the AI world: a single algorithm, with the same hyperparameters, learned to play seven different Atari games from raw pixels, outperforming human experts on three of them. The expanded 2015 Nature version scaled the same recipe to 49 games, many at superhuman level.
That algorithm was DQN, and it showed that deep learning and reinforcement learning could work together.
The Breakthrough
A Q-learning agent that uses a deep neural network to approximate the Q-function, stabilized by two key innovations: experience replay and target networks.
The deadly triad (off-policy + function approximation + bootstrapping) seemed fatal. DQN survives by breaking two correlations:
- Experience replay breaks the correlation between consecutive samples
- Target networks break the correlation between Q-values and their targets
Chapter Overview
This chapter covers the complete DQN algorithm, piece by piece:
The DQN Architecture
CNNs for processing visual observations
Experience Replay
Breaking correlations through random sampling
Target Networks
Stabilizing training with frozen targets
Putting It Together
The complete DQN algorithm
The Core Idea
DQN is fundamentally just Q-learning with a neural network:
But instead of a table, we have:
- A neural network parameterized by weights
- A replay buffer storing past experiences
- A target network with frozen weights
The same machinery works far beyond Atari. On CartPole—our running example—a DQN with a two-layer fully connected network learns to balance the pole from four state variables; on Atari, only the network (a CNN) and the preprocessing change.
The DQN loss function:
where is the replay buffer and are the target network parameters.
Prerequisites
This chapter builds on:
- Q-Learning for the core algorithm
- Function Approximation for why we need neural networks and the challenges they introduce
Key Questions We’ll Answer
- Why does naive neural network Q-learning fail?
- How does storing and replaying experiences help?
- Why do we need a separate target network?
- What preprocessing is needed for visual inputs?
Check Your Understanding
- DQN = Q-learning + neural network + two stabilizersThe update rule is unchanged; experience replay and target networks make it trainable.
- Experience replay decorrelates and reuses dataRandom sampling from a buffer approximates i.i.d. training and lets each transition teach the network many times.
- Target networks freeze the regression targetBetween periodic syncs, training is supervised regression toward fixed targets instead of chasing a moving one.
- Frame stacking restores the Markov propertyFour stacked frames give the network motion information a single image lacks.
- One recipe, 49 gamesIdentical architecture and hyperparameters reached superhuman play on 29 of 49 Atari games—the generality mattered as much as the scores.
Primary Sources
- Mnih et al. (2013), “Playing Atari with Deep Reinforcement Learning,” NIPS Deep Learning Workshop — the original 7-game DQN paper. arXiv:1312.5602
- Mnih et al. (2015), “Human-level control through deep reinforcement learning,” Nature 518 — the 49-game version with target networks, the standard DQN reference. Nature page