當前位置: 首頁>>代碼示例>>Python>>正文


Python box.Box方法代碼示例

本文整理匯總了Python中gym.spaces.box.Box方法的典型用法代碼示例。如果您正苦於以下問題:Python box.Box方法的具體用法?Python box.Box怎麽用?Python box.Box使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在gym.spaces.box的用法示例。


在下文中一共展示了box.Box方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: check_scaled_actions_from_range

# 需要導入模塊: from gym.spaces import box [as 別名]
# 或者: from gym.spaces.box import Box [as 別名]
def check_scaled_actions_from_range(low, high, scalar=False):
    """
    helper method which creates dummy action space spanning between respective components of low and high
    and then checks scaling to and from tanh co-domain for low, middle and high value from  that action space
    :param low: (np.ndarray), (int) or (float)
    :param high: (np.ndarray), (int) or (float)
    :param scalar: (bool) Whether consider scalar range or wrap it into 1d vector
    """

    if scalar and (isinstance(low, float) or isinstance(low, int)):
        ones = 1.
        action_space = Box(low, high, shape=(1,))
    else:
        low = np.atleast_1d(low)
        high = np.atleast_1d(high)
        ones = np.ones_like(low)
        action_space = Box(low, high)

    mid = 0.5 * (low + high)

    expected_mapping = [(low, -ones), (mid, 0. * ones), (high, ones)]

    for (not_scaled, scaled) in expected_mapping:
        assert np.allclose(scale_action(action_space, not_scaled), scaled)
        assert np.allclose(unscale_action(action_space, scaled), not_scaled) 
開發者ID:Stable-Baselines-Team,項目名稱:stable-baselines,代碼行數:27,代碼來源:test_math_util.py

示例2: __init__

# 需要導入模塊: from gym.spaces import box [as 別名]
# 或者: from gym.spaces.box import Box [as 別名]
def __init__(self, venv, nstack, device=None):
        self.venv = venv
        self.nstack = nstack

        wos = venv.observation_space  # wrapped ob space
        self.shape_dim0 = wos.shape[0]

        low = np.repeat(wos.low, self.nstack, axis=0)
        high = np.repeat(wos.high, self.nstack, axis=0)

        if device is None:
            device = torch.device('cpu')
        self.stacked_obs = torch.zeros((venv.num_envs,) + low.shape).to(device)

        observation_space = gym.spaces.Box(
            low=low, high=high, dtype=venv.observation_space.dtype)
        VecEnvWrapper.__init__(self, venv, observation_space=observation_space) 
開發者ID:montrealrobotics,項目名稱:dal,代碼行數:19,代碼來源:envs.py

示例3: __init__

# 需要導入模塊: from gym.spaces import box [as 別名]
# 或者: from gym.spaces.box import Box [as 別名]
def __init__(self, venv, nstack, device=None):
        self.venv = venv
        self.nstack = nstack

        wos = venv.observation_space  # wrapped ob space
        self.shape_dim0 = wos.shape[0]

        low = np.repeat(wos.low, self.nstack, axis=0)
        high = np.repeat(wos.high, self.nstack, axis=0)

        if device is None:
            device = torch.device('cpu')
        self.stacked_obs = torch.zeros((venv.num_envs, ) +
                                       low.shape).to(device)

        observation_space = gym.spaces.Box(
            low=low, high=high, dtype=venv.observation_space.dtype)
        VecEnvWrapper.__init__(self, venv, observation_space=observation_space) 
開發者ID:ikostrikov,項目名稱:pytorch-a2c-ppo-acktr-gail,代碼行數:20,代碼來源:envs.py

示例4: __init__

# 需要導入模塊: from gym.spaces import box [as 別名]
# 或者: from gym.spaces.box import Box [as 別名]
def __init__(self, venv, nstack, device=None):
        self.venv = venv
        self.nstack = nstack

        wos = venv.observation_space  # wrapped ob space
        self.shape_dim0 = wos.shape[0]

        low = np.repeat(wos.low, self.nstack, axis=0)
        high = np.repeat(wos.high, self.nstack, axis=0)

        if device is None:
            device = torch.device('cpu')
        self.stacked_obs = torch.zeros((venv.num_envs,) + low.shape).to(device)

        observation_space = gym.spaces.Box(
            low=low, high=high, dtype=venv.observation_space.dtype)
        VecEnvWrapper.__init__(
            self, venv, observation_space=observation_space) 
開發者ID:justinglibert,項目名稱:bezos,代碼行數:20,代碼來源:envs.py

示例5: observation_space

# 需要導入模塊: from gym.spaces import box [as 別名]
# 或者: from gym.spaces.box import Box [as 別名]
def observation_space(self):
        """See class definition."""
        speed = Box(
            low=0,
            high=1,
            shape=(self.initial_vehicles.num_vehicles,),
            dtype=np.float32)
        dist_to_intersec = Box(
            low=0.,
            high=np.inf,
            shape=(self.initial_vehicles.num_vehicles,),
            dtype=np.float32)
        edge_num = Box(
            low=0.,
            high=1,
            shape=(self.initial_vehicles.num_vehicles,),
            dtype=np.float32)
        traffic_lights = Box(
            low=0.,
            high=1,
            shape=(3 * self.rows * self.cols,),
            dtype=np.float32)
        return Tuple((speed, dist_to_intersec, edge_num, traffic_lights)) 
開發者ID:flow-project,項目名稱:flow,代碼行數:25,代碼來源:traffic_light_grid.py

示例6: convert_openai_space

