当前位置: 首页>>代码示例>>Python>>正文


Python specs.BoundedArray方法代码示例

本文整理汇总了Python中dm_env.specs.BoundedArray方法的典型用法代码示例。如果您正苦于以下问题:Python specs.BoundedArray方法的具体用法?Python specs.BoundedArray怎么用?Python specs.BoundedArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在dm_env.specs的用法示例。


在下文中一共展示了specs.BoundedArray方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _spec_to_box

# 需要导入模块: from dm_env import specs [as 别名]
# 或者: from dm_env.specs import BoundedArray [as 别名]
def _spec_to_box(spec):
    def extract_min_max(s):
        assert s.dtype == np.float64 or s.dtype == np.float32
        dim = np.int(np.prod(s.shape))
        if type(s) == specs.Array:
            bound = np.inf * np.ones(dim, dtype=np.float32)
            return -bound, bound
        elif type(s) == specs.BoundedArray:
            zeros = np.zeros(dim, dtype=np.float32)
            return s.minimum + zeros, s.maximum + zeros

    mins, maxs = [], []
    for s in spec:
        mn, mx = extract_min_max(s)
        mins.append(mn)
        maxs.append(mx)
    low = np.concatenate(mins, axis=0)
    high = np.concatenate(maxs, axis=0)
    assert low.shape == high.shape
    return spaces.Box(low, high, dtype=np.float32) 
开发者ID:denisyarats,项目名称:dmc2gym,代码行数:22,代码来源:wrappers.py

示例2: _convert_spec_to_space

# 需要导入模块: from dm_env import specs [as 别名]
# 或者: from dm_env.specs import BoundedArray [as 别名]
def _convert_spec_to_space(spec):
    if isinstance(spec, dict):
        return spaces.Dict(
            {k: _convert_spec_to_space(v)
             for k, v in spec.items()})
    if isinstance(spec, specs.DiscreteArray):
        return spaces.Discrete(spec.num_values)
    elif isinstance(spec, specs.BoundedArray):
        return spaces.Box(
            low=np.asscalar(spec.minimum),
            high=np.asscalar(spec.maximum),
            shape=spec.shape,
            dtype=spec.dtype)
    elif isinstance(spec, specs.Array):
        return spaces.Box(
            low=-float("inf"),
            high=float("inf"),
            shape=spec.shape,
            dtype=spec.dtype)

    raise NotImplementedError(
        ("Could not convert `Array` spec of type {} to Gym space. "
         "Attempted to convert: {}").format(type(spec), spec)) 
开发者ID:ray-project,项目名称:ray,代码行数:25,代码来源:dm_env_wrapper.py

示例3: action_spec

# 需要导入模块: from dm_env import specs [as 别名]
# 或者: from dm_env.specs import BoundedArray [as 别名]
def action_spec(self, physics):
    """Returns a `BoundedArray` spec matching the `Physics` actuators.

    BoundedArray.name should contain a tab-separated list of actuator names.
    When overloading this method, non-MuJoCo actuators should be added to the
    top of the list when possible, as a matter of convention.

    Args:
      physics: used to query actuator names in the model.
    """
    names = [physics.model.id2name(i, 'actuator') or str(i)
             for i in range(physics.model.nu)]
    action_spec = mujoco.action_spec(physics)
    return specs.BoundedArray(shape=action_spec.shape,
                              dtype=action_spec.dtype,
                              minimum=action_spec.minimum,
                              maximum=action_spec.maximum,
                              name='\t'.join(names)) 
开发者ID:deepmind,项目名称:dm_control,代码行数:20,代码来源:task.py

示例4: array_spec

