Is it possible to modify OpenAI environments?

你离开我真会死。 提交于 2020-02-22 08:42:28

问题


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 straight forward?

For example, consider the BipedalWalker environment.

In this case how would I edit things like the SPEED_HIP or SPEED_KNEE variables?

Thanks


回答1:


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.

A nicer way is to download the bipedal walker environment file (from here) and save it to a file (say, 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()

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.

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




回答2:


You can edit the bipedal walker environment just like you can modify the cartpole environment.

All you have to do is modify the constants for SPEED_HIP and SPEED_KNEE.

If you want to change how those constants are used in the locomotion of the agent, you might also want to tweak the step method.

After making changes to the code, when you instantiate the environment, the new instance will be using the modifications you made.



来源:https://stackoverflow.com/questions/53194107/is-it-possible-to-modify-openai-environments

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!