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


Python gym.GoalEnv方法代码示例

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


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

示例1: _check_obs

# 需要导入模块: import gym [as 别名]
# 或者: from gym import GoalEnv [as 别名]
def _check_obs(obs: Union[tuple, dict, np.ndarray, int],
               observation_space: spaces.Space,
               method_name: str) -> None:
    """
    Check that the observation returned by the environment
    correspond to the declared one.
    """
    if not isinstance(observation_space, spaces.Tuple):
        assert not isinstance(obs, tuple), ("The observation returned by the `{}()` "
                                            "method should be a single value, not a tuple".format(method_name))

    # The check for a GoalEnv is done by the base class
    if isinstance(observation_space, spaces.Discrete):
        assert isinstance(obs, int), "The observation returned by `{}()` method must be an int".format(method_name)
    elif _enforce_array_obs(observation_space):
        assert isinstance(obs, np.ndarray), ("The observation returned by `{}()` "
                                             "method must be a numpy array".format(method_name))

    assert observation_space.contains(obs), ("The observation returned by the `{}()` "
                                             "method does not match the given observation space".format(method_name)) 
开发者ID:Stable-Baselines-Team,项目名称:stable-baselines,代码行数:22,代码来源:env_checker.py

示例2: _check_unsupported_obs_spaces

# 需要导入模块: import gym [as 别名]
# 或者: from gym import GoalEnv [as 别名]
def _check_unsupported_obs_spaces(env: gym.Env, observation_space: spaces.Space) -> None:
    """Emit warnings when the observation space used is not supported by Stable-Baselines."""

    if isinstance(observation_space, spaces.Dict) and not isinstance(env, gym.GoalEnv):
        warnings.warn("The observation space is a Dict but the environment is not a gym.GoalEnv "
                      "(cf https://github.com/openai/gym/blob/master/gym/core.py), "
                      "this is currently not supported by Stable Baselines "
                      "(cf https://github.com/hill-a/stable-baselines/issues/133), "
                      "you will need to use a custom policy. "
                      )

    if isinstance(observation_space, spaces.Tuple):
        warnings.warn("The observation space is a Tuple,"
                      "this is currently not supported by Stable Baselines "
                      "(cf https://github.com/hill-a/stable-baselines/issues/133), "
                      "you will need to flatten the observation and maybe use a custom policy. "
                      ) 
开发者ID:Stable-Baselines-Team,项目名称:stable-baselines,代码行数:19,代码来源:env_checker.py

示例3: __init__

# 需要导入模块: import gym [as 别名]
# 或者: from gym import GoalEnv [as 别名]
def __init__(self, bit_length=16, max_steps=None):

        super(BitFlip, self).__init__()

        assert bit_length >= 1, 'bit_length must be >= 1, found {}'.format(bit_length)

        self.bit_length = bit_length

        if max_steps is None:
            self.max_steps = bit_length
        else:
            self.max_steps = max_steps

        self.last_action = -1  # -1 for reset
        self.steps = 0
        self.seed()
        self.action_space = spaces.Discrete(bit_length + 1)  # index = n means to not flip any bit
        # achieved goal and observation are identical in bit_flip environment, however it is made this way to be
        # compatible with Openai GoalEnv
        self.observation_space = spaces.Dict(dict(
            observation=spaces.Box(low=0, high=1, shape=(bit_length,), dtype=np.int32),
            achieved_goal=spaces.Box(low=0, high=1, shape=(bit_length,), dtype=np.int32),
            desired_goal=spaces.Box(low=0, high=1, shape=(bit_length,), dtype=np.int32),
        ))

        self.reset() 
开发者ID:rlgraph,项目名称:rlgraph,代码行数:28,代码来源:bit_flip.py

示例4: _check_returned_values

# 需要导入模块: import gym [as 别名]
# 或者: from gym import GoalEnv [as 别名]
def _check_returned_values(env: gym.Env, observation_space: spaces.Space, action_space: spaces.Space) -> None:
    """
    Check the returned values by the env when calling `.reset()` or `.step()` methods.
    """
    # because env inherits from gym.Env, we assume that `reset()` and `step()` methods exists
    obs = env.reset()

    _check_obs(obs, observation_space, 'reset')

    # Sample a random action
    action = action_space.sample()
    data = env.step(action)

    assert len(data) == 4, "The `step()` method must return four values: obs, reward, done, info"

    # Unpack
    obs, reward, done, info = data

    _check_obs(obs, observation_space, 'step')

    # We also allow int because the reward will be cast to float
    assert isinstance(reward, (float, int)), "The reward returned by `step()` must be a float"
    assert isinstance(done, bool), "The `done` signal must be a boolean"
    assert isinstance(info, dict), "The `info` returned by `step()` must be a python dictionary"

    if isinstance(env, gym.GoalEnv):
        # For a GoalEnv, the keys are checked at reset
        assert reward == env.compute_reward(obs['achieved_goal'], obs['desired_goal'], info) 
开发者ID:Stable-Baselines-Team,项目名称:stable-baselines,代码行数:30,代码来源:env_checker.py

示例5: setup_class

# 需要导入模块: import gym [as 别名]
# 或者: from gym import GoalEnv [as 别名]
def setup_class(cls):
        """Initialise the class."""
        cls.env = gym.GoalEnv()
        configuration = ConnectionConfig(connection_id=GymConnection.connection_id)
        identity = Identity("name", address="my_key")
        cls.gym_con = GymConnection(
            gym_env=cls.env, identity=identity, configuration=configuration
        )
        cls.gym_con.channel = GymChannel("my_key", gym.GoalEnv())
        cls.gym_con._connection = None 
开发者ID:fetchai,项目名称:agents-aea,代码行数:12,代码来源:test_gym.py


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