def rollout_with_model_performance(self, history=[]): value_to_choose = [] list_configuration_to_choose = [] list_rollout = [] st_time = time.time() try: configs = self.config_space.sample_partial_configuration( history, 500) list_configuration_to_choose = [ np.nan_to_num(c.get_array()) for c in configs ] except Exception as e: pass mu, sigma = self.score_model.get_mu_sigma_from_rf( np.array(list_configuration_to_choose), self.score_model.model) ei_values = expected_improvement(mu, sigma, self.bestconfig["validation_score"]) mu_time, sigma_time = self.score_model.get_mu_sigma_from_rf( np.array(list_configuration_to_choose), self.score_model.model_of_time) ei_values = [ ei if mu_t < (self.cpu_time_in_s) else -1000 for ei, mu_t in zip(ei_values, mu_time) ] id_max = np.argmax(ei_values) return configs[id_max]
def rollout_in_expert_neighborhood(self, history=[]): try: expert, _ = self.experts[tuple(history)] except: expert = self.config_space.sample_partial_configuration_with_default( history) try: #configs = [c_f for c_f in # [get_one_exchange_neighbourhood_with_history(c_i, self.seed, history) for c_i in # [c for c in get_one_exchange_neighbourhood_with_history(expert, self.seed, history)] #]] configs = [] # print("[Rollout] Neighborhood on", expert.get_dictionary()) for c in get_one_exchange_neighbourhood_with_history( expert, self.seed, history): tmp_ = list( get_one_exchange_neighbourhood_with_history( c, self.seed, history)) configs.extend(tmp_) configs.extend( self.config_space.sample_partial_configuration(history, 1000)) list_configuration_to_choose = np.nan_to_num( np.array([c.get_array() for c in configs])) except Exception as e: raise (e) mu_loc, sigma_loc = self.score_model.get_mu_sigma_from_rf( np.array(list_configuration_to_choose), "local") ei_values = expected_improvement(mu_loc, sigma_loc, self.bestconfig["validation_score"]) #mu_time, sigma_time = self.score_model.get_mu_sigma_from_rf(np.array(list_configuration_to_choose), "time") #if self.is_metalearning: # beta = self.get_beta() # mu_gen, sigma_gen = self.score_model.get_mu_sigma_from_rf(np.array(list_configuration_to_choose), "general") #ei_values = np.array([mu_gener * beta + (1 - beta) * mu_local for mu_gener, mu_local in zip(mu, mu_loc)]) id_max = (-ei_values).argsort()[:3] return [configs[np.random.choice(id_max)] for _ in range(3)]