深度强化学习:CartPole 游戏的 Q 学习与 SARSA 学习实现
在强化学习领域,我们常常通过构建模型来让智能体在特定环境中学习并执行任务。本文将详细介绍如何使用深度 Q 学习(DQN)和深度 SARSA 学习在 OpenAI Gym 的 CartPole-v1 游戏中训练智能体,并对模型性能进行测试和评估。
测试 DQN 模型
首先,我们需要测试训练好的 DQN 模型在新游戏中的表现。以下是测试函数的代码:
def test(env, model, states, episodes=100, render=False):
"""Test the performance of the DQN agent."""
scores_test = []
for episode in range(1, (episodes+1)):
state = env.reset()
state = state.reshape(1, states)
done = False
time_step = 0
while not done:
if render:
env.render()
action = np.argmax(model.predict(state)[0])
new_state, reward, done, info = env.step(action)
new_state = new_state.
超级会员免费看
订阅专栏 解锁全文
69

被折叠的 条评论
为什么被折叠?



