TL;DR
Mnih and colleagues trained one convolutional network to play seven Atari 2600 games. The input was raw screen pixels, the training signal was only the game score, and the network and learning rule were identical for every game. Only the frame-skip differed, 3 instead of 4 for Space Invaders. The method combined Q-learning with a replay memory of past experience. It beat every earlier learned approach on six of the seven games and beat a human expert on three.
Where you'll see it: the paper that made deep Q-learning on raw pixels a standard baseline. Later work on Atari, game-playing agents and value-based deep RL all measure themselves against it.
The problem
Before this paper, learning to act from high-dimensional sensory input, such as an image of the screen, was hard for reinforcement learning. The usual recipe was to hand-design features of the screen and fit a linear value function on top of them. The features carried most of the prior knowledge, and the learning was a small part of the system.
Deep networks could learn features from raw inputs, but three properties of reinforcement learning made them difficult to combine with deep learning:
- Sparse, delayed, noisy reward. Deep learning usually has a direct label for each input. An action's effect on the score can show up thousands of steps later.
- Correlated data. Consecutive frames look almost the same, so the samples are not independent, which standard stochastic gradient training assumes.
- Moving data distribution. As the agent improves, the states it visits change, so the training data are not drawn from a fixed distribution.
There was also a known stability problem. Combining Q-learning with a nonlinear function approximator, such as a neural network, could make the Q-values diverge. Most of the field had therefore moved to linear approximators with convergence guarantees.
A single screen is also not a full description of the game state. Two screens can look the same while the ball moves in opposite directions. The paper handles this by giving the network a short stack of recent frames.
Key idea
The paper's answer has two parts that make a nonlinear Q-function trainable with cheap stochastic updates:
- Experience replay. Store every transition the agent sees in a large buffer. Each training step samples a random minibatch from the buffer instead of learning only from the newest step. Random sampling breaks the correlations between consecutive frames.
- One output per action. The network takes the state and outputs one Q-value per legal action, so all action values come from a single forward pass.
Together with frame preprocessing, frame skipping and reward clipping, these choices made deep Q-learning run end to end on raw pixels.
flowchart LR E[Atari emulator] -->|frame x_t and reward r_t| P[Preprocess: grayscale, crop, stack 4 frames] P --> Q[Convolutional Q-network] Q -->|epsilon-greedy action| E E -->|transition e_t| D[(Replay memory, last 1M frames)] D -->|random minibatch of 32| U[Q-learning update] U --> Q
The method
Setting up the problem
The agent sees screen images and picks actions from the legal game actions, a set of size that is between 4 and 18 across the games. The paper treats the history as the state, which makes the problem a large but finite Markov decision process. Each distinct history is a different state, so the standard RL machinery applies, as long as the function approximator can generalise across histories.
The discounted return is
where is the discount factor and is the step at which the game ends. The optimal action-value function is the largest expected return from state after taking action . It satisfies the Bellman equation (see Bellman Equation):
The loss
The network is trained to match a target that is computed from the Bellman equation. For iteration the loss is
Replacing the expectations with single samples and updating after every step gives Q-learning with a neural network (see Q-Learning). The update is model-free, because it uses samples from the emulator and never builds a model of it. It is off-policy, because it learns the greedy policy while the behaviour follows an -greedy policy.
The paper's text and its Algorithm 1 disagree here. The text above, with held fixed while optimising , describes a target from the previous iteration's weights. Algorithm 1 computes the target for each sampled transition with the current weights , and it does not keep a separate frozen copy of the network. The 2015 Nature paper added a separate target network, which is why many later descriptions of DQN include one.
Experience replay
Each step the agent stores a transition
in a memory . The memory keeps the most recent one million frames' worth of experience (the paper's wording) and overwrites the oldest. Each update draws a minibatch of 32 transitions uniformly at random from . The paper gives three reasons for this design:
- Data efficiency. Each stored transition can be used in many updates.
- Decorrelation. Learning from consecutive frames is unstable because neighbouring samples are nearly identical. Random minibatches reduce the variance of the updates.
- No feedback loop. If the agent learned only from its latest experience, the policy would drive the data, and the data would drive the policy, which can lock the agent into a bad strategy. A replay buffer spreads the training data over a longer history.
Uniform sampling is a simplification. The paper notes that a better sampling rule might favour transitions the agent can learn the most from, which is the idea behind prioritised replay.
Preprocessing and the network
A raw Atari frame is pixels with a 128-colour palette. The preprocessing converts each frame to grayscale, downsamples it to , and crops an region that contains the playing area. The function stacks the last four preprocessed frames, so the network input is .
The network has three hidden layers and a linear output:
| Layer | Filters or units | Kernel and stride | Output shape |
|---|---|---|---|
| Input | (4 stacked frames) | ||
| Conv 1 | 16 | , stride 4, ReLU | |
| Conv 2 | 32 | , stride 2, ReLU | |
| Fully connected | 256 | ReLU | 256 |
| Output | linear | Q-values |
The output sizes come from the standard formula for valid convolutions, . The first layer gives , and the second gives .
Pong has legal actions. Count the weights and biases layer by layer.
- Conv 1: each filter has weights, so weights, plus 16 biases. Total .
- Conv 2: each filter has weights, so weights, plus 32 biases. Total .
- Fully connected: the flattened input has values. That gives weights, plus 256 biases. Total .
- Output: weights, plus 6 biases. Total .
- Sum: .
Interpretation: about 0.68 million parameters, and almost all of them sit in the single fully connected layer. The convolutional layers are small. That is a common pattern for pixel-based networks, and it means the cost of the model is set by the layer that sees the flattened feature map.
Training regime
The same settings were used for all seven games:
- Frame skipping. The agent chooses an action every -th frame and repeats it on the frames in between. The paper uses , and for Space Invaders, where makes the lasers blink out of view.
- Reward clipping. Every positive reward becomes and every negative reward becomes , and zero stays zero. Game scores differ in scale from game to game, so clipping lets one learning rate work everywhere. The cost is that the agent cannot tell a big reward from a small one. Clipping is applied during training only; the agents are evaluated on the unmodified games.
- Optimiser. RMSProp with minibatches of 32.
- Exploration. is annealed linearly from 1 to 0.1 over the first million frames and then held at 0.1. Evaluation uses .
- Length. Training ran for 10 million frames with a replay memory of one million frames.
- epsilon
Suppose one sampled transition has reward , discount , and the network's best Q-value for the next state is . The current prediction for the taken action is .
- Target: .
- Error: .
- Squared loss: .
- Gradient step: the update moves up, toward , by an amount set by the learning rate.
If the transition is terminal, the target is only the reward: . The error becomes , and the update pushes the prediction down.
Interpretation: the target mixes one real reward with the network's own estimate of the future. That mix is what lets learning chain one-step updates into long-horizon values.
Results
The paper compares DQN with two hand-engineered linear methods, Sarsa and Contingency, with an evolutionary method (HNeat) that uses a hand-built object detector, and with a random policy and a human expert. For the learned methods the table reports the average score of an -greedy policy with over a fixed number of steps, the protocol of the Arcade Learning Environment papers the authors follow. The human row is the median score of an expert after about two hours of play. The HNeat rows are different: HNeat policies are deterministic and were evaluated only on their single highest-scoring episode, so they are best-episode numbers, not averages. The paper's caption puts HNeat in a lower table of best episodes, while the layout here merges everything into one table.
| Game | Random | Sarsa | Contingency | DQN | Human | HNeat Best | HNeat Pixel |
|---|---|---|---|---|---|---|---|
| Beam Rider | 354 | 996 | 1743 | 4092 | 7456 | 3616 | 1332 |
| Breakout | 1.2 | 5.2 | 6 | 168 | 31 | 52 | 4 |
| Enduro | 0 | 129 | 159 | 470 | 368 | 106 | 91 |
| Pong | -20.4 | -19 | -17 | 20 | -3 | 19 | -16 |
| Q*bert | 157 | 614 | 960 | 1952 | 18900 | 1800 | 1325 |
| Seaquest | 110 | 665 | 723 | 1705 | 28010 | 920 | 800 |
| Space Invaders | 179 | 271 | 268 | 581 | 3690 | 1720 | 1145 |
Reading the table:
- Text versus abstract. Section 5.3 says DQN beats "the other learning methods" on all seven games, while the abstract and conclusion say six of seven. Both are consistent with the table: the first counts only Sarsa and Contingency, and the second also counts HNeat.
- Against the linear methods, DQN wins on all seven games, usually by a wide margin. On Breakout it scores 168 against 6 for Contingency, and on Seaquest 1705 against 723.
- Against HNeat Best, DQN wins six of seven games. The exception is Space Invaders, where HNeat Best scores 1720 against DQN's 581. HNeat Best used a hand-engineered object detector, and the paper notes that its policies exploit deterministic sequences, so they may not generalise to random perturbations. DQN's average also beats HNeat's best episode on the other six games, and DQN's own best episode (DQN Best row, 1075 on Space Invaders) does not close the gap either.
- Against a human expert, DQN is above the human expert on Breakout (168 against 31), Enduro (470 against 368) and Pong (20 against -3). On Beam Rider it reaches about 55 percent of the human score (4092 out of 7456). On Q*bert, Seaquest and Space Invaders it is far from human level, which the paper attributes to the need for strategies that play out over long time spans.
The paper also reports a "DQN Best" row (5184, 225, 661, 21, 4500, 1740 and 1075 for the seven games in table order), the single best episode, for comparison with HNeat. These are higher than the averages on every game, but they are not the main claim, because a single episode does not measure reliability.
Two other diagnostics support the training method. The average episode reward during training is very noisy, because small weight changes can shift which states the policy visits. The average predicted maximum Q-value over a fixed set of states rises smoothly, so the paper uses it to show that learning is progressing. A third figure traces the predicted value over a 30-frame segment of Seaquest. The value jumps when an enemy appears, peaks as a torpedo is about to hit, and falls back when the enemy leaves.
Why it mattered
The paper showed that one learning procedure, with one architecture and one set of hyperparameters, could learn control policies from raw pixels for several games. Before it, end-to-end learning from images in RL had not been shown on a suite of games like this.
Its main contributions became standard parts of deep RL:
- Replay memory with minibatch updates became a default way to train off-policy value networks.
- Atari became a standard benchmark, and later work reported results on the same games under the same protocol.
- The 2015 Nature paper extended the approach to 49 games, added a separate target network, and reported results against a wider set of baselines.
Follow-up work targeted the weaknesses this paper left open. Double Q-learning addressed overestimation of Q-values. Prioritised replay addressed the uniform sampling that the paper flags as a limitation. Dueling architectures separated the value of a state from the advantage of each action. Rainbow combined several of these improvements in one agent. None of them would be easy to motivate without the baseline this paper set.
Reading guide
Read the paper in this order, and use the listed lessons for the prerequisites each section needs:
- Section 1, Introduction. Needs Reinforcement Learning for the idea of an agent learning from reward, and Deep Q-Network for the context of value-based deep RL.
- Section 2, Background. Needs Markov Decision Process for states, actions, rewards and discounting, Bellman Equation for the recursive definition of the optimal value, and Q-Learning for the update rule.
- Section 3, Related Work. Needs Temporal-Difference Learning for the TD-Gammon method, and Stochastic Gradient Descent for why the paper prefers minibatch updates.
- Section 4, Deep Reinforcement Learning. Needs Experience Replay for the replay memory, Convolutional Neural Network for the convolution layers, Feedforward Neural Network for the fully connected head, and Rectified Linear Unit (ReLU) for the rectifier activations. Read the algorithm box and the architecture subsection together.
- Section 5, Experiments. Needs Reinforcement Learning for the -greedy evaluation protocol. Read the training-stability and value-function subsections before the results table.
- Section 6, Conclusion. Has no new prerequisites.
Check yourself
QuestionRecall: what does the network take as input, and what does it output?Show answer
The input is the stacked preprocessed frames, an array made from the last four frames. The output is one Q-value per legal action, computed in a single forward pass. Putting the actions at the output, rather than feeding each action in as an input, is what lets the agent score every action with one pass.
QuestionComputation: an input of goes through a convolution with filters, stride 4 and no padding. What is the output spatial size?Show answer
The output size is . With 16 filters, the output is .
QuestionWhy: why does sampling a random minibatch from the replay memory help, instead of training on the newest transition?Show answer
Consecutive transitions are nearly identical, so training on them in order gives correlated, high-variance updates. Random sampling breaks those correlations. The buffer also lets each transition be used in many updates, which makes the method data-efficient. Finally, learning only from the latest experience can create a feedback loop in which the policy shapes the data that shapes the policy, and a buffer spreads the data over a longer history.
QuestionApplied: a new game gives +1000 for each coin and +1 for each enemy defeated. What does the agent see after reward clipping, and what is lost?Show answer
Both rewards become , because clipping maps every positive reward to . The agent cannot tell a coin from an enemy, so it has no signal that coins are worth a thousand times more. The paper accepts this loss to keep one learning rate across games. If the game's reward scale matters for the strategy, clipping is the wrong choice, and you would need a different scaling or a tuned learning rate.
Sources
- Mnih et al. (2013), Playing Atari with Deep Reinforcement Learning: arxiv.org/abs/1312.5602
- Mnih et al. (2015), Human-level control through deep reinforcement learning, Nature: doi.org/10.1038/nature14236