# 需要导入模块: from dm_env import specs [as 别名]
# 或者: from dm_env.specs import BoundedArray [as 别名]
def array_spec(self):
    if self._depth:
      # Note that these are loose bounds - the exact bounds are given by:
      # extent*(znear, zfar), however the values of these parameters are unknown
      # since we don't have access to the compiled model within this method.
      minimum = 0.0
      maximum = np.inf
    elif self._segmentation:
      # -1 denotes background pixels. See dm_control.mujoco.Camera.render for
      # further details.
      minimum = -1
      maximum = np.iinfo(self._dtype).max
    else:
      minimum = np.iinfo(self._dtype).min
      maximum = np.iinfo(self._dtype).max

    return specs.BoundedArray(
        minimum=minimum,
        maximum=maximum,
        shape=(self._height, self._width, self._n_channels),
        dtype=self._dtype) 
开发者ID:deepmind,项目名称:dm_control,代码行数:23,代码来源:mjcf.py

示例5: convert_dm_control_to_gym_space

# 需要导入模块: from dm_env import specs [as 别名]
# 或者: from dm_env.specs import BoundedArray [as 别名]
def convert_dm_control_to_gym_space(dm_control_space):
    r"""Convert dm_control space to gym space. """
    if isinstance(dm_control_space, specs.BoundedArray):
        space = spaces.Box(low=dm_control_space.minimum, 
                           high=dm_control_space.maximum, 
                           dtype=dm_control_space.dtype)
        assert space.shape == dm_control_space.shape
        return space
    elif isinstance(dm_control_space, specs.Array) and not isinstance(dm_control_space, specs.BoundedArray):
        space = spaces.Box(low=-float('inf'), 
                           high=float('inf'), 
                           shape=dm_control_space.shape, 
                           dtype=dm_control_space.dtype)
        return space
    elif isinstance(dm_control_space, dict):
        space = spaces.Dict({key: convert_dm_control_to_gym_space(value)
                             for key, value in dm_control_space.items()})
        return space 
开发者ID:zuoxingdong,项目名称:dm2gym,代码行数:20,代码来源:dm_suite_env.py

示例6: act

# 需要导入模块: from dm_env import specs [as 别名]
# 或者: from dm_env.specs import BoundedArray [as 别名]
def act(self):
    action = {}

    for name, spec in self.action_spec.items():
      # Uniformly sample BoundedArray actions.
      if isinstance(spec, specs.BoundedArray):
        action[name] = np.random.uniform(spec.minimum, spec.maximum, spec.shape)
      else:
        action[name] = spec.generate_value()
    return action 
开发者ID:deepmind,项目名称:dm_memorytasks,代码行数:12,代码来源:random_agent.py

示例7: observation_spec

# 需要导入模块: from dm_env import specs [as 别名]
# 或者: from dm_env.specs import BoundedArray [as 别名]
def observation_spec(self):
    """Returns the observation spec."""
    return specs.BoundedArray(shape=self._board.shape, dtype=self._board.dtype,
                              name="board", minimum=0, maximum=1) 
开发者ID:deepmind,项目名称:dm_env,代码行数:6,代码来源:catch.py

示例8: discount_spec

# 需要导入模块: from dm_env import specs [as 别名]
# 或者: from dm_env.specs import BoundedArray [as 别名]
def discount_spec(self):
    """Describes the discount returned by the environment.

    By default this is assumed to be a single float between 0 and 1.

    Returns:
      An `Array` spec, or a nested dict, list or tuple of `Array` specs.
    """
    return specs.BoundedArray(
        shape=(), dtype=float, minimum=0., maximum=1., name='discount') 
开发者ID:deepmind,项目名称:dm_env,代码行数:12,代码来源:_environment.py

示例9: testInvalidMinimum

# 需要导入模块: from dm_env import specs [as 别名]
# 或者: from dm_env.specs import BoundedArray [as 别名]
def testInvalidMinimum(self):
    with six.assertRaisesRegex(self, ValueError, "not compatible"):
      specs.BoundedArray((3, 5), np.uint8, (0, 0, 0), (1, 1)) 
开发者ID:deepmind,项目名称:dm_env,代码行数:5,代码来源:specs_test.py

