Пример #1
0
def test_observation_space():
    observation_space = ObservationSpace(np.array([1, 10]), -10, 10)

    # testing that val_matches_space_definition works
    assert observation_space.val_matches_space_definition(np.ones([1, 10]))
    assert not observation_space.val_matches_space_definition(np.ones([2, 10]))
    assert not observation_space.val_matches_space_definition(
        np.ones([1, 10]) * 100)
    assert not observation_space.val_matches_space_definition(
        np.ones([1, 1, 10]))

    # is_point_in_space_shape
    assert observation_space.is_point_in_space_shape(np.array([0, 9]))
    assert observation_space.is_point_in_space_shape(np.array([0, 0]))
    assert not observation_space.is_point_in_space_shape(np.array([1, 8]))
    assert not observation_space.is_point_in_space_shape(np.array([0, 10]))
    assert not observation_space.is_point_in_space_shape(np.array([-1, 6]))
 def validate_input_observation_space(
         self, input_observation_space: ObservationSpace):
     if len(
             self.stack
     ) > 0 and not input_observation_space.val_matches_space_definition(
             self.stack[-1]):
         raise ValueError(
             "The given input observation space is different than the observations already stored in"
             "the filters memory")
     if input_observation_space.num_dimensions <= self.stacking_axis:
         raise ValueError(
             "The stacking axis is larger than the number of dimensions in the observation space"
         )