Compute Double DQN targets

Why it matters Double Q targets are standard in every value-based RL agent since 2015.

Double DQN picks the next action with the online network but evaluates it with the target network, reducing overestimation.

Write double_dqn_target(r, done, q_online_next, q_target_next, gamma). Arrays are batched: r (B,), done (B,), q tables (B, A). Return r + gamma * (1 - done) * q_target_next[b, argmax_a q_online_next[b, a]].

Signaturedef double_dqn_target(r, done, q_online_next, q_target_next, gamma)

Example

r [1], done [0], online [[1, 5]], target [[10, 2]], gamma 0.9 gives [1 + 0.9 * 2] = [2.8].

Understand the idea

DQN's target uses the max over next actions of a noisy Q estimate, and taking a max of noisy numbers tends to overshoot. Double DQN splits the job: the online network picks the best next action, and the target network says how good that action is. Since the two networks have different noise, the overestimate shrinks. Worked example: batch of 2, gamma 0.9. Row 0: r 0.5, not done, online Q next [2, 3] picks action 1, target Q next [4, 1] gives 1, so the target is 0.5 + 0.9 * 1 = 1.4. Plain DQN would take max target 4, giving 4.1. Row 1: r 1, done, so the target is just 1. Result [1.4, 1.0]. Rule: a* = argmax over actions of q_online_next[b]; target_b = r_b + gamma * (1 - done_b) * q_target_next[b, a*]. Select with the online network and evaluate with the target network, never both with the target. Treat done as 0 or 1 so terminal rows get no bootstrap. Used in: Atari DQN agents and most modern value-based RL methods, which use this target by default.

solution.pyPython idle
Ctrl/Cmd + Enter runs sample tests

Run checks the first 2 tests. Submit checks all 3.

  • Sample 1: exampledouble_dqn_target([1], [0], [[1, 5]], [[10, 2]], 0.9)
  • Sample 2: terminaldouble_dqn_target([1, 2], [0, 1], [[0, 1], [3, 0]], [[4, 2], [9, 9]], 0.99)
  • Test 3: randomdouble_dqn_target(_r, _d, _qo, _qt, 0.95)