题意:“是否可以修改 OpenAI 环境?”
问题背景:
There are some things that I would like to modify in the OpenAI environments. If we use the Cartpole example then we can edit things that are in the class init function but with environments that use Box2D
it doesn't seem to be as straightforward.
“我有一些想要修改的 OpenAI 环境。如果我们使用 Cartpole 示例,我们可以编辑类的初始化函数中的内容,但对于使用 Box2D 的环境,这似乎就不那么简单了。”
For example, consider the BipedalWalker environment.
“例如,考虑一下 BipedalWalker 环境。”
In this case, how would I edit things like the SPEED_HIP
or SPEED_KNEE
variables?
“在这种情况下,我该如何编辑像 SPEED_HIP 或 SPEED_KNEE 这样的变量?”
问题解决:
Yes, you can modify or create new environments in gym. The simplest (but not recommended) way is to modify the constants in your local gym installation directly, but of course that's not really nice.
“是的,你可以修改或创建新的 Gym 环境。最简单(但不推荐)的方法是直接修改你本地 Gym 安装中的常量,但这种做法并不优雅。”
A nicer way is to download the bipedal walker environment file (from here) and save it to a file (say, my_bipedal_walker.py
)
“更好的方法是下载 Bipedal Walker 环境文件(从这里),并将其保存到一个文件中(比如,`my_bipedal_walker.py`)。”
Then you modify the constants in the my_bipedal_walker.py
file, and then just import it in your code (assuming you put the file in a path that is importable, or the same folder as your other code files):
“然后你可以修改 `my_bipedal_walker.py` 文件中的常量,然后在你的代码中导入它(假设你将文件放在一个可以导入的路径中,或与其他代码文件在同一文件夹下)。”
import gym
from my_bipedal_walker import BipedalWalker
env = BipedalWalker()
Then you have the env
variable being an instance of the environment, with your defined constants for the physics computation, which you can use with any RL algorithm.
“这样,`env` 变量就会成为环境的一个实例,使用你定义的物理计算常量,你可以将其用于任何强化学习算法。”
An even nicer way would be making your custom environment available in the OpenAI gym registry, which you can do by following the instructions here
“一个更好的方法是将你的自定义环境注册到 OpenAI Gym 注册表中,你可以按照 [这里](链接) 的说明进行操作。”