openai gym env.P, AttributeError 'TimeLimit' 对象没有属性 'P'
openai gym env.P, AttributeError 'TimeLimit' object has no attribute 'P'
我目前正在阅读 Sudharsan Ravichandiran 的 Hands-On Reinforcement Learning with Python 以及我 运行 进入这个 AttributeError 的第一个例子:
AttributeError 'TimeLimit' object has no attribute 'P'
由以下行提出:
for next_sr in env.P[state][action]:
我找不到关于 env.P 的任何文档,但我在此处找到了用 python2 编写的类似示例:https://gym.openai.com/evaluations/eval_48sirBRSRAapMjotYzjb6w/
我想 env.P 是一个过时图书馆的一部分(即使这本书是在 2018 年 6 月出版的,并且有罪的代码在 python3 ), 那么我该如何替换它呢?
首先尝试通过添加这个
解包 env
env = env.unwrapped
试试这个,
for next_sr in env.env.P[state][action]:
注意开头的额外 'env'
一般用途,试试
>>> dir(class_name)
这将给出成员函数列表。
如果您使用的是最新版本的 OpenAI Gym,this github issue link 中提出的解决方案对我有用。
如 github 问题中所述,最新版本的 gym 中的监控已被 wrapper 取代,因此监控将不适用于最新的 gym。要在最新版本的 Gym 中重新实现监控,请更改类似以下的代码:
env.monitor.start('cartpole-hill/', force=True)
到
env = gym.wrappers.Monitor(env,directory='cartpole-hill/',force=True,write_upon_reset=True)
我目前正在阅读 Sudharsan Ravichandiran 的 Hands-On Reinforcement Learning with Python 以及我 运行 进入这个 AttributeError 的第一个例子:
AttributeError 'TimeLimit' object has no attribute 'P'
由以下行提出:
for next_sr in env.P[state][action]:
我找不到关于 env.P 的任何文档,但我在此处找到了用 python2 编写的类似示例:https://gym.openai.com/evaluations/eval_48sirBRSRAapMjotYzjb6w/
我想 env.P 是一个过时图书馆的一部分(即使这本书是在 2018 年 6 月出版的,并且有罪的代码在 python3 ), 那么我该如何替换它呢?
首先尝试通过添加这个
解包 envenv = env.unwrapped
试试这个,
for next_sr in env.env.P[state][action]:
注意开头的额外 'env'
一般用途,试试
>>> dir(class_name)
这将给出成员函数列表。
如果您使用的是最新版本的 OpenAI Gym,this github issue link 中提出的解决方案对我有用。
如 github 问题中所述,最新版本的 gym 中的监控已被 wrapper 取代,因此监控将不适用于最新的 gym。要在最新版本的 Gym 中重新实现监控,请更改类似以下的代码:
env.monitor.start('cartpole-hill/', force=True)
到
env = gym.wrappers.Monitor(env,directory='cartpole-hill/',force=True,write_upon_reset=True)