def get_method_options(prob, capital_type): """ Returns the method options. """ methods = prob.methods all_method_options = {} for meth in methods: if meth == 'rand': curr_options = load_options(cp_random_optimiser_args) elif meth == 'ga': curr_options = load_options(cpga_opt_args) elif meth.startswith('dragonfly'): if meth.startswith('dragonfly-mf'): curr_options = load_options(get_all_mf_cp_gp_bandit_args()) else: curr_options = load_options(get_all_cp_gp_bandit_args()) meth_parts = meth.split('_') if len(meth_parts) == 2: curr_options.acq_opt_method = meth_parts[-1] elif meth in ['hyperopt', 'gpyopt', 'smac']: curr_options = load_options(blackbox_opt_args) curr_options = Namespace(redo_evals_for_true_val=False) else: raise ValueError('Unknown method %s.'%(meth)) curr_options.capital_type = capital_type all_method_options[meth] = curr_options return all_method_options
def get_method_options(prob, capital_type): """ Returns the method options. """ methods = prob.methods all_method_options = {} for meth in methods: if meth == 'rand': curr_options = load_options(cp_random_optimiser_args) elif meth == 'ga': curr_options = load_options(cpga_opt_args) elif meth.startswith('dragonfly'): if meth.startswith('dragonfly-mf'): curr_options = load_options(get_all_mf_cp_gp_bandit_args()) else: curr_options = load_options(get_all_cp_gp_bandit_args()) meth_parts = meth.split('_') if len(meth_parts) == 2: curr_options.acq_opt_method = meth_parts[-1] elif meth in ['hyperopt', 'gpyopt', 'smac', 'spearmint']: curr_options = load_options(blackbox_opt_args) curr_options = Namespace(redo_evals_for_true_val=True) else: raise ValueError('Unknown method %s.' % (meth)) # Some additional data we will need for Spearmint if meth == 'spearmint': # Swap in the following after you download and install Spearmint curr_options.exp_dir = '/home/karun/boss/e3_cp/Spearmint/' + \ prob.study_name.split('-')[0] curr_options.pkg_dir = '/home/karun/Spearmint/spearmint' curr_options.capital_type = capital_type all_method_options[meth] = curr_options return all_method_options
def get_command_line_args(): """ Returns all arguments for the command line. """ ret = dragonfly_args + \ ga_opt_args + \ euclidean_random_optimiser_args + cp_random_optimiser_args + \ mf_euclidean_random_optimiser_args + mf_cp_random_optimiser_args + \ get_all_euc_gp_bandit_args() + get_all_cp_gp_bandit_args() + \ get_all_mf_euc_gp_bandit_args() + get_all_mf_cp_gp_bandit_args() + \ euclidean_random_multiobjective_optimiser_args + \ cp_random_multiobjective_optimiser_args + \ get_all_euc_moo_gp_bandit_args() + get_all_cp_moo_gp_bandit_args() return get_unique_list_of_option_args(ret)
def prepare_chemist_options(self, chemist_args, domain_config): """ Resets default gp_bandit options with chemist arguments """ dflt_list_of_options = get_all_cp_gp_bandit_args() list_of_options = self.reset_default_options(dflt_list_of_options, chemist_args) for name, value in domain_config.items(): list_of_options += [{'name': name, 'default': value}] options = load_options(list_of_options, reporter=self.reporter) if self.mf_strategy is not None: options.mf_strategy = self.mf_strategy if isinstance(self.worker_manager, RealWorkerManager): options.capital_type = 'realtime' elif isinstance(self.worker_manager, SyntheticWorkerManager): options.capital_type = 'return_value' options.get_initial_qinfos = \ lambda num: get_cp_domain_initial_qinfos(self.func_caller.domain, num) return options
def main(): """ Main function. """ # First load arguments all_args = dragonfly_args + get_all_euc_gp_bandit_args() + get_all_cp_gp_bandit_args() \ + get_all_mf_euc_gp_bandit_args() + get_all_mf_cp_gp_bandit_args() \ + get_all_euc_moo_gp_bandit_args() + get_all_cp_moo_gp_bandit_args() all_args = get_unique_list_of_option_args(all_args) options = load_options(all_args, cmd_line=True) # Load domain and objective config = load_config_file(options.config) if hasattr(config, 'fidel_space'): is_mf = True else: is_mf = False expt_dir = os.path.dirname( os.path.abspath(os.path.realpath(options.config))) if not os.path.exists(expt_dir): raise ValueError("Experiment directory does not exist.") objective_file_name = config.name obj_module = imp.load_source( objective_file_name, os.path.join(expt_dir, objective_file_name + '.py')) # Set capital options.capital_type = 'return_value' if options.budget < 0: budget = options.max_capital else: budget = options.budget if budget < 0: raise ValueError( 'Specify the budget via argument budget or max_capital.') options.max_capital = budget # Call optimiser _print_prefix = 'Maximising' if options.max_or_min == 'max' else 'Minimising' call_to_optimise = { 'single': { 'max': maximise_function, 'min': minimise_function }, 'single_mf': { 'max': maximise_multifidelity_function, 'min': minimise_multifidelity_function }, 'multi': { 'max': multiobjective_maximise_functions, 'min': multiobjective_minimise_functions }, } if not options.is_multi_objective: if is_mf: print('%s function on fidel_space: %s, domain %s.' % (_print_prefix, config.fidel_space, config.domain)) opt_val, opt_pt, history = call_to_optimise['single_mf'][ options.max_or_min](obj_module.objective, domain=None, fidel_space=None, fidel_to_opt=config.fidel_to_opt, fidel_cost_func=obj_module.cost, max_capital=options.max_capital, config=config, options=options) else: print('%s function on domain %s.' % (_print_prefix, config.domain)) opt_val, opt_pt, history = call_to_optimise['single'][ options.max_or_min](obj_module.objective, domain=None, max_capital=options.max_capital, config=config, options=options) print('Optimum Value in %d evals: %0.4f' % (len(history.curr_opt_points), opt_val)) print('Optimum Point: %s.' % (opt_pt)) else: if is_mf: raise ValueError( 'Multi-objective multi-fidelity optimisation has not been ' + 'implemented yet.') else: print( '%s multiobjective functions on domain %s with %d functions.' % (_print_prefix, config.domain, len(obj_module.objectives))) pareto_values, pareto_points, history = \ call_to_optimise['multi'][options.max_or_min](obj_module.objectives, domain=None, max_capital=options.max_capital, config=config, options=options) num_pareto_points = len(pareto_points) print('Found %d Pareto Points: %s.' % (num_pareto_points, pareto_points)) print('Corresponding Pareto Values: %s.' % (pareto_values))