Reinforcement Learning

Deep Q-Networks & Replay Buffers

Scaling Q-Learning to high-dimensional continuous state spaces using neural network function approximators, Experience Replay, and Target Networks.

🔴 advanced5 min readrl
Deep Q-Networks (DQN - Mnih et al., 2015 / DeepMind) revolutionized Reinforcement Learning by using deep convolutional neural networks to approximate Q(s, a; θ) directly from raw Atari screen pixels. Combining non-linear neural network function approximators with Q-learning causes severe divergence. DQN stabilized training through two key innovations: Experience Replay (breaking temporal correlation between sequential training samples) and Target Networks Q(s, a; θ^-) (freezing target weights to prevent moving target feedback instabilities).

The DQN Architecture

  Raw Input Screen (84x84x4 pixels) ──► [ CNN Layers + FFN ] ──► Vector of Q-Values [ Q(s, a1), Q(s, a2), ..., Q(s, aK) ]

A single forward pass computes $Q$-values for all discrete actions simultaneously!

The Two Core Stabilizing Innovations

When combining Q-Learning with Deep Neural Networks, 3 sources of instability arise:

  1. Correlations between sequential observations ($s_t, s_{t+1}$).
  2. Non-stationary data distribution (Policy changes as $Q$ updates).
  3. Chasing a Moving Target: Updating $\theta$ changes both current $Q(s, a; \theta)$ AND target $r + \gamma \max_{a'} Q(s', a'; \theta)$.
                            DQN STABILIZATION TRIAD
┌───────────────────────────────────────┬───────────────────────────────────────┐
│ 1. EXPERIENCE REPLAY BUFFER (D)       │ 2. SEPARATE TARGET NETWORK (θ^-)      │
├───────────────────────────────────────┼───────────────────────────────────────┤
│ Store 1M transitions (s, a, r, s').   │ Maintain periodic copy of weights θ^-.│
│ Sample random mini-batches for SGD.   │ Freeze θ^- for C steps (e.g. C=10k).  │
│ Breaks temporal correlation -> i.i.d.! │ Eliminates moving target feedback!    │
└───────────────────────────────────────┴───────────────────────────────────────┘

Loss Function & Target Update

DQN minimizes Loss $\mathcal{L}_i(\theta_i)$ over random mini-batch $U(D)$:

$$\mathcal{L}i(\theta_i) = \mathbb{E}{(s, a, r, s') \sim U(D)} \left[ \left( \underbrace{r + \gamma \max_{a'} Q(s', a'; \theta_i^-)}{\text{Target (Frozen Weights } \theta^-)} - \underbrace{Q(s, a; \theta_i)}{\text{Prediction (Active Weights } \theta)} \right)^2 \right]$$

Every $C$ steps, copy active weights to target network: $\theta^- \leftarrow \theta$.

DQN Extension Family

Say this out loud

"DQN scales Q-learning to high-dimensional pixel inputs using deep CNNs. Training is stabilized using Experience Replay to break sample autocorrelation and a frozen Target Network Q(s,a; θ^-) to eliminate the moving target problem. Double DQN further decouples action selection from evaluation to eliminate overestimation bias."

Follow-ups to expect

Check yourself

Question 1 of 3

Why does training a Deep Q-Network directly on sequential environment steps (s_t, a_t, r_t, s_{t+1}) without a Replay Buffer cause training instability and divergence?

More in Reinforcement Learning

See all →
Value-Based vs Policy-Based Methods5 minMulti-Armed Bandits4 minProximal Policy Optimization5 min