def main(): """ Main Function. """ # Choose which objective to minimise and the configuration file objective_to_min, config_file, fidel_cost_func = _CHOOSER_DICT[(PROBLEM, IS_MF)] config = load_config_file(config_file) log_stream = open(LOG_FILE, 'w') # Call the optimiser if IS_MF: opt_val, opt_pt, history = minimise_multifidelity_function( objective_to_min, config.fidel_space, config.domain, config.fidel_to_opt, fidel_cost_func, MAX_CAPITAL, capital_type='realtime', config=config, reporter=log_stream) else: opt_val, opt_pt, history = minimise_function(objective_to_min, config.domain, MAX_CAPITAL, capital_type='realtime', config=config, reporter=log_stream) # Print out result log_stream.close() print('Optimum Value found in %02.f time (%d evals): %0.4f' % (MAX_CAPITAL, len(history.curr_opt_points), opt_val)) print('Optimum Point: %s.' % (str(opt_pt)))
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 minimize_function(self, f, n_iter=10, verbose=True, seed=None): """ Run Dragonfly Bayesian optimization to minimize function f. Parameters ---------- f : function Function to optimize. n_iter : int Number of iterations of Bayesian optimization. verbose : bool If True, print information. seed : int If not None, set the random seed to seed. """ if seed is not None: np.random.seed(seed) domain = self._get_domain() opt_method = 'bo' parsed_config = self._get_parsed_config() options = self._get_options() opt_val, opt_pt, history = dragonfly.minimise_function( func=f, domain=domain, max_capital=n_iter, opt_method=opt_method, config=parsed_config, options=options, ) results = Namespace(opt_val=opt_val, opt_pt=opt_pt, history=history) if verbose: vals = results.history.query_vals min_vals_idx = min(range(len(vals)), key=lambda x: vals[x]) print('Minimum y = {}'.format(results.opt_val)) print('Minimizer x = {}'.format(results.opt_pt)) print('Found at iter = {}'.format(min_vals_idx + 1)) return results
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)