本文主要是介绍How to user “Discrete“ object in openai-gym environments?,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
题意:怎样在 OpenAI Gym 环境中使用 “Discrete” 对象
问题背景:
I am trying to create a Q-Learning agent for a openai-gym "Blackjack-v0" environment. I am trying to get the size of the observation space but its in a form a "tuples" and "discrete" objects.
我正在尝试为 OpenAI Gym 的 "Blackjack-v0" 环境创建一个 Q-Learning 代理。我想获取观察空间的大小,但它是以“元组”和“离散”对象的形式呈现的。
All I want is to return the size of the "discrete" object. When I print "env.observation_space[0]", it returns "Discrete(32)". I've found the class on github (https://github.com/openai/gym/blob/master/gym/spaces/discrete.py), but nothing is showing how to return the integer "32" or even the value at say "env.observation_space[0][5]".
我只想返回“离散”对象的大小。当我打印 `env.observation_space[0]` 时,它返回 `Discrete(32)`。我在 GitHub 上找到了对应的类([链接](https://github.com/openai/gym/blob/master/gym/spaces/discrete.py)),但没有显示如何返回整数“32”,甚至没有显示如何获取 `env.observation_space[0][5]` 处的值。
Is there other functions I can use to return the size of the "discrete" object, and the value itself at a certain index?
我可以使用其他函数来返回“离散”对象的大小,以及在某个索引处的值吗?
Here is some code: 以下是某些代码:
print(state_size[0]) # Discrete(32)
# I want it to print 32, not Discrete(32)
print(state_size[1]) # Discrete(11)
# I want it to print 11, not Discrete(11)
print(state_size[2]) # Discrete(2)
# I want it to print 2, not Discrete(2)print(q_table[state_size[0][0]]) # TypeError: 'Discrete' object does not support indexing
# I want to return the value of the "Discrete" object
问题解决:
In your case you can use the attribute n
of Discrete object.
在你的情况下,你可以使用 `Discrete` 对象的 `n` 属性。
Example:
env.observation_space[0].n >> 32
这篇关于How to user “Discrete“ object in openai-gym environments?的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!