繁体   English   中英

不同边界的观察。 `reset()` 方法返回的观察与给定的观察空间不匹配

[英]Observation with different boundaries. The observation returned by the `reset()` method does not match the given observation space

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

error: 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
        )

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

结果证明错误在边界内。 但最后,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
        }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM