পাঠ ১৫ · ৩২-এর মধ্যে · মডিউল ২

Double DQN ও Dueling DQN

Fixing DQN's biases — Double & Dueling architectures
৭ মিনিট পড়া উচ্চ · Advanced PyTorch

এই পাঠে যা শিখবেন

  • Double DQN — overestimation bias-এর সমাধান
  • Dueling architecture — V ও Advantage শাখা
  • Rainbow agent — ৬ improvement-এর synthesis
  • NoisyNet ও Distributional RL preview

১ · Vanilla DQN-এর overestimation

DQN target: $r + \gamma \max_{a'} Q_{\theta^-}(s', a')$।

Q-learning-এর pre-existing bias (পাঠ ১২) — function approximation-এ amplified:

  • NN-এর Q-prediction noisy (some action over, some under)।
  • $\max$ — over-estimated action সবসময় বাছে।
  • Bias propagates — Q values inflate।

Hasselt (2015) — Atari game-এ Q-value true value-এর চেয়ে ২-৩x বেশি দেখান।

২ · Double DQN solution

Hasselt, Guez, Silver (2016)। Idea: action selection ও action evaluation আলাদা network থেকে।

Original DQN target:

$$y^{DQN} = r + \gamma \max_{a'} Q_{\theta^-}(s', a')$$

Double DQN target:

$$y^{DDQN} = r + \gamma \cdot Q_{\theta^-}(s', \arg\max_{a'} Q_\theta(s', a'))$$

মানে — $\arg\max$ online net থেকে, value target net থেকে। দু'টি network-এর noise uncorrelated হলে — bias significantly reduced।

Implementation

DQN-এর কোডে শুধু target line বদল:
q_target = r + γ · target_net(s_next)[ argmax(q_net(s_next)) ]

৩ · Dueling DQN architecture

Wang et al. (2016)। Insight: $Q(s, a) = V(s) + A(s, a)$ where $A$ = advantage।

State-এ অনেক action-এর Q-value সমান হলে — শেখা inefficient। আলাদা $V$ ও $A$ branch করলে — $V$ dominant feature, $A$ nuance।

Architecture:

  • Shared CNN backbone।
  • Two heads:
    • $V_\theta(s)$ — scalar।
    • $A_\theta(s, a)$ — $|A|$ values।
  • Combine: $Q(s, a) = V(s) + A(s, a) - \frac{1}{|A|} \sum_{a'} A(s, a')$।

Mean-subtraction — identifiability ensure (V ও A unique decomposition)।

Dueling DQN Architecture Input s 84×84×4 Shared CNN 3 conv layers V branch FC → V(s) scalar A branch FC → A(s, ·) |A| values Combine Q = V + (A − mean A) identifiability Q(s, ·) |A| Q-values Insight: যখন প্রায় সব action-এর Q সমান — শুধু V update দিয়ে সব Q একসাথে শেখে। Vanilla DQN-এ — প্রতি action-এ আলাদা update। Dueling — V-tied learning, faster convergence। Atari-এ vanilla DQN-এর তুলনায় ~৩৫% improvement।
Dueling DQN — V ও Advantage শাখা। state value আলাদাভাবে শেখে, action-specific bonus advantage।

৪ · কেন Dueling কাজ করে

Atari Pong-এ — প্রতি frame-এ সব action-এর Q প্রায় সমান (ball দূরে থাকলে, কোন action নিলেই tied)। Vanilla DQN — প্রতি action-এর জন্য আলাদা update — slow।

Dueling — $V(s)$ একবার update করলেই — সব action-এর Q implicitly update। sample efficient।

৫ · PyTorch Double + Dueling

Python · Dueling DQN
import torch
import torch.nn as nn

class DuelingDQN(nn.Module):
    def __init__(self, state_dim, n_actions):
        super().__init__()
        self.feature = nn.Sequential(
            nn.Linear(state_dim, 128), nn.ReLU(),
            nn.Linear(128, 128), nn.ReLU(),
        )
        self.value_head = nn.Linear(128, 1)
        self.advantage_head = nn.Linear(128, n_actions)

    def forward(self, x):
        feat = self.feature(x)
        V = self.value_head(feat)               # (B, 1)
        A = self.advantage_head(feat)           # (B, |A|)
        # mean-subtraction for identifiability
        Q = V + (A - A.mean(dim=1, keepdim=True))
        return Q

# Double-DQN target
def double_dqn_target(q_net, target_net, s_next, r, done, gamma):
    with torch.no_grad():
        # online net চয়ন করে action
        a_select = q_net(s_next).argmax(dim=1, keepdim=True)
        # target net ওই action-এর value দেয়
        q_next = target_net(s_next).gather(1, a_select).squeeze()
        target = r + gamma * (1 - done) * q_next
    return target

print("Double + Dueling DQN ready")

    
১৫ লাইনের পরিবর্তনে — vanilla DQN থেকে significant improvement। Atari benchmark-এ Double+Dueling — original DQN-এর চেয়ে ২৫-৪০% better।

৬ · Rainbow DQN (Hessel et al., 2017)

৬ improvement একসাথে combine — Atari SOTA:

  1. Double DQN — overestimation।
  2. Dueling DQN — V/A decomposition।
  3. Prioritized replay — important transition।
  4. Multi-step learning ($n$-step return)।
  5. Distributional DQN (C51): categorical distribution over returns।
  6. Noisy networks: exploration via parameter noise।

Result: Atari median performance — DQN-এর ৩-৪x।

৭ · Distributional RL — short intro

Bellemare et al. (2017) — C51। $Q$-এর জায়গায় full distribution $Z(s, a)$ predict — discrete bins।

Bellman update — distribution-এ:

$$Z(s, a) \stackrel{D}{=} R + \gamma Z(s', \arg\max_{a'} \mathbb{E}[Z(s', a')])$$

