Advertisement

How to user “Discrete“ object in openai-gym environments?

阅读量:

题意 :怎样在 OpenAI Gym 环境中使用 “Discrete” 对象

问题背景:

My goal is to develop a Q-Learning agent within the OpenAI Gym's Blackjack-v0 environment. While exploring, I aim to determine the dimensions of the observation space, which is presented as a combination of tuple and discrete data structures.

我致力于为 OpenAI Gym 的 "Blackjack-v0" 环境开发一个 Q-Learning 代理,并希望深入了解其观察空间的规模。然而,在当前实现中,观察空间是以元组和离散对象的形式展示的。

我的目标是返回'discrete'对象的大小。
当我在终端中运行'space[0]'时,默认会显示出'Discrete(32)'。
我已经在GitHub上找到了该类(链接),但并未说明如何获取整数值'32'或其他位置的数据如'space[0][5]'。

我的目标仅仅是获取'离散'对象的大小信息。当访问env.observation_space[0]时,系统返回了Discrete(32)这一结果。我参考了GitHub上的相关代码(链接),但并未提供关于如何提取整数值'32'的具体方法,也没有说明如何访问env.observation_space[0][5]处的具体值。

What other functions are available for me to retrieve the dimension of a discrete object and its value at that position?

我可以使用其他函数来返回“离散”对象的大小,以及在某个索引处的值吗?

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

全部评论 (0)

还没有任何评论哟~