Double DQN

Deep Reinforcement Learning ด้วย Python

Timothée Carayol

Principal Machine Learning Engineer, Komment

Double Q-learning

  • Q-learning ประเมิน Q-value สูงเกินจริง ส่งผลต่อประสิทธิภาพการเรียนรู้
  • สาเหตุมาจาก maximization bias
  • Double Q-Learning แก้ปัญหา bias โดยแยกการเลือก action และการประเมินค่าออกจากกัน

ตาราง Q สองตาราง (ภาพประกอบจากคอร์ส Reinforcement Learning with Gymnasium using Python); double Q-learning ใช้ตารางทั้งสองสลับกัน

Deep Reinforcement Learning ด้วย Python

แนวคิดของ DDQN

  • เริ่มจาก DQN แบบสมบูรณ์ (พร้อม fixed Q-targets)
  • ใน DQN TD target:
    • การเลือก action: target network
    • การประเมินค่า: target network
  • ใน DDQN TD target:
    • การเลือก action: online network
    • การประเมินค่า: target network
  • ไม่ใช่ double Q-learning แบบดั้งเดิม (ไม่มีการสลับ Q-network)
  • ได้ประโยชน์เกือบเท่ากัน แต่แก้ไขโค้ดน้อยมาก

Bellman Error (DQN with fixed Q-targets): Q_online(s_t, a_t) - (r_t+1 + gamma max(Q_target(s_t+1, a)))

Bellman Error (DDQN with fixed Q-targets): Q_online(s_t, a_t) - (r_t+1 + gamma Q_target(s_t+1, tilde a)) with tilde a = argmax_a(Q_online(s_t+1, a))

Deep Reinforcement Learning ด้วย Python

การนำ Double DQN ไปใช้งาน

DQN:

... # instantiate online and target networks
q_values = (online_network(states)
            .gather(1, actions).squeeze(1))

with torch.no_grad():
# # next_q_values = (target_network(next_states) .amax(1))
target_q_values = (rewards + gamma * next_q_values * (1 - dones))
loss = torch.nn.MSELoss()(q_values, target_q_values) ... # gradient descent ... # target network update

DDQN:

... # instantiate online and target networks
q_values = (online_network(states)
            .gather(1, actions).squeeze(1))

with torch.no_grad():

target_q_values = (rewards + gamma * next_q_values * (1 - dones))
loss = torch.nn.MSELoss()(q_values, target_q_values) ... # gradient descent ... # target network update
Deep Reinforcement Learning ด้วย Python

การนำ Double DQN ไปใช้งาน

DQN:

... # instantiate online and target networks
q_values = (online_network(states)
            .gather(1, actions).squeeze(1))

with torch.no_grad():
next_actions = (target_network(next_states) .argmax(1).unsqueeze(1))
next_q_values = (target_network(next_states) .gather(1, next_actions).squeeze(1))
target_q_values = (rewards + gamma * next_q_values * (1 - dones))
loss = torch.nn.MSELoss()(q_values, target_q_values) ... # gradient descent ... # target network update

DDQN:

... # instantiate online and target networks
q_values = (online_network(states)
            .gather(1, actions).squeeze(1))

with torch.no_grad():
next_actions = (online_network(next_states) .argmax(1).unsqueeze(1))
next_q_values = (target_network(next_states) .gather(1, next_actions).squeeze(1))
target_q_values = (rewards + gamma * next_q_values * (1 - dones))
loss = torch.nn.MSELoss()(q_values, target_q_values) ... # gradient descent ... # target network update
Deep Reinforcement Learning ด้วย Python

ประสิทธิภาพของ DDQN

 

  • เปรียบเทียบประสิทธิภาพของ DDQN, DQN และผู้เล่นมนุษย์บนเกม Atari
  • DDQN: ทำคะแนนได้สูงกว่า DQN เดิม
  • ไม่เป็นเช่นนั้นเสมอไป -> ควรทดลองทั้งสองแบบ

แผนภูมิแท่งแสดงว่า DQN ทำคะแนนใกล้เคียงมนุษย์สำหรับเกมค่ามัธยฐาน และทำคะแนนเหนือมนุษย์โดยเฉลี่ย; ส่วน DDQN ทำคะแนนเหนือทั้งมนุษย์และ DQN ทั้งในค่ามัธยฐานและค่าเฉลี่ย

1 https://arxiv.org/abs/2303.11634
Deep Reinforcement Learning ด้วย Python

มาฝึกกันเถอะ!

Deep Reinforcement Learning ด้วย Python

Preparing Video For Download...