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
from bbob import bbobbenchmarks, fgeneric import Config from modea.Algorithms import _customizedES from modea.Utils import getOpts, getVals, options, initializable_parameters, \ chunkListByLength, guaranteeFolderExists, reprToString, ESFitness from local import datapath try: from mpi4py import MPI MPI_available = True except: MPI = None MPI_available = False guaranteeFolderExists(datapath) # Options to be stored in the log file(s) bbob_opts = { 'algid': None, 'comments': '<comments>', 'inputformat': 'col' } # 'row' or 'col' '''----------------------------------------------------------------------------- # Small Utility Functions # -----------------------------------------------------------------------------''' def _sysPrint(string): """ Small function to take care of the 'overhead' of sys.stdout.write + flush """ sys.stdout.write(string)
def test_create_folder(self): guaranteeFolderExists(self.folder_name) self.assertIn(self.folder_name, os.listdir('.'))
def test_use_existing_folder(self): os.mkdir(self.folder_name) guaranteeFolderExists(self.folder_name) self.assertIn(self.folder_name, os.listdir('.'))
from functools import partial from copy import copy from bbob import bbobbenchmarks import Config from modea.Algorithms import _MIES from EvolvingES import ensureFullLengthRepresentation, evaluateCustomizedESs, _displayDuration, MPIpool_evaluate from modea.Individual import MixedIntIndividual from modea.Parameters import Parameters from modea.Utils import ESFitness, getOpts, options, num_options_per_module, \ getBitString, getPrintName, create_bounds, guaranteeFolderExists from local import non_bbob_datapath # Sets of noise-free and noisy benchmarks free_function_ids = bbobbenchmarks.nfreeIDs noisy_function_ids = bbobbenchmarks.noisyIDs guaranteeFolderExists(non_bbob_datapath) opts = { 'algid': None, 'comments': '<comments>', 'inputformat': 'col' } # 'row' or 'col' def sysPrint(string): """ Small function to take care of the 'overhead' of sys.stdout.write + flush """ sys.stdout.write(string) sys.stdout.flush() def _testEachOption():