def test_clips_observations(self): history = trax_history.History() self._append_metrics(history, ('eval', 'loss'), [-10, 10]) observations = online_tune.history_to_observations( history, metrics=(('eval', 'loss'), ), observation_range=(-2, 2), include_lr=False, ) np.testing.assert_array_equal(observations, [[-2], [2]])
def test_converts_history_to_observations_without_learning_rate(self): history = trax_history.History() self._append_metrics(history, ('train', 'loss'), [3.0, 1.07]) self._append_metrics(history, ('eval', 'accuracy'), [0.12, 0.68]) observations = online_tune.history_to_observations( history, metrics=(('eval', 'accuracy'), ('train', 'loss')), observation_range=(0, 5), include_lr=False, ) np.testing.assert_array_equal(observations, [[0.12, 3.0], [0.68, 1.07]])
def test_converts_history_to_observations_with_learning_rate(self): history = trax_history.History() self._append_metrics(history, ('train', 'training/learning_rate'), [1e-3, 1e-4]) observations = online_tune.history_to_observations( history, metrics=(), observation_range=(0, 5), include_lr=True, ) self.assertEqual(observations.shape, (2, 1)) ((log_lr_1, ), (log_lr_2, )) = observations self.assertGreater(log_lr_1, log_lr_2)