简体   繁体   English

如何为我使用 Gym.Scpaces.Box 创建的自定义 Gym 环境正确定义此观察空间?

[英]How to correctly define this Observation Space for the custom Gym environment I am creating using Gym.Scpaces.Box?

I am trying to implement DDPG algorithm of the Paper .我正在尝试实现Paper的 DDPG 算法。

Here in the image below, gk[n] and rk[n] are KxM matrices of real values.在下图中,gk[n] 和 rk[n] 是 KxM 实数值矩阵。 Theta[n] and v[n] are arrays of size M. Theta[n] 和 v[n] 是大小为 M 的 arrays。

I want to write correct code to specify state/observation space in my custom environment .我想编写正确的代码来在我的自定义环境中指定状态/观察空间

Since the data type input to the neural.network needs to be unified, the state array can be expressed as由于需要统一输入到neural.network的数据类型,所以state数组可以表示为

论文中提到的状态空间定义

observation_space = spaces.Box(low=0, high=1, shape=(K, M), dtype=np.float16......)

I am stuck.我卡住了。

If you use stable-baselines3, you may use a Dict observation space filled with Box es with meaningful limits for all your vectors and matrices (if limits are unknown, you may always use +inf/-inf ).如果你使用 stable-baselines3,你可以使用充满Box es 的Dict观察空间,对你的所有向量和矩阵都有有意义的限制(如果限制未知,你可以总是使用+inf/-inf )。 The code could be something like:代码可能是这样的:

from gym import Env
from gym.spaces import Box, Dict

class MySuperGymEnv(Env):
  def __init__(self):
    ...
    spaces = {
       'theta': Box(low=0, high=1, shape=(99,), dtype=np.float32),
       'g': Box(low=0, high=255, shape=(100,200), dtype=np.float32),
       ...
    }
    self.observation_space = Dict(spaces)
    ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM