【问题标题】:Observation with different boundaries. The observation returned by the `reset()` method does not match the given observation space不同边界的观察。 `reset()` 方法返回的观察与给定的观察空间不匹配
【发布时间】:2023-01-31 02:56:24
【问题描述】:

我是强化学习的初学者,所以不要苛刻地评判我。

错误:AssertionError:reset()方法返回的观察与给定的观察空间不匹配

观察空间:

self.observation_space = gym.spaces.Tuple((
            gym.spaces.Box(low=-float('inf'), high=self.fp.HEIGHT, shape=(1,), dtype=np.float64), # player y
            gym.spaces.Box(low=0, high=self.fp.WIDTH + self.fp.MIN_PIPE_GAP + self.fp.PIPE_WIDTH, shape=(2,), dtype=np.float64), # pipes x
            gym.spaces.Box(low=-float('inf'), high=float('inf'), shape=(1,), dtype=np.float64), # gravity
            gym.spaces.Box(low=-(self.fp.HEIGHT / 4 * 3 + self.fp.MIN_PIPE_GAP + 100), high=self.fp.HEIGHT / 4 * 3 + self.fp.MIN_PIPE_GAP + 100, shape=(4,), dtype=np.float64), # pipes y
            gym.spaces.Box(low=self.fp.PX, high=self.fp.PX, shape=(1,), dtype=np.float64) # player x
        ))

返回观察:

return (
            np.array([float(self.py)]),  # py
            np.array([float(self.pipes[ind]['x']), float(self.pipes[ind + 1]['x'])]),  # x1 x2
            np.array([float(self.gravity)]),  # gravity
            np.array([float(self.pipes[ind]['y1']), float(self.pipes[ind]['y2']), float(self.pipes[ind + 1]['y1']), float(self.pipes[ind + 1]['y2'])]), # y1 y2 y3 y4
            np.array([float(self.PX)])  # px
        )

我试图将所有内容都放在一个数组中(它起作用了),但这是错误的,因为不同的数据组需要不同的边界。最有可能的是,错误的格式不对,如果根据您的说法,一切都是正确的,那么我会尝试在边框中找到错误

【问题讨论】:

    标签: python deep-learning reinforcement-learning openai-gym


    【解决方案1】:

    结果证明错误在边界内。但最后,checker建议使用Dict,所以我就这样重写了代码:

    观察空间:

    self.observation_space = gym.spaces.Dict({
                "player_y": gym.spaces.Box(low=-float('inf'), high=self.fp.HEIGHT, shape=(1,), dtype=np.float64), # player y
                "pipes_x": gym.spaces.Box(low=0, high=self.fp.WIDTH * 3, shape=(2,), dtype=np.float64), # pipes x
                "gravity": gym.spaces.Box(low=-float('inf'), high=float('inf'), shape=(1,), dtype=np.float64), # gravity
                "pipes_y": gym.spaces.Box(low=-(self.fp.HEIGHT / 4 * 3 + self.fp.MIN_PIPE_GAP + 100), high=self.fp.HEIGHT / 4 * 3 + self.fp.MIN_PIPE_GAP + 100, shape=(4,), dtype=np.float64), # pipes y
                "player_x": gym.spaces.Box(low=self.fp.PX, high=self.fp.PX, shape=(1,), dtype=np.float64) # player x
            })
    

    返回:

    return {
                "player_y": np.array([float(self.py)]),  # py
                "pipes_x": np.array([float(self.pipes[ind]['x']), float(self.pipes[ind + 1]['x'])]),  # x1 x2
                "gravity": np.array([float(self.gravity)]),  # gravity
                "pipes_y": np.array([float(self.pipes[ind]['y1']), float(self.pipes[ind]['y2']), float(self.pipes[ind + 1]['y1']), float(self.pipes[ind + 1]['y2'])]), # y1 y2 y3 y4
                "player_x": np.array([float(self.PX)])  # px
            }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-24
      • 1970-01-01
      • 1970-01-01
      • 2017-05-06
      • 1970-01-01
      • 2012-05-11
      相关资源
      最近更新 更多