def main(job_id, params): print '!!! Entered Main !!!' print 'Anything printed here will end up in the output directory for job #:', str( job_id) print params f = Branin() # Change this res = f.objective_function([params['x'], params['y']]) # CHANGE THIS print res with open('/home/mansurm/Experiments/brannin/run1.csv', 'a') as csvfile: # CHANGE THIS writer = csv.writer(csvfile, delimiter=',') writer.writerow([res['main'][0]]) return res['main'][0]
def run_example(num_points_to_sample=200, verbose=False, **kwargs): b = Branin() bounds = b.get_meta_information()['bounds'] dimensions = len(bounds) lower =np.array([i[0] for i in bounds]) upper =np.array([i[1] for i in bounds]) start_point = (upper-lower)/2 exp = Experiment([lower,upper]) exp.historical_data.append_sample_points([ SamplePoint(start_point, wrapper(start_point,b), 0.6)]) for _ in range(num_points_to_sample): next_point_to_sample = gp_next_points(exp, **kwargs)[0] value_of_next_point = wrapper(next_point_to_sample,b) if verbose: print "Sampled f({0:s}) = {1:.18E}".format(str(next_point_to_sample), value_of_next_point) exp.historical_data.append_sample_points([SamplePoint(next_point_to_sample, value_of_next_point, 0.6)])
import numpy as np from hpolib.benchmarks.synthetic_functions import Branin # Perform random search on the Branin function b = Branin() values = [] cs = b.get_configuration_space() for i in range(1000): configuration = cs.sample_configuration() rval = b.objective_function(configuration) loss = rval['function_value'] values.append(loss) print(np.min(values))
import os from fanova import fANOVA import numpy as np from robo.fmin import random_search from hpolib.benchmarks.synthetic_functions import Branin import fanova.visualizer objective_function = Branin() info = objective_function.get_meta_information() bounds = np.array(info['bounds']) config_space = objective_function.get_configuration_space() # Start Bayesian optimization to optimize the objective function results = random_search(objective_function, bounds[:, 0], bounds[:, 1], num_iterations=50) # Creating a fANOVA object X = np.array([i for i in results['X']]) Y = np.array([i for i in results['y']]) f = fANOVA(X, Y) print(f.quantify_importance((0, ))) # Visualization os.makedirs("./plots", exist_ok=True) vis = fanova.visualizer.Visualizer(f, config_space, "./plots/") vis.plot_marginal(1)
""" This example shows how RoBO can be combined with HPOlib. Before you run it, make sure that you installed it. For further information have a look here https://github.com/automl/HPOlib2.git """ import numpy as np from hpolib.benchmarks.synthetic_functions import Branin from robo.fmin import bayesian_optimization f = Branin() info = f.get_meta_information() bounds = np.array(info['bounds']) # Start Bayesian optimization to optimize the objective function results = bayesian_optimization(f, bounds[:, 0], bounds[:, 1], num_iterations=50) print(results["x_opt"]) print(results["f_opt"])
import numpy as np from hpolib.benchmarks.synthetic_functions import Branin from robo.fmin import bayesian_optimization f = Branin() info = f.get_meta_information() bounds = np.array(info['bounds']) # Start Bayesian optimization to optimize the objective function results = bayesian_optimization(f, bounds[:, 0], bounds[:, 1], num_iterations=50) print(results["x_opt"]) print(results["f_opt"])
class Wrapper(UserFunction): def __init__(self, b): self.b = b def evaluate(self, X: np.ndarray): res = [] for xi in X: yi = self.b.objective_function(xi)["function_value"] res.append(UserFunctionResult(xi, np.array([yi]))) return res if args.benchmark == "branin": b = Branin() elif args.benchmark == "hartmann3": b = Hartmann3() elif args.benchmark == "hartmann6": b = Hartmann6() elif args.benchmark == "bohachevsky": b = Bohachevsky() elif args.benchmark == "rosenbrock": b = Rosenbrock() elif args.benchmark == "goldsteinprice": b = GoldsteinPrice() elif args.benchmark == "forrester": b = Forrester() elif args.benchmark == "camelback": b = Camelback() elif args.benchmark == "sinone":
from fanova import fANOVA import numpy as np from robo.fmin import random_search from hpolib.benchmarks.synthetic_functions import Branin import fanova.visualizer objective_function = Branin() info = objective_function.get_meta_information() bounds = np.array(info['bounds']) config_space = objective_function.get_configuration_space() # Start Bayesian optimization to optimize the objective function results = random_search(objective_function, bounds[:, 0], bounds[:, 1], num_iterations=50) # Creating a fANOVA object X = np.array([i for i in results['X']]) Y = np.array([i for i in results['y']]) f = fANOVA(X,Y) print(f.quantify_importance((0, ))) # Visualization vis = fanova.visualizer.Visualizer(f, config_space, "./plots/") vis.plot_marginal(1)