Beispiel #1
0
    def test_space(self):
        """Tests descrete space.
        """
        s = Space(shape=(), low=0, high=10, dtype=np.int32)
        self._test_space(s, (), 0, 10, np.dtype(np.int32))
        self.assertTrue(s.contains(5))
        self.assertFalse(s.contains(5.))
        self.assertFalse(s.contains(15))

        s = Space(low=0, high=10, dtype=np.int32)
        self._test_space(s, (), 0, 10, np.dtype(np.int32))
Beispiel #2
0
def convert_gym_space(spc):
    """Converts a :gym:`gym.Space <#spaces>` instance to a
    :class:`~texar.tf.agents.Space` instance.

    Args:
        spc: An instance of `gym.Space` or
            :class:`~texar.tf.agents.Space`.
    """
    from texar.tf.agents.agent_utils import Space
    if isinstance(spc, Space):
        return spc
    if isinstance(spc, gym.spaces.Discrete):
        return Space(shape=(), low=0, high=spc.n, dtype=spc.dtype)
    elif isinstance(spc, gym.spaces.Box):
        return Space(shape=spc.shape,
                     low=spc.low,
                     high=spc.high,
                     dtype=spc.dtype)
Beispiel #3
0
    def __init__(self,
                 action_space=None,
                 network=None,
                 network_kwargs=None,
                 hparams=None):
        QNetBase.__init__(self, hparams=hparams)

        with tf.variable_scope(self.variable_scope):
            if action_space is None:
                action_space = Space(
                    low=0, high=self._hparams.action_space, dtype=np.int32)
            self._action_space = action_space
            self._append_output_layer()