# 需要導入模塊: from gym.spaces import box [as 別名]
# 或者: from gym.spaces.box import Box [as 別名]
def convert_openai_space(space):
        from gym.spaces.box import Box
        from gym.spaces.discrete import Discrete
        if isinstance(space, Box):
            return Space(space.low, space.high, False)
        elif isinstance(space, Discrete):
            return Space(0, space.n-1, True)
        else:
            raise ValueError("Does not support other types than Box and Discrete") 
開發者ID:garlicdevs,項目名稱:Fruit-API,代碼行數:11,代碼來源:priv.py

示例7: action_dim

# 需要導入模塊: from gym.spaces import box [as 別名]
# 或者: from gym.spaces.box import Box [as 別名]
def action_dim(self):
        if isinstance(self.env.action_space, Box):
            return self.env.action_space.shape[0]
        else:
            return self.env.action_space.n 
開發者ID:jingweiz,項目名稱:pytorch-rl,代碼行數:7,代碼來源:env.py

示例8: joint_position_space

# 需要導入模塊: from gym.spaces import box [as 別名]
# 或者: from gym.spaces.box import Box [as 別名]
def joint_position_space(self):
        low = np.array(
            [-0.020833, -0.020833, -3.0503, -3.8095, -3.0426, -3.0439, -2.9761,
             -2.9761, -4.7124])
        high = np.array(
            [0.020833, 0.020833, 3.0503, 2.2736, 3.0426, 3.0439, 2.9761,
             2.9761, 4.7124])
        return Box(low, high, dtype=np.float32) 
開發者ID:rlworkgroup,項目名稱:gym-sawyer,代碼行數:10,代碼來源:sawyer.py

示例9: __init__

# 需要導入模塊: from gym.spaces import box [as 別名]
# 或者: from gym.spaces.box import Box [as 別名]
def __init__(self, env=None):
        super(AtariRescale42x42, self).__init__(env)
        self.observation_space = Box(0.0, 1.0, [1, 42, 42]) 
開發者ID:ikostrikov,項目名稱:pytorch-a3c,代碼行數:5,代碼來源:envs.py

示例10: get_space_size

# 需要導入模塊: from gym.spaces import box [as 別名]
# 或者: from gym.spaces.box import Box [as 別名]
def get_space_size(space):
    if isinstance(space, Box):
        return space.shape
    elif isinstance(space, Discrete):
        return [1, ]  # space.n
    else:
        raise NotImplementedError("Assuming to use Box or Discrete, not {}".format(type(space))) 
開發者ID:keiohta,項目名稱:tf2rl,代碼行數:9,代碼來源:get_replay_buffer.py

示例11: test_batch_shape_invariant_to_scaling

# 需要導入模塊: from gym.spaces import box [as 別名]
# 或者: from gym.spaces.box import Box [as 別名]
def test_batch_shape_invariant_to_scaling():
    """
    test that scaling deals well with batches as tensors and numpy matrices in terms of shape
    """
    action_space = Box(np.array([-10., -5., -1.]), np.array([10., 3., 2.]))

    tensor = tf.constant(1., shape=[2, 3])
    matrix = np.ones((2, 3))

    assert scale_action(action_space, tensor).shape == (2, 3)
    assert scale_action(action_space, matrix).shape == (2, 3)

    assert unscale_action(action_space, tensor).shape == (2, 3)
    assert unscale_action(action_space, matrix).shape == (2, 3) 
開發者ID:Stable-Baselines-Team,項目名稱:stable-baselines,代碼行數:16,代碼來源:test_math_util.py

示例12: __init__

# 需要導入模塊: from gym.spaces import box [as 別名]
# 或者: from gym.spaces.box import Box [as 別名]
def __init__(self, env=None):
        super(TransposeImage, self).__init__(env)
        obs_shape = self.observation_space.shape
        self.observation_space = Box(
            self.observation_space.low[0, 0, 0],
            self.observation_space.high[0, 0, 0],
            [obs_shape[2], obs_shape[1], obs_shape[0]],
            dtype=self.observation_space.dtype) 
開發者ID:ShangtongZhang,項目名稱:DeepRL,代碼行數:10,代碼來源:envs.py

示例13: step

# 需要導入模塊: from gym.spaces import box [as 別名]
# 或者: from gym.spaces.box import Box [as 別名]
def step(self, actions):
        if isinstance(self.action_space, Box):
            actions = np.clip(actions, self.action_space.low, self.action_space.high)
        return self.env.step(actions) 
開發者ID:ShangtongZhang,項目名稱:DeepRL,代碼行數:6,代碼來源:envs.py

示例14: __init__

# 需要導入模塊: from gym.spaces import box [as 別名]
# 或者: from gym.spaces.box import Box [as 別名]
def __init__(self, env=None):
        super(AddTimestep, self).__init__(env)
        self.observation_space = Box(
            self.observation_space.low[0],
            self.observation_space.high[0],
            [self.observation_space.shape[0] + 1],
            dtype=self.observation_space.dtype) 
開發者ID:maximecb,項目名稱:gym-miniworld,代碼行數:9,代碼來源:envs.py

示例15: observation_space

# 需要導入模塊: from gym.spaces import box [as 別名]
# 或者: from gym.spaces.box import Box [as 別名]
def observation_space(self):
    # Return the observation space adjusted to match the shape of the processed
    # observations.
    return Box(low=0, high=255, shape=(self.screen_size, self.screen_size, 1),
               dtype=np.uint8) 
開發者ID:google-research,項目名稱:seed_rl,代碼行數:7,代碼來源:atari_preprocessing.py


注:本文中的gym.spaces.box.Box方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。