def run_hartmann6_benchmarks(D, rep, random_subspace=False): if D == 100: problem = hartmann6_100 elif D == 1000 and not random_subspace: problem = hartmann6_1000 elif D == 1000 and random_subspace: problem = hartmann6_random_subspace_1000 experiment, f = benchmark_minimize_callable( problem=problem, num_trials=200, method_name='turbo', replication_index=rep, ) turbo1 = turbo.Turbo1( f=f, lb=np.zeros(D), ub=np.ones(D), n_init=10, max_evals=200, ) turbo1.optimize() rs_str = 'random_subspace_' if random_subspace else '' with open(f'results/hartmann6_{rs_str}{D}_turbo_rep_{rep}.json', "w") as fout: json.dump(object_to_json(experiment), fout)
def run_hartmann6_benchmarks(D, rep, random_subspace=False): if D == 100: problem = hartmann6_100 elif D == 1000 and not random_subspace: problem = hartmann6_1000 elif D == 1000 and random_subspace: problem = hartmann6_random_subspace_1000 experiment, f = benchmark_minimize_callable( problem=problem, num_trials=200, method_name='smac', replication_index=rep, ) fmin_smac_nopynisher( func=f, x0=[0.5] * D, bounds=[[0, 1]] * D, maxfun=200, rng=rep + 1, ) rs_str = 'random_subspace_' if random_subspace else '' with open(f'results/hartmann6_{rs_str}{D}_smac_rep_{rep}.json', "w") as fout: json.dump(object_to_json(experiment), fout)
def test_minimize_callable(self): problem = BenchmarkProblem( name="Branin", search_space=get_branin_search_space(), optimization_config=get_branin_optimization_config(), ) experiment, f = benchmark_minimize_callable(problem=problem, num_trials=20, method_name="scipy", replication_index=2) res = minimize( fun=f, x0=np.zeros(2), bounds=[(-5, 10), (0, 15)], options={"maxiter": 3}, method="Nelder-Mead", ) self.assertTrue(res.fun < 0) # maximization problem self.assertEqual(len(experiment.trials), res.nfev) self.assertEqual(len(experiment.fetch_data().df), res.nfev) self.assertEqual(experiment.name, "scipy_on_Branin__v2") with self.assertRaises(ValueError): minimize(fun=f, x0=np.zeros(2), bounds=[(-5, 10), (0, 15)], method="Nelder-Mead")
def run_hartmann6_benchmarks(D, rep, random_subspace=False): if D == 100: problem = hartmann6_100 elif D == 1000 and not random_subspace: problem = hartmann6_1000 elif D == 1000 and random_subspace: problem = hartmann6_random_subspace_1000 experiment, f = benchmark_minimize_callable( problem=problem, num_trials=200, method_name='cmaes', replication_index=rep, ) try: cma.fmin( objective_function=f, x0=[0.5] * D, sigma0=0.25, options={ 'bounds': [[0] * D, [1] * D], 'maxfevals': 200 }, ) except ValueError: pass # CMA-ES doesn't always terminate at exactly maxfevals rs_str = 'random_subspace_' if random_subspace else '' with open(f'results/hartmann6_{rs_str}{D}_cmaes_rep_{rep}.json', "w") as fout: json.dump(object_to_json(experiment), fout)
def run_hartmann6_benchmarks(D, rep): if D == 100: problem = hartmann6_100 elif D == 1000: problem = hartmann6_1000 experiment, f = benchmark_minimize_callable( problem=problem, num_trials=200, method_name='ebo', replication_index=rep, ) options = { 'x_range': np.vstack((np.zeros(D), np.ones(D))), 'dx': D, 'max_value': 3.32237, # Let it cheat and know the true max value 'T': 200, 'gp_sigma': 1e-7, } options.update(core_options) f_max = lambda x: -f(x) # since EBO maximizes e = ebo(f_max, options) try: e.run() except ValueError: pass # EBO can ask for more than T function evaluations with open(f'results/hartmann6_{D}_ebo_rep_{rep}.json', "w") as fout: json.dump(object_to_json(experiment), fout)
def run_branin_benchmarks(rep): experiment, f = benchmark_minimize_callable( problem=branin_100, num_trials=50, method_name='add_gp_ucb', replication_index=rep, ) options = Namespace(acq="add_ucb") res = minimise_function( f, domain=[[-5, 10]] * 50 + [[0, 15]] * 50, max_capital=49, options=options, ) with open(f'results/branin_100_addgpucb_rep_{rep}.json', "w") as fout: json.dump(object_to_json(experiment), fout)
def run_branin_benchmarks(rep): experiment, f = benchmark_minimize_callable( problem=branin_100, num_trials=50, method_name='smac', replication_index=rep, ) fmin_smac_nopynisher( func=f, x0=[2.5] * 50 + [7.5] * 50, bounds=[[-5, 10]] * 50 + [[0, 15]] * 50, maxfun=50, rng=rep + 1, ) with open(f'results/branin_100_smac_rep_{rep}.json', "w") as fout: json.dump(object_to_json(experiment), fout)
def run_hartmann6_benchmarks(D, rep): if D == 100: problem = hartmann6_100 elif D == 1000: problem = hartmann6_1000 experiment, f = benchmark_minimize_callable( problem=problem, num_trials=200, method_name='add_gp_ucb', replication_index=rep, ) options = Namespace(acq="add_ucb") res = minimise_function(f, domain=[[0, 1]] * D, max_capital=199, options=options) with open(f'results/hartmann6_{D}_addgpucb_rep_{rep}.json', "w") as fout: json.dump(object_to_json(experiment), fout)
def run_branin_benchmarks(rep): experiment, f = benchmark_minimize_callable( problem=branin_100, num_trials=50, method_name='turbo', replication_index=rep, ) turbo1 = turbo.Turbo1( f=f, lb=np.hstack((-5 * np.ones(50), np.zeros(50))), ub=np.hstack((10 * np.ones(50), 15 * np.ones(50))), n_init=10, max_evals=50, ) turbo1.optimize() with open(f'results/branin_100_turbo_rep_{rep}.json', "w") as fout: json.dump(object_to_json(experiment), fout)
def run_branin_benchmarks(rep): experiment, f = benchmark_minimize_callable( problem=branin_100, num_trials=50, method_name='cmaes', replication_index=rep, ) try: cma.fmin( objective_function=f, x0=[2.5] * 50 + [7.5] * 50, sigma0=3.75, options={ 'bounds': [[-5] * 50 + [0] * 50, [10] * 50 + [15] * 50], 'maxfevals': 50, }, ) except ValueError: pass # CMA-ES doesn't always terminate at exactly maxfevals with open(f'results/branin_100_cmaes_rep_{rep}.json', "w") as fout: json.dump(object_to_json(experiment), fout)
def run_branin_benchmarks(rep): experiment, f = benchmark_minimize_callable( problem=branin_100, num_trials=50, method_name='ebo', replication_index=rep, ) options = { 'x_range': np.vstack(( np.hstack((-5 * np.ones(50), np.zeros(50))), np.hstack((10 * np.ones(50), 15 * np.ones(50))), )), 'dx': 100, 'max_value': -0.397887, # Let it cheat and know the true max value 'T': 50, 'gp_sigma': 1e-7, } options.update(core_options) f_max = lambda x: -f(x) # since EBO maximizes e = ebo(f_max, options) try: e.run() except ValueError: pass # EBO can ask for more than T function evaluations with open(f'results/branin_100_ebo_rep_{rep}.json', "w") as fout: json.dump(object_to_json(experiment), fout)