def test_sobol_GPEI(self): """Tests sobol + GPEI instantiation.""" exp = get_branin_experiment() # Check that factory generates a valid sobol modelbridge. sobol = get_sobol(search_space=exp.search_space) self.assertIsInstance(sobol, RandomModelBridge) for _ in range(5): sobol_run = sobol.gen(n=1) exp.new_batch_trial().add_generator_run(sobol_run).run() # Check that factory generates a valid GP+EI modelbridge. exp.optimization_config = get_branin_optimization_config() gpei = get_GPEI(experiment=exp, data=exp.fetch_data()) self.assertIsInstance(gpei, TorchModelBridge) gpei = get_GPEI(experiment=exp, data=exp.fetch_data(), search_space=exp.search_space) self.assertIsInstance(gpei, TorchModelBridge) botorch = get_botorch(experiment=exp, data=exp.fetch_data()) self.assertIsInstance(botorch, TorchModelBridge)
def run_sparse(self): sparse_exp = SparseExperiment(self.epochs1, **self.__dict__) self.exp, self.data = sparse_exp.create_load_experiment() sobol = get_sobol(self.exp.search_space) sobol = self.run_model(self.r1, sobol, model_type="random") self.exp.optimization_config.objective.metrics[0].epochs = self.epochs2 if self.arc: botorch = get_botorch_arc(experiment=self.exp, data=self.data) else: botorch = get_botorch(experiment=self.exp, data=self.data) botorch = self.run_model(self.r2, botorch, model_type="bo") if self.morphisms: self.pareto_arms = clean_models_return_pareto( self.data, self.models_path) self.develop_morphisms(botorch)
# #### Run the optimization loop # # We're ready to run the Bayesian Optimization loop. for i in range(5): print(f"Running optimization batch {i+1}/5...") # user added: # get_botorch is a self-contained macro-framework that does everything for you: # 1) It fits the GP model to the new data # 2) If optimizes the acquisition function and provides the next candidate # 3) It evaluates such candidate (next point) # 4) It returns the best suggestion (best guess) model = get_botorch( experiment=exp, data=exp.eval(), search_space=exp.search_space, model_constructor=_get_and_fit_simple_custom_gp, ) batch = exp.new_trial(generator_run=model.gen(1)) # user TODO: See https://ax.dev/api/_modules/ax/modelbridge/factory.html#get_botorch # 1) Pass a custom acquisition function constructor # 2) Maybe change the optimizer # 3) print(batch) print("Done!")