如何在 OpenAI 中创建一个新的健身房环境?
How to create a new gym environment in OpenAI?
我有一项任务是制作一个 AI 代理,该代理将学习使用 ML 玩视频游戏。我想使用 OpenAI Gym 创建一个新环境,因为我不想使用现有环境。如何创建新的自定义环境?
此外,有没有其他方法可以让我开始开发让 AI Agent 在没有 OpenAI Gym 帮助的情况下玩特定的视频游戏?
绝对有可能。他们在接近尾声的文档页面中这样说。
具体怎么做,你应该看看现有环境的源代码来寻找灵感。它在 github:
中可用
https://github.com/openai/gym#installation
他们的大部分环境都没有从头开始实施,而是围绕现有环境创建了一个包装器,并为其提供了一个便于强化学习的接口。
如果你想自己制作,你应该朝这个方向努力,并尝试将已经存在的东西适应健身房界面。虽然这很有可能非常耗时。
还有一个选项可能对您的目的感兴趣。这是 OpenAI 的宇宙
它可以与网站集成,例如,您可以在 kongregate 游戏上训练您的模型。但是Universe没有Gym好用
如果您是初学者,我的建议是您从标准环境中的原始实现开始。通过基础问题后,继续增加...
请参阅我的 banana-gym
以了解极小的环境。
创建新环境
查看存储库的主页:
https://github.com/openai/gym/blob/master/docs/creating_environments.md
步骤是:
- 创建具有 PIP 包结构的新存储库
它应该是这样的
gym-foo/
README.md
setup.py
gym_foo/
__init__.py
envs/
__init__.py
foo_env.py
foo_extrahard_env.py
里面的内容,按照上面的link。没有提到的细节特别是 foo_env.py
中的一些函数应该是什么样子。查看示例和 gym.openai.com/docs/ 有帮助。这是一个例子:
class FooEnv(gym.Env):
metadata = {'render.modes': ['human']}
def __init__(self):
pass
def _step(self, action):
"""
Parameters
----------
action :
Returns
-------
ob, reward, episode_over, info : tuple
ob (object) :
an environment-specific object representing your observation of
the environment.
reward (float) :
amount of reward achieved by the previous action. The scale
varies between environments, but the goal is always to increase
your total reward.
episode_over (bool) :
whether it's time to reset the environment again. Most (but not
all) tasks are divided up into well-defined episodes, and done
being True indicates the episode has terminated. (For example,
perhaps the pole tipped too far, or you lost your last life.)
info (dict) :
diagnostic information useful for debugging. It can sometimes
be useful for learning (for example, it might contain the raw
probabilities behind the environment's last state change).
However, official evaluations of your agent are not allowed to
use this for learning.
"""
self._take_action(action)
self.status = self.env.step()
reward = self._get_reward()
ob = self.env.getState()
episode_over = self.status != hfo_py.IN_GAME
return ob, reward, episode_over, {}
def _reset(self):
pass
def _render(self, mode='human', close=False):
pass
def _take_action(self, action):
pass
def _get_reward(self):
""" Reward is given for XY. """
if self.status == FOOBAR:
return 1
elif self.status == ABC:
return self.somestate ** 2
else:
return 0
使用你的环境
import gym
import gym_foo
env = gym.make('MyEnv-v0')
例子
- https://github.com/openai/gym-soccer
- https://github.com/openai/gym-wikinav
- https://github.com/alibaba/gym-starcraft
- https://github.com/endgameinc/gym-malware
- https://github.com/hackthemarket/gym-trading
- https://github.com/tambetm/gym-minecraft
- https://github.com/ppaquette/gym-doom
- https://github.com/ppaquette/gym-super-mario
- https://github.com/tuzzer/gym-maze
我有一项任务是制作一个 AI 代理,该代理将学习使用 ML 玩视频游戏。我想使用 OpenAI Gym 创建一个新环境,因为我不想使用现有环境。如何创建新的自定义环境?
此外,有没有其他方法可以让我开始开发让 AI Agent 在没有 OpenAI Gym 帮助的情况下玩特定的视频游戏?
绝对有可能。他们在接近尾声的文档页面中这样说。
具体怎么做,你应该看看现有环境的源代码来寻找灵感。它在 github:
中可用https://github.com/openai/gym#installation
他们的大部分环境都没有从头开始实施,而是围绕现有环境创建了一个包装器,并为其提供了一个便于强化学习的接口。
如果你想自己制作,你应该朝这个方向努力,并尝试将已经存在的东西适应健身房界面。虽然这很有可能非常耗时。
还有一个选项可能对您的目的感兴趣。这是 OpenAI 的宇宙
它可以与网站集成,例如,您可以在 kongregate 游戏上训练您的模型。但是Universe没有Gym好用
如果您是初学者,我的建议是您从标准环境中的原始实现开始。通过基础问题后,继续增加...
请参阅我的 banana-gym
以了解极小的环境。
创建新环境
查看存储库的主页:
https://github.com/openai/gym/blob/master/docs/creating_environments.md
步骤是:
- 创建具有 PIP 包结构的新存储库
它应该是这样的
gym-foo/
README.md
setup.py
gym_foo/
__init__.py
envs/
__init__.py
foo_env.py
foo_extrahard_env.py
里面的内容,按照上面的link。没有提到的细节特别是 foo_env.py
中的一些函数应该是什么样子。查看示例和 gym.openai.com/docs/ 有帮助。这是一个例子:
class FooEnv(gym.Env):
metadata = {'render.modes': ['human']}
def __init__(self):
pass
def _step(self, action):
"""
Parameters
----------
action :
Returns
-------
ob, reward, episode_over, info : tuple
ob (object) :
an environment-specific object representing your observation of
the environment.
reward (float) :
amount of reward achieved by the previous action. The scale
varies between environments, but the goal is always to increase
your total reward.
episode_over (bool) :
whether it's time to reset the environment again. Most (but not
all) tasks are divided up into well-defined episodes, and done
being True indicates the episode has terminated. (For example,
perhaps the pole tipped too far, or you lost your last life.)
info (dict) :
diagnostic information useful for debugging. It can sometimes
be useful for learning (for example, it might contain the raw
probabilities behind the environment's last state change).
However, official evaluations of your agent are not allowed to
use this for learning.
"""
self._take_action(action)
self.status = self.env.step()
reward = self._get_reward()
ob = self.env.getState()
episode_over = self.status != hfo_py.IN_GAME
return ob, reward, episode_over, {}
def _reset(self):
pass
def _render(self, mode='human', close=False):
pass
def _take_action(self, action):
pass
def _get_reward(self):
""" Reward is given for XY. """
if self.status == FOOBAR:
return 1
elif self.status == ABC:
return self.somestate ** 2
else:
return 0
使用你的环境
import gym
import gym_foo
env = gym.make('MyEnv-v0')
例子
- https://github.com/openai/gym-soccer
- https://github.com/openai/gym-wikinav
- https://github.com/alibaba/gym-starcraft
- https://github.com/endgameinc/gym-malware
- https://github.com/hackthemarket/gym-trading
- https://github.com/tambetm/gym-minecraft
- https://github.com/ppaquette/gym-doom
- https://github.com/ppaquette/gym-super-mario
- https://github.com/tuzzer/gym-maze