【问题标题】:What does spaces.Discrete mean in OpenAI GymSpaces.Discrete 在 OpenAI Gym 中是什么意思
【发布时间】:2019-12-26 05:37:31
【问题描述】:

我尝试使用 openAI Gym 学习在二十一点中应用的 MC-蒙特卡洛方法。而且我不明白这些行:

def __init__(self, natural=False):
    self.action_space = spaces.Discrete(2)
    self.observation_space = spaces.Tuple((
        spaces.Discrete(32),
        spaces.Discrete(11),
        spaces.Discrete(2)))
    self.seed()

来源:https://github.com/openai/gym/blob/master/gym/envs/toy_text/blackjack.py

【问题讨论】:

    标签: python-3.x openai-gym blackjack


    【解决方案1】:

    观察空间和动作空间已经定义在cmetshere

    观察空间:

    The observation of a 3-tuple of: the player's current sum,
    the dealer's one showing card (1-10 where 1 is ace),
    and whether or not the player holds a usable ace (0 or 1).
    
    eg: (14, 9, False) means the current sum is 14, card shown is 9 and there is no usable ace(because ace can be used as 1 or 11)
    

    动作空间:

    The player can request additional cards (hit=1) until they decide to stop
    (stick=0) or exceed 21 (bust).
    

    当我们在环境中定义一个离散的动作/观察空间时,使用离散空间。所以spaces.Discrete(2) 意味着我们有一个离散变量,它可以取两个可能值之一。

    在二十一点环境中,

    self.action_space = spaces.Discrete(2)
    # here spaces.Discrete(2) means that action can either be True or False.
    
    self.observation_space = spaces.Tuple((
            spaces.Discrete(32),
            spaces.Discrete(11),
            spaces.Discrete(2)))
    # here spaces.Discrete(32) corresponds to the 32 possible sum of card number possible
    # here spaces.Discrete(11) corresponds to the 11 possible cards which can be dealed
    # by the dealer: [1,2,3,4,5,6,7,8,9,10(king,queen,jack),11(ace if possible)]
    # here spaces.Discrete(2) corresponds to the two possible uses of the ace: [True, False]
    # True if it can be used as 11.
    
    

    【讨论】:

    • 32个可能的卡号总和是多少?如何获得 32 个可能的总和?谢谢!
    • @doob 我猜你错过了“对三元组的观察:玩家当前的总和,庄家的一张牌(1-10,其中 1 是王牌),以及玩家是否持有可用的王牌(0 或 1)。”在注释中。玩家当前总和最小为 1,而当当前总和为“21”时玩家抽出“ace”时获得最大总和。 32 肯定是由 11 + 21 计算出来的。即使我认为最大总和应该是 30 x 10 + 20 )
    • @doob, Discrete(32) 在这个空间中有 32 个可能的值。取值范围其实是[0, 31],即最大和应该是31 = 11 (ace) + 10 + 10。另请参考this discussion
    猜你喜欢
    • 2021-08-10
    • 2017-01-13
    • 2022-10-08
    • 2011-08-12
    • 2017-06-11
    • 2018-03-05
    • 2023-03-27
    • 2016-08-17
    • 2010-12-28
    相关资源
    最近更新 更多