action_space是做什么用的?

时间:2019-06-17 15:00:32

标签: openai-gym

我正在OpenAI Gym中创建自定义环境,真的不明白,action_space是做什么的?我应该放什么呢?准确地说,我不知道什么是action_space,我没有在任何代码中使用它。而且我没有在互联网上找到任何东西,什么可以正常回答我的问题。

1 个答案:

答案 0 :(得分:0)

在体育馆环境中使用的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)

对于离散的用户,可以使用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)

如果您有任何其他要求,可以通过OpenAI体育馆仓库中的this文件夹。您还可以遍历Gym文件夹中提供的不同环境,以获取有关action_spaceobservation_space用法的更多示例。

此外,请通过core.py来了解使环境与健身室兼容所需的所有方法/功能。

    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.