Chapter 122
📝Draft

Deep Q-Networks

The breakthrough that made deep RL work

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

📖Deep Q-Network (DQN)

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:

  1. Experience replay breaks the correlation between consecutive samples
  2. Target networks break the correlation between Q-values and their targets

Chapter Overview

This chapter covers the complete DQN algorithm, piece by piece:

The Core Idea

DQN is fundamentally just Q-learning with a neural network:

Q(s,a)Q(s,a)+α[r+γmaxaQ(s,a)Q(s,a)]Q(s, a) \leftarrow Q(s, a) + \alpha \left[ r + \gamma \max_{a'} Q(s', a') - Q(s, a) \right]

But instead of a table, we have:

  • A neural network Q(s,a;θ)Q(s, a; \theta) parameterized by weights θ\theta
  • A replay buffer storing past experiences
  • A target network Q(s,a;θ)Q(s, a; \theta^-) 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.

Mathematical Details

The DQN loss function:

L(θ)=E(s,a,r,s)D[(r+γmaxaQ(s,a;θ)Q(s,a;θ))2]L(\theta) = \mathbb{E}_{(s,a,r,s') \sim \mathcal{D}} \left[ \left( r + \gamma \max_{a'} Q(s', a'; \theta^-) - Q(s, a; \theta) \right)^2 \right]

where D\mathcal{D} is the replay buffer and θ\theta^- are the target network parameters.

Prerequisites

This chapter builds on:

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

Check your understanding
1. Why does naive Q-learning with a neural network tend to fail without DQN's additions?
2. What does experience replay guarantee?
3. Why does DQN use a separate target network instead of computing targets with the online network?
4. Why does DQN stack 4 consecutive frames as its network input on Atari?
5. Which statement about DQN's Atari results is accurate?
  1. DQN = Q-learning + neural network + two stabilizers
    The update rule is unchanged; experience replay and target networks make it trainable.
  2. Experience replay decorrelates and reuses data
    Random sampling from a buffer approximates i.i.d. training and lets each transition teach the network many times.
  3. Target networks freeze the regression target
    Between periodic syncs, training is supervised regression toward fixed targets instead of chasing a moving one.
  4. Frame stacking restores the Markov property
    Four stacked frames give the network motion information a single image lacks.
  5. One recipe, 49 games
    Identical 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
Next ChapterDQN Improvements