为智能体策略计算折扣回报
折扣回报用于评估智能体在一段时间内期望累计的总奖励,同时考虑到未来奖励的价值低于立即获得的奖励。已给出某个 RL 智能体两种不同策略的期望奖励(exp_rewards_strategy_1 和 exp_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}")