iT邦幫忙

第 11 屆 iThome 鐵人賽

DAY 28
0
AI & Data

人工智慧(RL系列) 完爆遊戲30天系列 第 28

Day28 認識Class Discrete

  • 分享至 

  • twitterImage
  •  

跟上章節的Box相比較,Discrete是離散的資料類別

import numpy as np
from .space import Space

類別初始化

def __init__(self, n):
    assert n >= 0
    self.n = n
    super(Discrete, self).__init__((), np.int64)

def sample(self):
    return self.np_random.randint(self.n)

def contains(self, x):
    if isinstance(x, int):
        as_int = x
    elif isinstance(x, (np.generic, np.ndarray)) and (x.dtype.kind in np.typecodes['AllInteger'] and x.shape == ()):
        as_int = int(x)
    else:
        return False
    return as_int >= 0 and as_int < self.n

結語

對於動作控制來說,打電動很適合用Discrete設計,但像是轉方向盤,轉幾度這就要靠Box。其實基本的資料類別就這樣,明天來講講怎麼註冊寫好的自定義環境。

補充參考

OpenAI gym 源碼:https://bre.is/WhrzVNKC


上一篇
Day27 認識Class Box
下一篇
Day29 環境註冊
系列文
人工智慧(RL系列) 完爆遊戲30天30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言