套用 Double Q-learning
在這個練習中,你要在與前一題 Expected SARSA 相同的自訂環境中,套用 Double Q-learning 演算法來比較差異。Double Q-learning 透過使用兩個 Q-table,能減少傳統 Q-learning 內建的高估偏誤,並且比其他時間差分方法有更穩定的學習表現。你將用這個方法在方格環境中導航,在盡可能快速抵達目標的同時,爭取最高報酬並避開山脈。

本練習屬於課程
使用 Python 的 Gymnasium 進行強化學習
練習說明
- 使用你在上一個練習中撰寫的
update_q_tables()函式來更新 Q-table。 - 將兩個 Q-table 相加來合併。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
Q = [np.zeros((num_states, num_actions))] * 2
for episode in range(num_episodes):
state, info = env.reset()
terminated = False
while not terminated:
action = np.random.choice(num_actions)
next_state, reward, terminated, truncated, info = env.step(action)
# Update the Q-tables
____
state = next_state
# Combine the learned Q-tables
Q = ____
policy = {state: np.argmax(Q[state]) for state in range(num_states)}
render_policy(policy)