OpenAI 环境(健身房)应该如何使用 env.seed(0)?

Mar*_*oma 5 random random-seed openai-gym

我创建了一个非常简单的 OpenAI 健身房 ( banana-gym) 并想知道我是否应该/如何实现env.seed(0).

例如,参见https://github.com/openai/gym/issues/250#issuecomment-234126816

Den*_*ers 2

该函数的文档字符串(可以在此文件env.seed()中找到)提供了有关该函数应实现的功能的以下文档:

Sets the seed for this env's random number generator(s).

    Note:
        Some environments use multiple pseudorandom number generators.
        We want to capture all such seeds used in order to ensure that
        there aren't accidental correlations between multiple generators.
    Returns:
        list<bigint>: Returns the list of seeds used in this env's random
          number generators. The first value in the list should be the
          "main" seed, or the value which a reproducer should pass to
          'seed'. Often, the main seed equals the provided 'seed', but
          this won't be true if seed=None, for example.
Run Code Online (Sandbox Code Playgroud)

请注意,与您链接到的问题中的文档和评论似乎暗示的不同,它似乎(对我来说)不env.seed()应该被自定义环境覆盖。env.seed()有一个非常简单的实现,它只调用并返回 的返回值env._seed(),在我看来,是应该被自定义环境覆盖的函数。

例如,OpenAI 健身房的atari 环境有一个自定义_seed()实现,它设置由(基于)Arcade 学习环境内部使用的种子C++

由于您random.random()自定义环境中进行了调用,因此您可能应该实现_seed()调用random.seed()。这样,您的环境的用户就可以通过确保seed()使用相同的参数调用您的环境来重现实验。

注意:像这样乱搞全局随机种子可能会出乎意料,最好在环境初始化时创建一个专用的随机对象,为该对象提供种子,并确保在需要时始终获取随机数。来自该物体的环境。