def test_GeneralTopologyBlackboxObject(self, controller_str): self.base_config.controller_type_str = controller_str self.base_config.horizon = 2 self.base_config.environment_name = 'Pendulum' self.config = config_util.generate_config(self.base_config, current_time_string='TEST') self.config.setup_controller_fn() self.object = objects.GeneralTopologyBlackboxObject(self.config) optimizer = self.config.es_blackbox_optimizer_fn( self.object.get_metaparams()) params = self.object.get_initial() topology_str = pg.to_json(self.config.controller.propose_dna()) core_hyperparams = optimizer.get_hyperparameters() hyperparams = [0] + list(core_hyperparams) self.object.execute_with_topology(params, topology_str, hyperparams)
def propose_queries_blackbox_optimizer(config, current_input, blackbox_optimizer, iteration): """Proposes perturbations and topology_str's.""" start_time = time.time() core_hyperparameters = blackbox_optimizer.get_hyperparameters() proposed_perturbations = [] proposed_dnas = [] requests = [] for i in range(config.total_num_perturbations): perturbation = np.random.normal( size=(len(current_input))) * config.es_precision_parameter proposed_perturbations.append(perturbation) dna = config.controller.propose_dna() topology_str = pg.to_json(dna) proposed_dnas.append(dna) tag = i + 1 request = { 'current_input': current_input, 'hyperparameters': core_hyperparameters, 'perturbation': perturbation, 'tag': tag, 'topology_str': topology_str } requests.append(request) if config.est_type == 'antithetic': antiperturbation = -perturbation proposed_perturbations.append(antiperturbation) dna = config.controller.propose_dna() topology_str = pg.to_json(dna) proposed_dnas.append(dna) request = { 'current_input': current_input, 'hyperparameters': core_hyperparameters, 'perturbation': antiperturbation, 'tag': -tag, 'topology_str': topology_str } requests.append(request) for _ in range(config.num_exact_evals): null_perturbation = np.zeros_like(current_input) dna = config.controller.propose_dna() topology_str = pg.to_json(dna) proposed_dnas.append(dna) request = { 'current_input': current_input, 'hyperparameters': core_hyperparameters, 'perturbation': null_perturbation, 'tag': 0, 'topology_str': topology_str } requests.append(request) end_time = time.time() logging.info('Iteration %d, requests proposed in %f seconds', iteration, end_time - start_time) return requests, proposed_perturbations, proposed_dnas
def init_topology(self): """Sets the edge_dict (needed for parent get_action function) to be complete.""" init_dna = self.template.encode(next(pg.random_sample(self.search_space))) init_topology_str = pg.to_json(init_dna) self.update_topology(init_topology_str)