问题描述
我想在 OpenAI 环境中修改一些内容.如果我们使用 Cartpole 示例,那么我们可以编辑类 init 函数中的内容,但对于使用 Box2D
的环境,它似乎并不那么简单.
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.
例如,考虑 BipedalWalker 环境.
在这种情况下,我将如何编辑 SPEED_HIP
或 SPEED_KNEE
变量之类的内容?
In this case, how would I edit things like the SPEED_HIP
or SPEED_KNEE
variables?
推荐答案
是的,您可以在 Gym 中修改或创建新环境.最简单(但不推荐)的方法是直接修改本地健身房安装中的常量,但这当然不是很好.
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.
更好的方法是下载 Bipedal walker 环境文件(从这里) 并将其保存到文件中(例如,my_bipedal_walker.py
)
A nicer way is to download the bipedal walker environment file (from here) and save it to a file (say, my_bipedal_walker.py
)
然后您修改 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):
import gym
from my_bipedal_walker import BipedalWalker
env = BipedalWalker()
然后,env
变量是环境的一个实例,其中包含为物理计算定义的常量,可以与任何 RL 算法一起使用.
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.
更好的方法是在 OpenAI 健身房注册表中提供您的自定义环境,您可以按照说明进行操作 这里
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 环境?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!