Skip to main content
. 2025 Sep 11;15(18):2304. doi: 10.3390/diagnostics15182304
Algorithm 2 DualContextAtt DQN Algorithm
  • Step 1: Initialize

  • Initialize Q-network and target Q-network with dueling architecture and context-aware self-attention.

  • Initialize replay buffer D.

  • for each episode do

  •       Reset environment and observe initial state s.

  •       for each time step do

  •             Select action at using ϵ-greedy:
    at=argmaxaQ(s,a;θ)
  •             Execute at, observe reward rt and next state st+1.

  •             Store (st,at,rt,st+1) in buffer D.

  •             Sample mini-batch of transitions (s,a,r,s′) from D.

  •             Step 2: Compute Target Q-values
    yi=ri+γmaxa′Q′(s′,a′;θ−),ifnotterminalri,ifterminal
  •             Step 3: Compute Predicted Q-values with Attention Fusion

  •             Compute value stream V(s;θ)

  •             Compute advantage stream A(s,a;θ)

  •             Compute attention fusion weight w(s;θ)

  •             Fuse:
    Q(s,a;θ)=w·V(s)+(1−w)·A(s,a)−1|A|∑a′A(s,a′)
  •             Step 4: Compute Loss (MSE)
    L(θ)=1N∑i∈NQθ(si,ai)−Qθ′(si,ai)2
    where
    Qθ′=R(st,at)+γmaxai′Qθ(si′,ai′)
  •             Step 5: Update Parameters

  •             Perform gradient descent on L(θ)

  •             Update target network parameters: θ−←θ periodically

  •       end for

  • end for

  • Step 6: Repeat Until Convergence

  • Repeat steps until convergence or maximum episodes.