কেন better: richer signal for learning। variance, skewness — সব encoded।

৮ · NoisyNet — exploration via parameter noise

Fortunato et al. (2017)। ε-greedy-এর alternative — network parameters-এ Gaussian noise:

$$y = (\mu^w + \sigma^w \odot \epsilon^w) x + (\mu^b + \sigma^b \odot \epsilon^b)$$

$\sigma$ trainable। শুরুতে noise বড় (explore), ধীরে ধীরে কমে (exploit)। state-aware automatic exploration।

৯ · Modern context

  • R2D2 (2019): Dueling + Distributional + recurrent। Atari-এ human ৪x।
  • NGU (2020): intrinsic motivation + R2D2।
  • Agent57 (2020): Atari ৫৭ গেমে human surpass।
  • MuZero (2020): tree search + learned model — Atari, Go, Chess all।

প্রতিটি — DQN-এর ideas-এর evolution।

Pure DQN production-এ rarely। কিন্তু এদের ideas (target net, replay, V/A decomposition) সর্বত্র — DDPG, SAC, Decision Transformer, MuZero।

ভাবনার প্রশ্ন

প্র ০১Double DQN এ "double" কেন উল্টো? আগে দু'টি Q-table ছিল, DDQN-এ একটাই online + target?

Original Double Q-learning (Hasselt 2010) tabular — দু'টি independent Q-table $Q_A, Q_B$:

  • Update $Q_A$: target = $\max_a Q_B(s', a)$।
  • Update $Q_B$: target = $\max_a Q_A(s', a)$।

Double DQN (2016) — function approximation context-এ সরলীকরণ:

  • Online net $\theta$ (already exists)।
  • Target net $\theta^-$ (already exists for stability)।
  • Hasselt observed: এই দুটোই decorrelated enough! Action select online থেকে, evaluate target থেকে — practically Double Q-learning।

Pragmatic shortcut: existing target net "বিনামূল্যে" double Q-learning দেয়। কোনো extra parameter, extra memory নেই।

Limitation: $\theta$ ও $\theta^-$ correlated (slowly drifting)। তাই bias reduction partial — but enough for big gain।

প্র ০২Dueling-এ mean-subtraction কেন — max-subtraction না কেন?

$Q(s, a) = V(s) + A(s, a)$ — equation underdetermined (V + c, A − c — same Q)। তাই constraint দরকার।

Option 1: max-subtraction

$Q = V + (A - \max_{a'} A(s, a'))$।

  • $\max A = 0$ — best action-এ A=0।
  • $V$ = best Q।
  • Theoretically clean — V exactly state value।
  • কিন্তু — gradient max-এ থেকে বেশি কিছু flows না — slow learning।

Option 2: mean-subtraction (Wang 2016)

$Q = V + (A - \text{mean}_{a'} A)$।

  • সব A-এর gradient কিছু flow করে।
  • $V$ ≠ state value (mean-shifted) কিন্তু practically OK।
  • Empirically more stable।

Option 3: no constraint

  • $V, A$ free — identifiability issue।
  • Empirically: gradient drift, sometimes diverge।

Choice: Wang et al. paper-এ mean-subtraction better empirically। তাই standard।

প্র ০৩Rainbow-এর ৬ improvement-এ কোনটি সবচেয়ে impactful?

Hessel et al. paper-এ ablation — প্রতিটি component remove করে impact measure।

Most impactful (based on ablation):

  1. Multi-step (n-step) learning — single biggest। short-horizon problem-এ slight, long-horizon-এ huge।
  2. Prioritized replay — Atari sparse-reward game-এ critical।
  3. Distributional (C51) — significant on most games।
  4. NoisyNet — improves exploration in hard games।
  5. Dueling — moderate, mostly value-based games।
  6. Double — smallest individual effect (overlapping with others)।

Surprise: n-step has biggest effect. tabular world-এ n-step-এর importance under-appreciated, scale-এ প্রকাশিত।

Synergy: ৬ একসাথে — sum of parts-এর চেয়ে বেশি। interaction effects positive।

Recent simplification: "Revisiting Rainbow" (2021) — শুধু n-step, double, replay enough for 90% gain।

প্র ০৪Distributional RL কেন expected value approach-এর চেয়ে ভাল?

C51 (Bellemare 2017) — Q-এর জায়গায় full return distribution learn।

Why richer signal:

  • Mean ছাড়াও variance, skewness encoded।
  • Multi-modal returns (e.g., 50% chance +10, 50% chance -10) properly represent।
  • NN-এর representation — distribution learning-এ better gradient flow।

Categorical (C51) approach:

  • Return space-কে 51 bins-এ split।
  • Q-net output — softmax over 51 atoms।
  • Bellman update — KL divergence loss।

Quantile regression (QR-DQN):

  • Bins-এর জায়গায় quantile predict।
  • Smoother, support boundary issue নেই।

IQN (Implicit Quantile Network):

  • Continuous quantile distribution।
  • Atari SOTA।

Risk-sensitive RL:

  • Distribution থাকলে — risk-averse policy (CVaR)। medical, finance-এ critical।
  • Mean-only — risk hidden।

Modern: distributional RL — Atari, Go, robotics-এ standard option। MuZero-এ used।

অনুশীলন

  1. DDQN target compute: $Q_\theta(s', \cdot) = [3, 5, 4]$, $Q_{\theta^-}(s', \cdot) = [4, 4, 5]$, $r=1, \gamma=0.9$, not done। DQN ও DDQN target?

    DQN: $1 + 0.9 \cdot \max[4,4,5] = 1 + 4.5 = 5.5$।

    DDQN: argmax of $Q_\theta = $ index 1 (Q=5)। Target net-এর index 1: 4। Target = $1 + 0.9 \cdot 4 = 4.6$।

    DDQN-এর target কম — overestimation reduction।

  2. Dueling parse: $V(s) = 5$, $A(s, \cdot) = [1, 3, 2]$, mean=2। $Q(s, \cdot)$?

    $Q = V + (A - \text{mean}) = 5 + [-1, 1, 0] = [4, 6, 5]$।

  3. Code modify: উপরের Dueling network-এ — separate network for V (no shared backbone)। কি পার্থক্য পাবেন?

    Separate backbone — V ও A independent feature learn। সাধারণত performance worse — feature redundancy। Shared backbone parameter-efficient ও representation generalize।

আরও পড়ুন

পূর্ববর্তী পাঠ
পাঠ ১৪ · Replay & Target Net