简体   繁体   English

如何创建具有多种功能的 OpenAI Gym Observation 空间

[英]how to create an OpenAI Gym Observation space with multiple features

Using Python3.6, Ubuntu 18.04, Gym 0.15.4, RoS melodic, Tensorflow 1.14 and rl_coach 1.01:使用 Python3.6、Ubuntu 18.04、Gym 0.15.4、RoS 旋律、Tensorflow 1.14 和 rl_coach 1.01:

I have built a custom Gym environment that is using a 360 element array as the observation_space.我已经构建了一个使用 360 元素数组作为观察空间的自定义 Gym 环境。

high = np.array([4.5] * 360) #360 degree scan to a max of 4.5 meters
low = np.array([0.0] * 360)
self.observation_space = spaces.Box(low, high, dtype=np.float32)

However, this is not enough state to properly train via the ClippedPPO algo and I want to add additional features to my state that include:但是,这还不足以通过 ClippedPPO 算法正确训练 state,我想向我的 state 添加其他功能,包括:

Position in the world (x,y coords) Position 世界(x,y坐标)
Orientation in the world (Quaternion: x,y,z,w) Linear Trajectory (x,y,z coords) angular trajectory (x,y,z coords).世界方向(四元数:x,y,z,w) 线性轨迹(x,y,z 坐标) angular 轨迹(x,y,z 坐标)。

I put the four features above into their own np.arrays and tried to pass them all back as the state object, but obviously it does not match the observation space.我把上面的四个特征放到了他们自己的 np.arrays 中,并试图将它们全部作为 state object 传递回来,但显然它与观察空间不匹配。 the space.Box confuses me. space.Box 让我很困惑。 I am assuming I cannot dump all these features into a single np array since uppper and lower bounds will differ, however, I can't determine how to create a spaces.Box object with multiple "features".我假设我无法将所有这些功能转储到单个 np 数组中,因为上限和下限会有所不同,但是,我无法确定如何创建空格。具有多个“功能”的框 object。

TIA TIA

gym.spaces.Dict is what you need:gym.spaces.Dict是你需要的:

import gym

spaces = {
  'position': gym.spaces.Box(low=0, high=100, shape=(2,),
  'orientation': ...
}
dict_space = gym.spaces.Dict(spaces)

Please look at the gym.spaces.Tuple class ref请查看gym.spaces.Tuple class ref

PS You can look at how I have used it for my own ROS env here PS 你可以在这里查看我是如何将它用于我自己的 ROS 环境

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

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