python - 如何在 openai-gym 环境中使用“离散”对象?
问题描述
我正在尝试为 openai-gym “Blackjack-v0”环境创建一个 Q-Learning 代理。我试图获得观察空间的大小,但它的形式是“元组”和“离散”对象。
我想要的只是返回“离散”对象的大小。当我打印“env.observation_space[0]”时,它返回“离散(32)”。我在 github 上找到了这个类(https://github.com/openai/gym/blob/master/gym/spaces/discrete.py),但没有显示如何返回整数“32”甚至值在说“env.observation_space[0][5]”。
是否有其他函数可以用来返回“离散”对象的大小以及某个索引处的值本身?
这是一些代码:
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
解决方案
在您的情况下,您可以使用n
Discrete 对象的属性。
例子:
env.observation_space[0].n >> 32
推荐阅读
- python - 使用 PyInstaller 在 MSYS2/MinGW 中编译 GTK 软件的问题
- javascript - 选择子单选按钮时选择容器,未选中时 div 内的链接除外
- c# - 从 2.1 迁移到 3.1 .Net Core,Microsoft.AspNetCore.App 的替代品是什么?
- java - Java While 循环额外条件
- node.js - 无法建立一个或多个指定浏览器连接 / Ubuntu / Firefox Headless
- python - 仅为图像的特定点计算相邻像素的平均像素强度并存储在 n 维数组中
- twitter-bootstrap - 从引导程序 4.1.3 升级到 4.5.0 后,如何修复此按钮布局?
- r - 如何根据某个字符串值重命名列中的某些观察值?
- firebase - 创建用户后 Flutter Firebase 身份验证应用程序崩溃
- javascript - 如何在调整大小时动态地将按钮内的文本居中?