def test_observe_multiple_dimensions(self): observer = action_metrics.ContinuousActionObserver() observer.observe_first(env=_FAKE_ENV, timestep=_TIMESTEP) observer.observe(env=_FAKE_ENV, timestep=_TIMESTEP, action=np.array([[1, 2], [3, 4]])) np.testing.assert_equal( { 'action[0, 0]_max': 1, 'action[0, 0]_min': 1, 'action[0, 0]_mean': 1, 'action[0, 0]_p50': 1, 'action[0, 1]_max': 2, 'action[0, 1]_min': 2, 'action[0, 1]_mean': 2, 'action[0, 1]_p50': 2, 'action[1, 0]_max': 3, 'action[1, 0]_min': 3, 'action[1, 0]_mean': 3, 'action[1, 0]_p50': 3, 'action[1, 1]_max': 4, 'action[1, 1]_min': 4, 'action[1, 1]_mean': 4, 'action[1, 1]_p50': 4, }, observer.get_metrics(), )
def test_observe_zero_dimensions(self): observer = action_metrics.ContinuousActionObserver() observer.observe_first(env=_FAKE_ENV, timestep=_TIMESTEP) observer.observe(env=_FAKE_ENV, timestep=_TIMESTEP, action=np.array(1)) self.assertEqual( { 'action[]_max': 1, 'action[]_min': 1, 'action[]_mean': 1, 'action[]_p50': 1, }, observer.get_metrics(), )
def test_observe_multiple_step(self): observer = action_metrics.ContinuousActionObserver() observer.observe_first(env=_FAKE_ENV, timestep=_TIMESTEP) observer.observe(env=_FAKE_ENV, timestep=_TIMESTEP, action=np.array([1])) observer.observe(env=_FAKE_ENV, timestep=_TIMESTEP, action=np.array([4])) observer.observe(env=_FAKE_ENV, timestep=_TIMESTEP, action=np.array([5])) self.assertEqual( { 'action[0]_max': 5, 'action[0]_min': 1, 'action[0]_mean': 10 / 3, 'action[0]_p50': 4, }, observer.get_metrics(), )
def test_observe_first(self): observer = action_metrics.ContinuousActionObserver() observer.observe_first(env=_FAKE_ENV, timestep=_TIMESTEP) self.assertEqual({}, observer.get_metrics())
def test_observe_nothing(self): observer = action_metrics.ContinuousActionObserver() self.assertEqual({}, observer.get_metrics())