Exemple #1
0
 def test_fitness_gain_per_iteration(self):
     """
     Tests that the fitness gain per iteration is properly computed.
     """
     history = {
         "fitness": np.array([10, 5, 6, 2, 15, 4]),
         "parameters": np.array([[1, 2], [2, 3], [1, 3], [4, 3], [2, 1], [1, 5]]),
         "truncated": np.array([True, True, True, True, True, True]),
     }
     bb_obj = BBOptimizer(
         black_box=self.parabola,
         heuristic="surrogate_model",
         max_iteration=nbr_iteration,
         initial_sample_size=2,
         parameter_space=parameter_space,
         next_parameter_strategy=expected_improvement,
         regression_model=GaussianProcessRegressor,
     )
     bb_obj.history = history
     bb_obj.launched = True
     expected_gain_per_iteration = np.array([-5, 1, -4, 13, -11])
     np.testing.assert_array_equal(
         expected_gain_per_iteration,
         bb_obj.fitness_gain_per_iteration,
         "Computation of fitness gain per iteration did not work as " "expected.",
     )
Exemple #2
0
 def test_fitness_gain_per_iteration_not_launched(self):
     """
     Tests that the fitness gain per iteration is None if the experiment is not launched.
     """
     bb_obj = BBOptimizer(
         black_box=self.parabola,
         heuristic="surrogate_model",
         max_iteration=nbr_iteration,
         initial_sample_size=2,
         parameter_space=parameter_space,
         next_parameter_strategy=expected_improvement,
         regression_model=GaussianProcessRegressor,
     )
     bb_obj.launched = False
     self.assertEqual(bb_obj.fitness_gain_per_iteration, None)