action_space 有什么用?

What is the action_space for?

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

gym环境中使用的action_space是用来定义环境动作space的特征。这样,就可以说明动作 space 是连续的还是离散的,定义动作的最小值和最大值等

连续动作space可以使用Boxclass。

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 class.

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 gym 存储库中的 this 文件夹。您还可以通过 gym 文件夹中给出的不同环境来获取 action_spaceobservation_space.

用法的更多示例

此外,通过 core.py 了解所有 methods/functions 是与健身房兼容的环境所必需的。

    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.