def test_new_best_metric_higher_is_better(self): new_best_metric = actions.NewBestMetric( lambda x: x['value'], higher_is_better=True) self.assertTrue(new_best_metric.test({'value': 0.0})) self.assertTrue(new_best_metric.commit({'value': 0.0})) self.assertFalse(new_best_metric.test({'value': 0.0})) self.assertTrue(new_best_metric.test({'value': 1.0}))
def test_new_best_metric_persistence(self): backing_file = self.create_tempfile() new_best_metric = actions.NewBestMetric( 'value', higher_is_better=True, filename=backing_file.full_path, write_metric=False) self.assertTrue(new_best_metric.test({'value': 0.0})) self.assertTrue(new_best_metric.commit({'value': 0.0})) self.assertFalse(new_best_metric.test({'value': 0.0})) new_best_metric = actions.NewBestMetric( 'value', higher_is_better=True, filename=backing_file.full_path) self.assertLess(new_best_metric.best_value, 0.0) self.assertTrue(new_best_metric.commit({'value': 5.0})) self.assertEqual(new_best_metric.best_value, 5.0) new_best_metric = actions.NewBestMetric( 'value', higher_is_better=True, filename=backing_file.full_path) self.assertEqual(new_best_metric.best_value, 5.0)
def test_new_best_metric_lower_is_better(self): new_best_metric = actions.NewBestMetric('value', higher_is_better=False) self.assertTrue(new_best_metric.test({'value': 0.0})) self.assertTrue(new_best_metric.commit({'value': 0.0})) self.assertFalse(new_best_metric.test({'value': 0.0})) self.assertTrue(new_best_metric.test({'value': -1.0}))
def test_new_best_metric_lower_is_better(self): new_best_metric = actions.NewBestMetric(lambda x: x, higher_is_better=False) self.assertTrue(new_best_metric.test(0.0)) self.assertTrue(new_best_metric.commit(0.0)) self.assertFalse(new_best_metric.test(0.0)) self.assertTrue(new_best_metric.test(-1.0))