Deep Reinforcement Learning
Prerequisites
- MDPs — Bellman equations, value functions
- Q-Learning — tabular Q-learning, TD learning
- Neural Networks — backpropagation, gradient descent
🎯 Learning Objectives
- Explain why function approximation is necessary for large state spaces
- Describe the DQN architecture and its key innovations
- Understand Double DQN and Dueling DQN improvements
- Derive the REINFORCE policy gradient update rule
- Compare value-based, policy-based, and actor-critic methods
- Know the high-level ideas behind PPO and AlphaGo/AlphaZero
1. The Need for Function Approximation
📚 Curse of Dimensionality in RL
Tabular methods store one value for every state (or state-action pair). When the state space is very large or continuous, maintaining a table becomes infeasible. For example:
- Atari games: screen is 210 × 160 pixels × 3 colours ⇒ roughly 256100,800 possible frames
- Go: approximately 3361 ≈ 10170 board positions
- Robotics: continuous joint angles, velocities — infinite state space
The solution is function approximation: represent V(s), Q(s,a), or π(a|s) using a parameterised function (e.g., a neural network) with parameters θ. Instead of a lookup table, we learn a function:
Q(s, a; θ) ≈ Q*(s, a)
This allows generalisation across similar states — updating the value for one state automatically affects nearby states in the feature space.
💡 Types of Function Approximators
- Linear: Q(s,a;θ) = θT φ(s,a) where φ is a feature vector. Simple, stable, but limited representational power.
- Non-linear (neural networks): Much more expressive but can be unstable during training. Deep RL addresses this instability.
2. Deep Q-Network (DQN)
The Deep Q-Network (Mnih et al., 2015) was the breakthrough that showed neural networks could successfully approximate Q-values and achieve human-level performance on Atari 2600 games.
📚 DQN Architecture
A DQN uses a deep neural network to approximate Q*(s,a). The network takes a state s as input and outputs Q-values for all actions simultaneously:
Input: state s (e.g., stacked game frames) → CNN layers → FC layers → Output: Q(s, a1; θ), Q(s, a2; θ), …, Q(s, a|A|; θ)
Naively training a neural network with standard Q-learning update is unstable due to:
- Correlated samples: consecutive transitions (st, at, rt+1, st+1) are highly correlated.
- Non-stationary targets: the target r + γ maxa′ Q(s′, a′; θ) changes as θ changes.
2.1 Experience Replay
Store transitions (s, a, r, s′, done) in a replay buffer D of fixed capacity. During training, sample random mini-batches from D. This breaks correlations between consecutive samples and allows each transition to be reused multiple times.
2.2 Target Network
Maintain a separate target network with parameters θ− that are only updated periodically (e.g., every C steps: θ− ← θ). The loss function uses this frozen target:
DQN Loss Function
L(θ) = E(s,a,r,s′) ~ D [ (r + γ maxa′ Q(s′, a′; θ−) − Q(s, a; θ))2 ]
Where θ− is the frozen target network that stabilises training.
Algorithm: DQN with Experience Replay
Initialize replay buffer D with capacity N
Initialize Q-network with random weights θ
Initialize target network with weights θ⁻ ← θ
For episode = 1, 2, … do:
Initialise state s₁ (preprocess: stack last 4 frames)
For t = 1, 2, …, T do:
With probability ε select random action aₜ
Otherwise select aₜ = argmax_a Q(sₜ, a; θ)
Execute aₜ, observe reward rₜ₊₁ and next state sₜ₊₁
Store (sₜ, aₜ, rₜ₊₁, sₜ₊₁, done) in D
Sample random mini-batch of transitions from D
For each (sⱼ, aⱼ, rⱼ, s'ⱼ, doneⱼ):
If doneⱼ: yⱼ = rⱼ
Else: yⱼ = rⱼ + γ max_{a'} Q(s'ⱼ, a'; θ⁻)
Gradient descent on (yⱼ − Q(sⱼ, aⱼ; θ))² w.r.t. θ
Every C steps: θ⁻ ← θ
📝 Atari Performance
The original DQN paper achieved superhuman performance on 29 out of 49 Atari games using the same architecture and hyperparameters for every game. The input was raw pixel frames (4 stacked 84×84 grayscale images) and the only game-specific knowledge was the set of available actions.
3. Double DQN
📚 Overestimation Problem
Standard DQN uses maxa′ Q(s′, a′; θ−) for its target. The max operator introduces a positive bias because it both selects and evaluates the best action using the same values. If Q-values have noise, max will tend to pick the noisiest (overestimated) value.
Double DQN (van Hasselt et al., 2016) decouples action selection from action evaluation:
Double DQN Target
y = r + γ Q(s′, argmaxa′ Q(s′, a′; θ); θ−)
The online network (θ) selects the best action, but the target network (θ−) evaluates it. This reduces overestimation bias significantly.
💡 Implementation Detail
Double DQN requires only a one-line change to the standard DQN code — change how the target value is computed. The rest of the algorithm (experience replay, target network updates) remains identical.
4. Dueling DQN
Dueling DQN (Wang et al., 2016) modifies the network architecture rather than the learning algorithm.
📚 Advantage Function
The advantage function measures how much better an action is compared to the average:
Aπ(s, a) = Qπ(s, a) − Vπ(s)
By definition, ∑a π(a|s) Aπ(s, a) = 0. The advantage tells us the relative value of each action.
The dueling architecture has two streams after the shared convolutional layers:
- Value stream: V(s; θ, α) — a scalar estimating the state value
- Advantage stream: A(s, a; θ, β) — one value per action estimating the advantage
These are combined as:
Q(s, a; θ, α, β) = V(s; θ, α) + A(s, a; θ, β) − (1/|A|) ∑a′ A(s, a′; θ, β)
💡 Why Dueling Helps
In many states, it doesn’t matter which action you take — the state value dominates. Dueling architecture can learn V(s) independent of A, making it more efficient when many actions have similar Q-values. This is especially useful in states where the choice of action is less important than recognising you are in a good or bad state.
5. Policy Gradient Methods
Instead of learning Q-values and deriving a policy, policy gradient methods directly parameterise the policy π(a|s; θ) and optimise it by gradient ascent on the expected return.
📚 Policy Gradient Objective
The objective is to maximise the expected return:
J(θ) = Eπθ[G0] = Eπθ[∑t=0∞ γt Rt+1]
Policy Gradient Theorem
The gradient of the objective can be written (without requiring the derivative of the state distribution) as:
∇θ J(θ) = Eπθ[∑t=0T ∇θ log π(At|St; θ) · Gt]
Where Gt = ∑k=0∞ γk Rt+k+1 is the return from time step t.
5.1 REINFORCE Algorithm
REINFORCE (Williams, 1992) is the simplest policy gradient method. It uses complete episode returns as the estimate of Gt.
Algorithm: REINFORCE (Monte Carlo Policy Gradient)
Initialize policy network π(a|s; θ) with random weights
For each episode:
Generate trajectory τ = (S₀, A₀, R₁, S₁, A₁, R₂, …, S_T)
by following π(·|·; θ)
For t = 0, 1, …, T−1:
Compute return: Gₜ = ∑_{k=0}^{T-t-1} γᵏ R_{t+k+1}
Update: θ ← θ + α ∑_{t=0}^{T-1} ∇_θ log π(Aₜ|Sₜ; θ) · Gₜ
5.2 Baseline Subtraction
REINFORCE has high variance because Gt can vary enormously between episodes. A common variance reduction technique is to subtract a baseline b(s) from the return:
∇θ J(θ) = Eπθ[∑t ∇θ log π(At|St; θ) · (Gt − b(St))]
The optimal baseline is approximately Vπ(s). Subtracting it does not change the expected gradient (unbiased) but greatly reduces variance. The quantity Gt − V(St) is an estimate of the advantage A(St, At).
⚠ REINFORCE Limitations
- Requires complete episodes (Monte Carlo)
- High variance even with a baseline
- Slow convergence — sample-inefficient
- Can converge to local optima (policy space is generally non-convex)
6. Actor-Critic Methods
Actor-Critic methods combine the benefits of both value-based and policy-based approaches.
📚 Actor-Critic Architecture
- Actor: a parameterised policy π(a|s; θ) that selects actions
- Critic: a value function V(s; w) (or Q(s,a; w)) that evaluates how good the actor’s actions are
The critic provides a low-variance baseline for the policy gradient, replacing the high-variance Monte Carlo return with a bootstrapped TD estimate.
6.1 Advantage Actor-Critic (A2C)
The actor update uses the advantage estimate δt = rt+1 + γ V(st+1; w) − V(st; w) (the TD error) as an estimate of A(s,a):
- Actor update: θ ← θ + αθ δt ∇θ log π(at|st; θ)
- Critic update: w ← w + αw δt ∇w V(st; w)
6.2 Asynchronous Advantage Actor-Critic (A3C)
A3C (Mnih et al., 2016) runs multiple agents in parallel on separate copies of the environment. Each agent computes gradients locally and asynchronously updates a shared set of parameters. This provides:
- Decorrelated experience: different agents explore different parts of the state space simultaneously
- No replay buffer needed: the parallelism itself provides diverse training data
- Faster wall-clock training: leverages multi-core CPUs
| Aspect | DQN (Value-Based) | REINFORCE (Policy-Based) | Actor-Critic |
|---|---|---|---|
| Learns | Q-function | Policy directly | Both policy & value |
| Action space | Discrete only | Discrete or continuous | Discrete or continuous |
| Variance | Low | High | Medium (reduced by critic) |
| Bias | Biased (bootstrap) | Unbiased | Biased (bootstrap) |
| Sample efficiency | Good (replay buffer) | Poor | Moderate |
7. Proximal Policy Optimization (PPO)
PPO (Schulman et al., 2017) has become one of the most widely-used deep RL algorithms due to its simplicity and reliability. It is the algorithm behind much of the training for large language models via RLHF (Reinforcement Learning from Human Feedback).
📚 Trust Region Idea
Large policy updates can be catastrophic — a single bad update can destroy a well-performing policy. PPO constrains the policy update so that the new policy does not move too far from the old one.
Define the probability ratio:
rt(θ) = π(at|st; θ) / π(at|st; θold)
PPO Clipped Objective
LCLIP(θ) = Et[min(rt(θ) · Ât, clip(rt(θ), 1−ε, 1+ε) · Ât)]
Where ε is a small hyperparameter (typically 0.1–0.2) and Ât is the estimated advantage. The clip prevents the ratio from moving outside [1−ε, 1+ε], ensuring small policy changes.
💡 Why PPO Works Well
- Simple to implement (no second-order optimisation like TRPO)
- Robust to hyperparameter choices
- Works with both discrete and continuous action spaces
- Supports parallel data collection
- Used in ChatGPT-style RLHF pipelines
8. AlphaGo and AlphaZero
DeepMind’s AlphaGo (2016) and AlphaZero (2017) represent landmark achievements combining deep RL with search.
📚 AlphaGo Components
- Supervised learning (SL) policy network: trained on expert human moves to predict the next move given a board position
- RL policy network: fine-tuned the SL policy via self-play using REINFORCE
- Value network: trained to predict game outcomes from self-play positions
- Monte Carlo Tree Search (MCTS): used the neural networks to guide search during actual play
8.1 AlphaZero: Learning from Scratch
AlphaZero simplified AlphaGo by removing the supervised learning phase entirely:
- Single neural network fθ(s) = (p, v) outputs both a policy vector p (move probabilities) and a scalar value v (win probability)
- Trained entirely via self-play reinforcement learning
- Uses MCTS guided by the neural network for action selection during self-play
- Achieved superhuman performance in Go, Chess, and Shogi — all with the same algorithm
📝 AlphaZero Timeline
Starting from random play, AlphaZero surpassed AlphaGo (which had beaten world champion Lee Sedol) after just 3 days of self-play training. In Chess, it exceeded the strength of Stockfish (strongest traditional chess engine) after only 4 hours of self-play.
9. Applications of Deep RL
| Domain | Application | Key Algorithm |
|---|---|---|
| Game Playing | Atari, Go, StarCraft, Dota 2 | DQN, AlphaZero, PPO |
| Robotics | Manipulation, locomotion, dexterous hands | PPO, SAC, DDPG |
| Resource Management | Data centre cooling (Google), chip placement | PPO, custom architectures |
| NLP / LLMs | RLHF for ChatGPT, instruction following | PPO |
| Autonomous Driving | Lane-keeping, decision-making at intersections | DQN variants, A3C |
| Finance | Portfolio optimisation, algorithmic trading | DQN, Policy Gradient |
| Healthcare | Treatment planning, drug dosing | Batch RL methods |
⚠ Challenges in Deep RL
- Sample inefficiency: millions of interactions often required
- Reward design: poorly shaped rewards lead to unintended behaviour
- Stability: training can be highly sensitive to hyperparameters
- Sim-to-real gap: policies trained in simulation may not transfer to real world
- Safety: exploration in real-world systems can be dangerous
Summary
- Function approximation enables RL in large/continuous state spaces by replacing tables with parameterised functions (neural networks).
- DQN stabilised neural Q-learning through experience replay and target networks.
- Double DQN reduces overestimation bias; Dueling DQN separates state value from action advantage.
- Policy gradient methods (REINFORCE) directly optimise the policy; baseline subtraction reduces variance.
- Actor-Critic methods (A2C, A3C) combine policy and value learning for lower variance.
- PPO uses a clipped surrogate objective for stable, reliable training.
- AlphaGo/AlphaZero combined neural networks with MCTS to master board games from self-play.
- Deep RL applications span games, robotics, NLP (RLHF), resource management, and more.