学习和累积奖励是评估强化学习模型的良好指标吗?



我是强化学习的新手。

我在这里有一个问题,我正在使用DQN。我在学习和采取行动时绘制了累积奖励曲线。在 100 集之后,它显示出很多波动,并没有告诉我它是否学到了什么。

然而,我没有使用学习和累积奖励,而是在每一集之后对模型进行了整个模拟,没有学习方法,它向我展示了模型实际上学习得很好。这大大延长了程序运行时间。

此外,我必须在此过程中提取最佳模型,因为最终模型有时似乎表现不佳。

对此有什么建议或解释吗?

尝试使用平均回报率 这通常是一个很好的指标,可以知道代理是否在改善。

如果您正在使用tf_agent则可以执行以下操作:

...
checkpoint_dir = os.path.join('./', 'checkpoint')
train_checkpointer = common.Checkpointer(
ckpt_dir=checkpoint_dir,
max_to_keep=1,
agent=agent,
policy=agent.policy,
replay_buffer=replay_buffer,
global_step=train_step
)
policy_dir = os.path.join('./', 'policy')
tf_policy_saver = policy_saver.PolicySaver(agent.policy)

def train_agent(n_iterations):
best_AverageReturn = 0
time_step = None
policy_state = agent.collect_policy.get_initial_state(tf_env.batch_size)
iterator = iter(dataset)
for iteration in range(n_iterations):
time_step, policy_state = collect_driver.run(time_step, policy_state)
trajectories, buffer_info = next(iterator)
train_loss = agent.train(trajectories)
if iteration % 10 == 0:
print("r{} loss:{:.5f}".format(iteration, train_loss.loss.numpy()), end="")

if iteration % 1000 == 0 and averageReturnMetric.result() > best_AverageReturn:
best_AverageReturn = averageReturnMetric.result()
train_checkpointer.save(train_step)
tf_policy_saver.save(policy_dir)

在 1000 步之后,训练函数评估平均回报,如果有任何改进,则创建一个检查点

相关内容

最新更新