Ejemplo n.º 1
0
 def test_bohamiann(self):
     res = bohamiann(objective_function=objective,
                     lower=self.lower,
                     upper=self.upper,
                     n_init=2,
                     num_iterations=3)
     assert len(res["x_opt"]) == 1
     assert np.array(res["x_opt"]) >= 0
     assert np.array(res["x_opt"]) <= 1
Ejemplo n.º 2
0
def boham():
    """
    Bayesian Networks
    """
    print('\n============= START Bohamiann OPTIMIZATION =============\n')
    print("""Optimization parameters:
                    - lower = {}
                    - upper = {}
                    - num_iter = {}
                    - maximizer = {}
                    - acq_func = {}""".format(lower, upper,
                                              args.num_iterations,
                                              args.maximizer,
                                              args.acquisition_func))

    results = bohamiann(objective_function,
                        lower,
                        upper,
                        num_iterations=args.num_iterations,
                        maximizer=args.maximizer,
                        acquisition_func=args.acquisition_func)
    print(results["x_opt"])
    print(results["f_opt"])
    print('\n============= END OPTIMIZATION =============\n')
elif method == "rf":
    results = bayesian_optimization(f,
                                    bounds[:, 0],
                                    bounds[:, 1],
                                    num_iterations=n_iters,
                                    n_init=n_init,
                                    model_type="rf")
elif method == "random_search":
    results = random_search(f,
                            bounds[:, 0],
                            bounds[:, 1],
                            num_iterations=n_iters)
elif method == "bohamiann":
    results = bohamiann(f,
                        bounds[:, 0],
                        bounds[:, 1],
                        num_iterations=n_iters,
                        n_init=n_init)

# Offline Evaluation
test_error = []
cum_cost = 0

for i, inc in enumerate(results["incumbents"]):

    y = f.objective_function_test(np.array(inc))["function_value"]
    test_error.append(y)

    # Compute the time it would have taken to evaluate this configuration
    c = f.objective_function(np.array(results["X"][i]))["cost"]
    cum_cost += c
Ejemplo n.º 4
0
import logging
import numpy as np

from hpolib.benchmarks.synthetic_functions import Branin

from robo.fmin import bohamiann

logging.basicConfig(level=logging.INFO)


def objective_function(x):
    y = np.sin(3 * x[0]) * 4 * (x[0] - 1) * (x[0] + 2)
    return y


# Defining the bounds and dimensions of the input space
lower = np.array([0])
upper = np.array([6])

# Start Bayesian optimization to optimize the objective function
results = bohamiann(objective_function, lower, upper, num_iterations=20)
print(results["x_opt"])
print(results["f_opt"])