本文介绍了如何检查 OpenAI 健身房环境中可用的动作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用OpenAIgym时,用importgy导入库后,可以用env.action_space查看动作空间.但这仅给出了动作空间的大小.我想知道动作空间的每个元素对应什么样的动作.有没有简单的方法来做到这一点?

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?

推荐答案

如果你的动作空间是离散的和一维的,env.action_space 会给你一个 Discrete 对象.您可以像这样访问可用操作的数量(它只是一个整数):

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 = gym.make("Acrobot-v1")
a = env.action_space
print(a)                    #prints Discrete(3)
print(a.n)                  #prints 3

如果你的动作空间是离散的和多维的,你会得到一个 MultiDiscrete(而不是 Discrete)对象,你可以在它上面调用 nvec(而不是 n)来获取描述每个维度可用操作数量的数组.但请注意,这不是很常见的情况.

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.

如果你有一个连续的动作空间,env.action_space 会给你一个 Box 对象.以下是访问其属性的方法:

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

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

这篇关于如何检查 OpenAI 健身房环境中可用的动作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-18 01:49