示例10: testInvalidMaximum

# 需要导入模块: from dm_env import specs [as 别名]
# 或者: from dm_env.specs import BoundedArray [as 别名]
def testInvalidMaximum(self):
    with six.assertRaisesRegex(self, ValueError, "not compatible"):
      specs.BoundedArray((3, 5), np.uint8, 0, (1, 1, 1)) 
开发者ID:deepmind,项目名称:dm_env,代码行数:5,代码来源:specs_test.py

示例11: testMinMaxAttributes

# 需要导入模块: from dm_env import specs [as 别名]
# 或者: from dm_env.specs import BoundedArray [as 别名]
def testMinMaxAttributes(self):
    spec = specs.BoundedArray((1, 2, 3), np.float32, 0, (5, 5, 5))
    self.assertEqual(type(spec.minimum), np.ndarray)
    self.assertEqual(type(spec.maximum), np.ndarray) 
开发者ID:deepmind,项目名称:dm_env,代码行数:6,代码来源:specs_test.py

示例12: testReadOnly

# 需要导入模块: from dm_env import specs [as 别名]
# 或者: from dm_env.specs import BoundedArray [as 别名]
def testReadOnly(self):
    spec = specs.BoundedArray((1, 2, 3), np.float32, 0, (5, 5, 5))
    with six.assertRaisesRegex(self, ValueError, "read-only"):
      spec.minimum[0] = -1
    with six.assertRaisesRegex(self, ValueError, "read-only"):
      spec.maximum[0] = 100 
开发者ID:deepmind,项目名称:dm_env,代码行数:8,代码来源:specs_test.py

示例13: testEqualBroadcastingBounds

# 需要导入模块: from dm_env import specs [as 别名]
# 或者: from dm_env.specs import BoundedArray [as 别名]
def testEqualBroadcastingBounds(self):
    spec_1 = specs.BoundedArray(
        (1, 2), np.float32, minimum=0.0, maximum=1.0)
    spec_2 = specs.BoundedArray(
        (1, 2), np.float32, minimum=[0.0, 0.0], maximum=[1.0, 1.0])
    self.assertEqual(spec_1, spec_2) 
开发者ID:deepmind,项目名称:dm_env,代码行数:8,代码来源:specs_test.py

示例14: testNotEqualDifferentMinimum

# 需要导入模块: from dm_env import specs [as 别名]
# 或者: from dm_env.specs import BoundedArray [as 别名]
def testNotEqualDifferentMinimum(self):
    spec_1 = specs.BoundedArray(
        (1, 2), np.float32, minimum=[0.0, -0.6], maximum=[1.0, 1.0])
    spec_2 = specs.BoundedArray(
        (1, 2), np.float32, minimum=[0.0, 0.0], maximum=[1.0, 1.0])
    self.assertNotEqual(spec_1, spec_2) 
开发者ID:deepmind,项目名称:dm_env,代码行数:8,代码来源:specs_test.py

示例15: testNotEqualOtherClass

# 需要导入模块: from dm_env import specs [as 别名]
# 或者: from dm_env.specs import BoundedArray [as 别名]
def testNotEqualOtherClass(self):
    spec_1 = specs.BoundedArray(
        (1, 2), np.float32, minimum=[0.0, -0.6], maximum=[1.0, 1.0])
    spec_2 = specs.Array((1, 2), np.float32)
    self.assertNotEqual(spec_1, spec_2)
    self.assertNotEqual(spec_2, spec_1)

    spec_2 = None
    self.assertNotEqual(spec_1, spec_2)
    self.assertNotEqual(spec_2, spec_1)

    spec_2 = ()
    self.assertNotEqual(spec_1, spec_2)
    self.assertNotEqual(spec_2, spec_1) 
开发者ID:deepmind,项目名称:dm_env,代码行数:16,代码来源:specs_test.py


注:本文中的dm_env.specs.BoundedArray方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。