def test_grid_search(self):
        maximizer = GridSearch(self.objective_function, self.lower, self.upper)
        x = maximizer.maximize()

        assert x.shape[0] == 1
        assert len(x.shape) == 1
        assert np.all(x >= self.lower)
        assert np.all(x <= self.upper)
    def test_grid_search(self):
        maximizer = GridSearch(self.objective_function, self.lower, self.upper)
        x = maximizer.maximize()

        assert x.shape[0] == 1
        assert len(x.shape) == 1
        assert np.all(x >= self.lower)
        assert np.all(x <= self.upper)
Example #3
0
    def test_grid_search(self):
        maximizer = GridSearch(self.acquisition_func, self.X_lower, self.X_upper)
        x = maximizer.maximize()

        assert x.shape[0] == 1
        assert x.shape[1] == self.dims
        assert np.all(x[:, 0] >= self.X_lower[0])
        assert np.all(x[:, 0] <= self.X_upper[0])
        assert np.all(x < self.X_upper)
Example #4
0
    def test_grid_search(self):
        maximizer = GridSearch(self.acquisition_func, self.X_lower,
                               self.X_upper)
        x = maximizer.maximize()

        assert x.shape[0] == 1
        assert x.shape[1] == self.dims
        assert np.all(x[:, 0] >= self.X_lower[0])
        assert np.all(x[:, 0] <= self.X_upper[0])
        assert np.all(x < self.X_upper)
Example #5
0
    def objective_function(self, x):
        return np.sin(3 * x) * 4 * (x - 1) * (x + 2)

task = ExampleTask()

# Defining the method to model the objective function
kernel = GPy.kern.Matern52(input_dim=task.n_dims)
model = GPyModel(kernel, optimize=True, noise_variance=1e-4, num_restarts=10)

# The acquisition function that we optimize in order to pick a new x
acquisition_func = EI(model, X_upper=task.X_upper, X_lower=task.X_lower, compute_incumbent=compute_incumbent, par=0.1)  # par is the minimum improvement that a point has to obtain


# Set the method that we will use to optimize the acquisition function
maximizer = GridSearch(acquisition_func, task.X_lower, task.X_upper)


# Draw one random point and evaluate it to initialize BO
X = np.array([np.random.uniform(task.X_lower, task.X_upper, task.n_dims)])
Y = task.objective_function(X)

# This is the main Bayesian optimization loop
for i in range(10):
    # Fit the model on the data we observed so far
    model.train(X, Y)

    # Update the acquisition function model with the retrained model
    acquisition_func.update(model)

    # Optimize the acquisition function to obtain a new point