我正在 OpenAI Gym 中创建自定义环境,但真的不明白,action_space 是做什么用的?我应该在里面放什么?准确地说,我不知道 action_space 是什么,我没有在任何代码中使用它。而且我在互联网上没有找到任何东西,什么可以正常回答我的问题。
该action_space在健身房环境中使用是用来定义环境的作用空间的特性。有了这个,人们可以说明动作空间是连续的还是离散的,定义动作的最小值和最大值等。
对于连续动作空间,可以使用Box类。
import gym
from gym import spaces
class MyEnv(gym.Env):
def __init__(self):
# set 2 dimensional continuous action space as continuous
# [-1,2] for first dimension and [-2,4] for second dimension
self.action_space = spaces.Box(np.array([-1,-2]),np.array([2,4]),dtype=np.float32)
Run Code Online (Sandbox Code Playgroud)
对于离散,可以使用Discrete类。
import gym
from gym import spaces
class MyEnv(gym.Env):
def __init__(self):
# set 2 dimensional action space as discrete {0,1}
self.action_space = spaces.Discrete(2)
Run Code Online (Sandbox Code Playgroud)
如果您有任何其他要求,您可以查看 OpenAI 健身房存储库中的此文件夹。你也可以通过去在健身房文件夹给出不同的环境下得到的用法的更多示例action_space和observation_space。
此外,通过core.py了解与Gym兼容的环境所需的所有方法/功能。
The main OpenAI Gym class. It encapsulates an environment with
arbitrary behind-the-scenes dynamics. An environment can be
partially or fully observed.
The main API methods that users of this class need to know are:
step
reset
render
close
seed
And set the following attributes:
action_space: The Space object corresponding to valid actions
observation_space: The Space object corresponding to valid observations
reward_range: A tuple corresponding to the min and max possible rewards
Note: a default reward range set to [-inf,+inf] already exists. Set it if you want a narrower range.
The methods are accessed publicly as "step", "reset", etc.. The
non-underscored versions are wrapper methods to which we may add
functionality over time.
Run Code Online (Sandbox Code Playgroud)