Exemplo n.º 1
0
    def test_transform_function(self):
        """
        Tests that the transform function works properly by transforming the output of the
        compute method of the black-box function.
        """

        def perf_function(x):
            return x + 2

        bb_obj = BBOptimizer(
            black_box=self.parabola,
            heuristic="surrogate_model",
            max_iteration=nbr_iteration,
            parameter_space=parameter_space,
            perf_function=perf_function,
            regression_model=GaussianProcessRegressor,
            next_parameter_strategy=expected_improvement,
        )
        self.assertEqual(
            bb_obj.compute_result(np.array([5, 0])),
            27,
            "Use of a transformation "
            "function black-box output "
            "did not work properly.",
        )
Exemplo n.º 2
0
 def test_evaluate_fitness_single_item(self):
     """
     Tests that the fitness is properly evaluated when applied on a single numpy array.
     """
     test_parameters = np.array([2, 3])
     expected_result = np.array([13])
     bb_obj = BBOptimizer(
         black_box=self.parabola,
         heuristic="surrogate_model",
         max_iteration=nbr_iteration,
         time_out=time_out,
         parameter_space=parameter_space,
         next_parameter_strategy=expected_improvement,
         regression_model=GaussianProcessRegressor,
     )
     result = bb_obj.compute_result(test_parameters)
     np.testing.assert_array_equal(
         expected_result,
         result,
         "Fitness evaluation on a parameter "
         "single item did not work as "
         "expected.",
     )