def reset(self): super(ModeaEnv, self).reset_() self.dim = self.instance[0] self.function_id = self.instance[1] self.instance_id = self.instance[2] self.representation = self.ensureFullLengthRepresentation(self.instance[3]) opts = getOpts(self.representation[: len(options)]) self.lambda_ = self.representation[len(options)] self.mu = self.representation[len(options) + 1] values = getVals(self.representation[len(options) + 2 :]) self.function, self.target = bn.instantiate(int(self.function_id)) self.es = CustomizedES( self.dim, self.function, self.budget, self.mu, self.lambda_, opts, values ) parameter_opts = self.es.parameters.getParameterOpts() # print("Local restart on") if parameter_opts["lambda_"]: self.lambda_init = parameter_opts["lambda_"] elif parameter_opts["local_restart"] in ["IPOP", "BIPOP"]: self.lambda_init = int(4 + np.floor(3 * np.log(parameter_opts["n"]))) else: self.lambda_init = None parameter_opts["lambda_"] = self.lambda_init # BIPOP Specific parameters self.lambda_ = {"small": None, "large": self.lambda_init} self.budgets = {"small": None, "large": None} self.regime = "first" self.update_parameters() return self.get_state(self)
def reset(self): super(ModeaEnv, self).reset_() self.dim = self.instance[0] self.function_id = self.instance[1] self.instance_id = self.instance[2] self.representation = self.ensureFullLengthRepresentation(self.instance[3]) opts = getOpts(self.representation[: len(options)]) self.lambda_ = self.representation[len(options)] self.mu = self.representation[len(options) + 1] values = getVals(self.representation[len(options) + 2 :]) self.function = bn.instantiate(int(self.function_id))[0] self.es = CustomizedES( self.dim, self.function, self.budget, self.mu, self.lambda_, opts, values ) self.es.mutateParameters = self.es.parameters.adaptCovarianceMatrix self.adapt_es_opts(opts) return self.get_state()
def reset(self): """ Reset environment Returns ------- np.array Environment state """ super(CMAESEnv, self).reset_() self.history.clear() self.past_obj_vals.clear() self.past_sigma.clear() self.cur_loc = self.instance[3] self.dim = self.instance[1] self.init_sigma = self.instance[2] self.cur_sigma = [self.init_sigma] self.fcn = bn.instantiate(self.instance[0])[0] self.func_values = [] self.f_vals = deque(maxlen=self.popsize) self.es = CMAEvolutionStrategy( self.cur_loc, self.init_sigma, { "popsize": self.popsize, "bounds": self.bounds, "seed": self.initial_seed }, ) self.solutions, self.func_values = self.es.ask_and_eval(self.fcn) self.fbest = self.func_values[np.argmin(self.func_values)] self.f_difference = np.abs( np.amax(self.func_values) - self.cur_obj_val) / float( self.cur_obj_val) self.velocity = np.abs(np.amin(self.func_values) - self.cur_obj_val) / float(self.cur_obj_val) self.es.mean_old = self.es.mean self.history.append([self.f_difference, self.velocity]) return self.get_state(self)
def read_instance_set(self): """ Read path of instances from config into list """ path = ( os.path.dirname(os.path.abspath(__file__)) + "/" + self.config.instance_set_path ) self.config["instance_set"] = {} with open(path, "r") as fh: reader = csv.DictReader(fh) for row in reader: function = bn.instantiate(int(row["fcn_index"]))[0] init_locs = [float(row[f"init_loc{i}"]) for i in range(int(row["dim"]))] instance = [ function, int(row["dim"]), float(row["init_sigma"]), init_locs, ] self.config["instance_set"][int(row["ID"])] = instance
"SharpRidge", "StepEllipsoidal", "RosenbrockRotated", "SchaffersIllConditioned", "LunacekBiR", "GG101me", "GG21hi"] init_sigmas = [0.5]*len(test_fcns) for i in test_fcns: init_locs.append([0]*input_dim) cur_dir = os.path.dirname(os.path.abspath(__file__)) fcn_objs = [] fcns = [] for i in range(num_fcns//len(fcn_ids)): #instantiate BBOB functions based on their ID for i in fcn_ids: fcn_objs.append(bn.instantiate(i)[0]) for i,function in enumerate(fcn_objs): fcns.append({'fcn_obj': function, 'dim': input_dim, 'init_loc': list(init_locs[i]), 'init_sigma': init_sigmas[i]}) SENSOR_DIMS = { PAST_OBJ_VAL_DELTAS: history_len, CUR_PS: 1, CUR_SIGMA : 1, ACTION: 1, PAST_SIGMA: history_len } BASE_DIR = '/'.join(str.split(gps_filepath, '/')[:-2]) EXP_DIR = BASE_DIR + '/../examples/10BBOB' + '/'