我正在尝试为openai-gym "Blackjack-v0“环境创建一个Q-Learning代理。我试图得到观察空间的大小,但它是以“元组”和“离散”对象的形式出现的。
我只想返回“离散”对象的大小。当我打印"env.observation_space“时,它返回”离散(32)“。我在github (https://github.com/openai/gym/blob/master/gym/spaces/discrete.py)上找到了这个类,但没有任何东西显示如何返回整数"32“,甚至返回"env.observation_space”处的值。
有没有其他函数可以用来返回“离散”对象的大小,以及某个索引处的值本身?
下面是一些代码:
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发布于 2020-03-18 01:40:37
在您的情况下,可以使用离散对象的属性n。
示例:
env.observation_space[0].n >> 32发布于 2020-12-28 19:26:00
您还可以使用环境对象的属性nA。
示例:
env.nA >> 32环境对象还具有属性nS --提供状态的数量。
https://stackoverflow.com/questions/55961541
复制相似问题