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 QQ-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 (st,st+1s_t, s_{t+1}).
  2. Non-stationary data distribution (Policy changes as QQ updates).
  3. Chasing a Moving Target: Updating θ\theta changes both current Q(s,a;θ)Q(s, a; \theta) AND target r+γmax⁡a′Q(s′,a′;θ)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 Li(θi)\mathcal{L}_i(\theta_i) over random mini-batch U(D)U(D):

Li(θi)=E(s,a,r,s′)∼U(D)[(r+γmax⁡a′Q(s′,a′;θi−)⏟Target (Frozen Weights θ−)−Q(s,a;θi)⏟Prediction (Active Weights θ))2]\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 CC 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