Deep Q-Learning and Double DQN

Deep Q-Learning and Double DQN #

Tabular Q-learning gives each state-action pair its own entry. A Deep Q-Network (DQN) replaces the table with shared neural-network weights. For a state such as a stack of game frames, one forward pass can output a Q-value for every discrete action.

Course Content covered in this module:

  • Deep Q learning: DQN architecture, target networks, replay buffer
  • Instability and fixes
  • Extensions of DQN: Double DQN

1. From Q-Learning to a Q-Network #

The online network predicts action values, not action probabilities. An epsilon-greedy behaviour policy chooses an action; the learning target still looks towards a greedy next action. That distinction makes DQN off-policy. A frame stack can reveal motion that a single image cannot, while convolutions learn useful visual features rather than relying on a hand-written game representation.

2. Why Replay and Target Networks Help ☆ #

ProblemMechanismEffect
Consecutive transitions are strongly correlatedStore transitions in a replay buffer and sample random minibatchesReduces temporal correlation within batches and allows experience reuse
Updating a shared network can change both prediction and targetCompute next-state values with a separate target networkHolds the target for a given transition fixed between synchronisations

Replay stores states, actions, rewards, successor states and termination flags. A finite buffer typically discards its oldest transitions as new ones arrive. Sampling old experience means the current learner can train on actions from earlier behaviour policies; replay does not make the algorithm on-policy.

3. The DQN Training Target ☆ #

Let the online weights be \( \theta \) and the target weights be \( \theta^- \) . With \( d=1 \) on true termination and zero otherwise:

\[ y=r+\gamma(1-d)\max_{a'} Q(s',a';\theta^-),\qquad L(\theta)=\frac{1}{2}\big[y-Q(s,a;\theta)\big]^2. \]

Update the online weights using the minibatch loss, treating the targets as constants. In a hard-update implementation, copy the online weights into the target network every \( C \) steps. The target network does not receive gradients. A terminal transition uses just its observed reward; a time limit that truncates a continuing trajectory is not automatically a terminal state.

flowchart TD
    E["Environment transitions"] --> R["Replay minibatch"]
    R --> O["Online prediction"]
    R --> T["Frozen target"]
    O --> L["TD loss"]
    T --> L
    L --> U["Update online weights"]
    U --> |"Periodic copy"| T
    style R fill:#90CAF9,stroke:#1E88E5
    style O fill:#E1F5FE,stroke:#1E88E5
    style T fill:#E1F5FE,stroke:#1E88E5
    style U fill:#90CAF9,stroke:#1E88E5

4. Double DQN: Select Then Evaluate ☆ #

Taking the maximum over noisy estimates can favour actions whose estimates happen to be too high. Standard DQN both selects and evaluates the next action using target-network values. Double DQN uses the online network to select and the target network to evaluate:

\[ a^*=\arg\max_{a'}Q(s',a';\theta),\qquad y_{\mathrm{DDQN}}=r+\gamma(1-d)Q(s',a^*;\theta^-). \]

Suppose the online values for Left and Right are 8 and 7, and the corresponding target values are 5 and 9. With reward 2 and discount 0.9 on a nonterminal transition, standard DQN uses 9 and produces 10.1. Double DQN selects Left using 8, evaluates it using 5 and produces 6.5. The estimates need not disagree on every example; Double DQN reduces a systematic source of overestimation rather than guaranteeing that every estimate is smaller.

Common Mistakes #

  • A replay buffer stores transitions, not copies of network weights.
  • The online and target networks are not trained independently by backpropagation.
  • The numerical target is not the updated Q-value. Neural-network training updates weights; it does not directly overwrite a table entry.
  • Double DQN changes the target calculation. It is not the same as a duelling network, which changes the architecture.

Practice Questions #

  1. If a transition is terminal, what target is used by each algorithm?
  2. Recalculate the worked example if the online values become 7 and 8.
  3. Explain why removing replay and removing the target network introduce different problems.

References #

  • Consolidated DRL slides, PDF pp. 296–323; recordings 11–12.

Home | Deep Reinforcement Learning