首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在OpenAI中创建一个新的健身房环境?

如何在OpenAI中创建一个新的健身房环境?
EN

Stack Overflow用户
提问于 2017-07-13 06:32:21
回答 2查看 70.8K关注 0票数 92

我有一个任务是制作一个AI Agent,它将学习使用ML玩视频游戏。我想用OpenAI健身房创建一个新的环境,因为我不想使用现有的环境。如何创建新的自定义环境?

另外,有没有其他方法可以让我开始开发使AI代理在没有OpenAI健身房的帮助下玩特定的视频游戏?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-11-06 16:47:20

对于非常小的环境,请参阅我的banana-gym

创建新环境

请参阅存储库的主页:

https://github.com/openai/gym/blob/master/docs/creating_environments.md

具体步骤如下:

  1. 使用PIP-package structure

创建新存储库

它应该看起来像这样

代码语言:javascript
运行
复制
gym-foo/
  README.md
  setup.py
  gym_foo/
    __init__.py
    envs/
      __init__.py
      foo_env.py
      foo_extrahard_env.py

有关它的内容,请单击上面的链接。没有提到的细节特别是foo_env.py中的一些函数应该是什么样子的。查看示例和gym.openai.com/docs/会有所帮助。下面是一个示例:

代码语言:javascript
运行
复制
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

使用您的环境

代码语言:javascript
运行
复制
import gym
import gym_foo
env = gym.make('MyEnv-v0')

示例

  1. https://github.com/openai/gym-soccer
  2. https://github.com/openai/gym-wikinav
  3. https://github.com/alibaba/gym-starcraft
  4. https://github.com/endgameinc/gym-malware
  5. https://github.com/hackthemarket/gym-trading
  6. https://github.com/tambetm/gym-minecraft
  7. https://github.com/ppaquette/gym-doom
  8. https://github.com/ppaquette/gym-super-mario
  9. https://github.com/tuzzer/gym-maze
票数 138
EN

Stack Overflow用户

发布于 2017-07-20 10:09:55

这绝对是可能的。他们在文档页面中这样说,接近尾声。

https://gym.openai.com/docs

至于如何做到这一点,您应该查看现有环境的源代码以获得灵感。它在github中可用:

https://github.com/openai/gym#installation

他们的大多数环境都不是从头开始实现的,而是围绕现有环境创建了一个包装器,并为所有这些环境提供了一个便于强化学习的接口。

如果你想做你自己的,你可能应该朝这个方向走,试着把已经存在的东西调整到健身房界面上。尽管这很有可能是非常耗时的。

对于您的目的,还有另一个选项可能会很有趣。这是OpenAI的宇宙

https://universe.openai.com/

例如,它可以与网站集成,这样你就可以在kongregate游戏上训练你的模型。但是“宇宙”并不像健身房那么容易使用。

如果您是初学者,我的建议是从标准环境中的普通实现开始。在通过了基础知识的问题之后,继续递增...

票数 17
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45068568

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档