You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

强化学习环境报错:reset()返回观测与观测空间不匹配求助

问题:reset()返回观测与Gym观测空间不匹配的AssertionError

我是强化学习初学者,还请多多包涵。目前遇到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
        ))

reset()返回的观测

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
        )

我曾尝试将所有数据合并到一个数组中(能运行但不符合要求),因为不同数据组需要不同边界约束。我猜测错误大概率出在格式上,若您认为格式无误,我再去排查边界问题。

内容的提问来源于stack exchange,提问作者Vlad Sunny

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.02 20:25:46