def initializedESAlgorithm(self): representation = self.ensureFullLengthRepresentation(self.esconfig) opts = getOpts(representation[:len(options)]) values = getVals(representation[len(options)+2:]) values = getVals(self.esconfig) customES = Algorithms.CustomizedES(self.dimension, self.problemInstance, budget=self.totalBudget, opts=opts, values=values) customES.mutateParameters = customES.parameters.adaptCovarianceMatrix self.optimizer = customES
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 runCustomizedES(representation, iid, rep, ndim, fid, budget): """ Runs a customized ES on a particular instance of a BBOB function in some dimensionality with given budget. This function takes care of the BBOB setup and the translation of the representation to input arguments for the customizedES. :param representation: Representation of a customized ES (structure and parameter initialization) :param iid: Instance ID for the BBOB function :param rep: Repetition number (for output storage purposes only) :param ndim: Dimensionality to run the ES in :param fid: BBOB function ID :param budget: Evaluation budget for the ES :return: Tuple(target optimum value of the evaluated function, list of fitness-values over time) """ print(reprToString(representation), iid, rep) # Setup BBOB function + logging bbob_opts['algid'] = representation datapath_ext = '{repr}/{ndim}d-f{fid}/i{iid}-r{rep}/'.format( ndim=ndim, fid=fid, repr=reprToString(representation), iid=iid, rep=rep) guaranteeFolderExists(datapath + datapath_ext) f = fgeneric.LoggingFunction(datapath + datapath_ext, **bbob_opts) f_target = f.setfun(*bbobbenchmarks.instantiate(fid, iinstance=iid), dftarget=Config.default_target).ftarget # Interpret the representation into parameters for the ES opts = getOpts(representation[:len(options)]) lambda_ = representation[len(options)] mu = representation[len(options) + 1] values = getVals(representation[len(options) + 2:]) # Run the ES defined by opts once with the given budget results = _customizedES(ndim, f.evalfun, budget, lambda_=lambda_, mu=mu, opts=opts, values=values) f.finalizerun() return f_target, results
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 test_error(self): with self.assertRaises(IndexError): getVals(range(self.length * 2))
def test_nones(self): self.assertDictEqual(getVals([None] * self.length), dict())
def test_zip_case(self): expected_result = dict( zip(initializable_parameters, range(self.length))) result = getVals(range(self.length)) self.assertDictEqual(expected_result, result)