開始使用免費開始

計算代理程式策略的折扣報酬

折扣報酬有助於評估代理程式在一段時間內可望累積的獎勵總量,同時考量未來獎勵相較於立即獎勵的價值較低。你已獲得某個 RL 代理程式的兩種不同策略(exp_rewards_strategy_1exp_rewards_strategy_2)的期望獎勵。你的任務是計算每個策略的折扣報酬,並判斷哪一個策略的報酬較高。

已為你匯入 numpy 函式庫並命名為 np

本練習屬於課程

使用 Python 的 Gymnasium 進行強化學習

檢視課程

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

exp_rewards_strategy_1 = np.array([3, 2, -1, 5])

discount_factor = 0.9

# Compute discounts
discounts_strategy_1 = np.array([____ for i in range(len(exp_rewards_strategy_1))])

# Compute the discounted return
discounted_return_strategy_1 = np.sum(____)

print(f"The discounted return of the first strategy is {discounted_return_strategy_1}")
編輯並執行程式碼