Advertisement

How to check the actions available in OpenAI gym environment?

阅读量:

题意 :如何检查 OpenAI Gym 环境中可用的动作?

问题背景:

When using OpenAI gym, after importing the library with import gym, the action space can be checked with env.action_space. But this gives only the size of the action space. I would like to know what kind of actions each element of the action space corresponds to. Is there a simple way to do it?

在使用 OpenAI Gym 时,导入库(import gym)后,可以通过 env.action_space 检查动作空间。但这仅返回动作空间的大小。我想知道动作空间中每个元素对应的具体动作类型。有简单的方法可以做到吗?

问题解决:

If your action space is discrete and one dimensional, env.action_space will give you a Discrete object. You can access the number of actions available (which simply is an integer) like this:

如果你的动作空间是离散且一维的,env.action_space 会返回一个 Discrete 对象。你可以通过如下方式访问可用动作的数量(这只是一个整数):

复制代码
 env = gym.make("Acrobot-v1")

    
 a = env.action_space
    
 print(a)                    #prints Discrete(3)
    
 print(a.n)                  #prints 3
    
    
    
    

If your action space is discrete and multi dimensional, you'd get a MultiDiscrete (instead of Discrete) object, on which you can call nvec (instead of n) to get an array describing the number of available action for each dimension. But note that it is not a very common case.

如果你的动作空间是离散且多维的,你会得到一个 MultiDiscrete 对象(而不是 Discrete),你可以调用 nvec(而不是 n)来获取一个数组,该数组描述每个维度中可用的动作数量。但请注意,这种情况并不常见。

If you have a continous action space, env.action_space will give you a Box object. Here is how to access its properties:

如果你的动作空间是连续的,env.action_space 会返回一个 Box 对象。你可以通过以下方式访问它的属性:

复制代码
 env = gym.make("MountainCarContinuous-v0")

    
 a = env.action_space
    
 print(a)                    #prints Box(1,)
    
 print(a.shape)              #prints (1,), note that you can do a.shape[0] which is 1 here
    
 print(a.is_bounded())       #prints True if your action space is bounded
    
 print(a.high)               #prints [1.] an array with the maximum value for each dim
    
 print(a.low)                #prints [-1.] same for minimum value
    
    
    
    

全部评论 (0)

还没有任何评论哟~