Пример #1
0
 def test_optimizer_simple_resampling_noresample(self):
     """Tests that the _select_next_parameters_method works as expected
     when using simple resampling strategy and the parameters should not be resampled"""
     np.random.seed(1)
     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,
         resampling_policy="simple_resampling",
         nbr_resamples=2,
     )
     bb_obj.history = {
         "fitness": np.array([10, 5, 4, 2, 15, 20]),
         "parameters": np.array(
             [[1, 2, 3], [2, 3, 3], [1, 3, 3], [1, 5, 3], [1, 1, 3], [1, 5, 3]]
         ),
         "truncated": np.array([True, True, True, True, True, True]),
         "resampled": np.array([True, True, True, True, True, True]),
         "initialization": np.array([True, True, True, True, True, True]),
     }
     parameter = bb_obj._select_next_parameters()
     np.testing.assert_array_equal(parameter, [1, 3, 2])
Пример #2
0
 def test_select_parameters(self):
     """Test the function _select_next_parameters when there is no retry."""
     np.random.seed(10)
     bb_obj = BBOptimizer(
         black_box=self.parabola,
         heuristic="surrogate_model",
         max_iteration=1,
         initial_sample_size=2,
         parameter_space=parameter_space,
         next_parameter_strategy=expected_improvement,
         regression_model=GaussianProcessRegressor,
     )
     bb_obj._initialize()
     parameter = bb_obj._select_next_parameters()
     np.testing.assert_array_equal(parameter, np.array([-5, 2, -6]))