ML Systems Lab Open interactive version →
Intermediate 50 min read dqnexperience replaytarget networkdouble dqndueling

Deep Q-Networks

Experience replay, target network, Double DQN, Dueling, Prioritized Replay, failure modes

Consider Atari Breakout. The state is 4 consecutive 84×84 game frames — stacked to capture motion. The action space has 3 choices: left, right, no-op. The reward is +1 per brick broken. The state space is effectively infinite: no two sequences of frames are likely to be identical. A tabular Q-table for every possible pixel configuration is physically impossible. DQN replaces the Q-table with a neural network Q(s, a; θ) that takes raw pixels as input and outputs Q-values for all three actions simultaneously.

The problem is that applying Q-learning naively to a neural network is deeply unstable. Consecutive game frames are highly correlated — if the agent is in the top-left of the screen, the next 100 transitions are all from the top-left, and gradient updates overfit to that region while forgetting everything else. This violates the IID assumption that SGD requires: gradient estimates should be drawn from the full training distribution, not a narrow slice of recent experience. DQN's first fix is experience replay: store every transition (s_t, a_t, r_t, s_{t+1}) in a replay buffer of up to 1M entries, then sample random mini-batches. Temporal correlation breaks; transitions are reused multiple times.

The second instability is that the bootstrap target R + γ max_{a'} Q_θ(s', a') depends on the same θ being updated. As θ shifts, the target shifts — you are chasing a moving target, and the feedback loop amplifies Q-values until they diverge. DQN's second fix is the target network: maintain a separate θ^- that is copied from θ only every 10,000 steps. The target is computed using θ^-, which is frozen between updates. The feedback loop breaks.

Double DQN further improves on this. The DQN target uses the same θ^- to both select the best action and evaluate it, which produces a systematic upward bias — the max over noisy estimates is always higher than the estimate of the true max. Double DQN decouples these: use θ to select the action (argmax_a Q_θ(s', a')), then use θ^- to evaluate it. Dueling DQN goes further and decomposes Q(s, a) = V(s) + A(s, a), learning state value and action advantage separately.

NOT this: DQN is the standard deep RL algorithm. DQN only works for discrete action spaces. For continuous control — robot joint torques, motor commands — DQN's argmax over actions is infeasible. Use actor-critic methods (SAC, TD3, PPO) when actions are real-valued.

Key points

Takeaway

DQN makes Q-learning stable for neural networks with two fixes: experience replay breaks the temporal correlation that causes gradient overfitting, and a target network freezes the bootstrap target to prevent the moving-target feedback loop that amplifies Q-values into divergence.

Recap

Check your understanding

Q1. Vanilla DQN adds two specific mechanisms on top of neural-network Q-learning to make training stable. Which two are they?

Q2. What is the difference between Dueling DQN and standard DQN architecturally, and in what types of states does Dueling provide the largest benefit?

Q3. You are applying DQN to a robotic manipulation task where the reward is 1 only when the robot successfully places an object and 0 otherwise, with episodes of 200 steps. After 10M steps, the policy never achieves reward > 0. What is happening and what are your next steps?

Try it interactively

ML Systems Lab is a free interview-prep platform for ML engineers — work through the full interactive module, quizzes, and drills.

Open ML Systems Lab →