[英]How to correctly define this Observation Space for the custom Gym environment I am creating using Gym.Scpaces.Box?
[英]How to define action space in custom gym environment that receives 3 scalers and a matrix each turn?
對於個人項目,我需要定義一個運行特定棋盤游戲的自定義健身房環境。 游戲的每一輪,環境都將棋盤的狀態作為一個由 1 和 0 組成的矩陣,以及一個動作——描述為一個元組:
(整數,整數,小矩陣)
通過在線閱讀,我知道健身房環境應該是這樣的:
class CustomEnv(gym.Env):
"""Custom Environment that follows gym interface"""
metadata = {'render.modes': ['human']}
def __init__(self, arg1, arg2, ...):
super(CustomEnv, self).__init__()
self.action_space =
self.observation_space =
def step(self, action):
...
def reset(self):
...
def render(self, mode='human', close=False):
現在,我覺得這里的動作輸入並不完全屬於“離散”或“連續”——我應該如何實現 init 函數和 step 函數的動作部分?
使用gym的元組空間在init函數中定義你的動作空間是相當簡單的:
from gym import spaces
space = spaces.Tuple((
spaces.Discrete(5),
spaces.Discrete(4),
spaces.Box(low=0, high=1, shape=(2, 2))))
Discrete 空間表示整數范圍,Box 空間表示 n 維數組。 您可以打印您的空間樣本以了解它的外觀:
print(space.sample())
>>> (3, 1, array([[0.20318432, 0.26787955], [0.5323673 , 0.6564413 ]], dtype=float32))
對於 step 函數,您只需要根據輸入操作與您的環境進行交互,其格式將與示例一樣。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.