def test_loop():
    n_iterations = 5

    x_init = np.random.rand(5, 1)
    y_init = np.random.rand(5, 1)

    # Make GPy model
    gpy_model = GPy.models.GPRegression(x_init, y_init)
    model = GPyModelWrapper(gpy_model)

    space = ParameterSpace([ContinuousParameter('x', 0, 1)])
    acquisition = ExpectedImprovement(model)

    # Make loop and collect points
    bo = BayesianOptimizationLoop(model=model,
                                  space=space,
                                  acquisition=acquisition)
    bo.run_loop(UserFunctionWrapper(f),
                FixedIterationsStoppingCondition(n_iterations))

    # Check we got the correct number of points
    assert bo.loop_state.X.shape[0] == n_iterations + 5

    # Check the obtained results
    results = bo.get_results()

    assert results.minimum_location.shape[0] == 1
    assert results.best_found_value_per_iteration.shape[0] == n_iterations + 5
예제 #2
0
def test_loop():
    n_iterations = 5

    x_init = np.random.rand(5, 1)
    y_init = np.random.rand(5, 1)
    x = ContinuousParameter('x', 0, 1)
    bo = GPBayesianOptimization(variables_list=[x], X=x_init, Y=y_init)
    bo.run_optimization(f, n_iterations)

    # Check we got the correct number of points
    assert bo.loop_state.X.shape[0] == n_iterations + 5
def test_batch_loop_fails_without_gradients_implemented():
    parameter_space = ParameterSpace([ContinuousParameter('x', 0, 1)])

    model = mock.create_autospec(IModel)

    base_acquisition = ExpectedImprovement(model)

    batch_size = 10

    with pytest.raises(ValueError):
        BayesianOptimizationLoop(parameter_space, model, base_acquisition,
                                 batch_size)
예제 #4
0
def test_loop_initial_state():
    x_init = np.random.rand(5, 1)
    y_init = np.random.rand(5, 1)

    gpy_model = GPy.models.GPRegression(x_init, y_init)
    model = GPyModelWrapper(gpy_model)
    space = ParameterSpace([ContinuousParameter('x', 0, 1)])

    exp_design = ExperimentalDesignLoop(space, model)

    # test loop state initialization
    assert_array_equal(exp_design.loop_state.X, x_init)
    assert_array_equal(exp_design.loop_state.Y, y_init)
예제 #5
0
 def convert_to_list_of_continuous_parameters(
         self) -> List[ContinuousParameter]:
     """
     converts the integral bounds into a list of ContinuousParameter objects
     :return: a list if ContinuousParameter objects (one for each dimension)
     """
     continuous_parameters = []
     for i, bounds_d in enumerate(self.bounds):
         lb_d, ub_d = bounds_d
         name_d = self.name + '_' + str(i)
         param = ContinuousParameter(name=name_d,
                                     min_value=lb_d,
                                     max_value=ub_d)
         continuous_parameters.append(param)
     return continuous_parameters
예제 #6
0
def test_loop():
    n_iterations = 5

    x_init = np.random.rand(5, 1)
    y_init = np.random.rand(5, 1)

    # Make GPy model
    gpy_model = GPy.models.GPRegression(x_init, y_init)
    model = GPyModelWrapper(gpy_model)

    space = ParameterSpace([ContinuousParameter('x', 0, 1)])
    acquisition = ModelVariance(model)

    # Make loop and collect points
    exp_design = ExperimentalDesignLoop(space, model, acquisition)
    exp_design.run_loop(UserFunctionWrapper(f), FixedIterationsStoppingCondition(n_iterations))

    # Check we got the correct number of points
    assert exp_design.loop_state.X.shape[0] == 10
예제 #7
0
def test_loop():
    n_iterations = 5
    x_init = np.random.rand(5, 1)
    y_init = np.random.rand(5, 1)
    yc_init = np.random.rand(5, 1)
    x = ContinuousParameter('x', 0, 1)
    bo = UnknownConstraintGPBayesianOptimization(variables_list=[x],
                                                 X=x_init,
                                                 Y=y_init,
                                                 Yc=yc_init,
                                                 batch_size=1)
    results = None
    for _ in range(n_iterations + 1):
        X_new = bo.get_next_points(results)
        Y_new = f(X_new)
        Yc_new = fc(X_new)
        results = [
            UserFunctionResult(X_new[0], Y_new[0], Y_constraint=Yc_new[0])
        ]
    # Check we got the correct number of points
    assert bo.loop_state.X.shape[0] == n_iterations + 5