def printBestFromRankedBF(): for dim in dimensions: for fid in functions: print("Results for F{} in {}dim:".format(fid, dim)) # print(findGivenInRankedBF(dim, 1, given)) results = getBestFromRankedBF(dim, fid, num=10) for ES, rank, fit in results: print("Rank: {0:>4}\t{1:>33}\t{2}".format( rank + 1, intToRepr(ES), fit)) print()
def get_default_hyperparameter_values(params, dim, rep, budget=1000): """ Reads the inital hyperparameter values from a single-split CMA-ES :param params: list of the required parameters :param dim: dimensionality of the problem :param rep: the algorithm variant :param budget: optional budget (should not change parameter values?) :return: the inital hyperparameter values for all keys in params """ alg = SingleSplitCMAES(dim, None, representation=intToRepr(rep), representation2=None, split=None, budget=budget, seed=0) return alg.get_default_values(params)
def printComparisonGivenInBF(given=None): # Add/remove choices as you wish if given is None: given = default_ESs for dim in dimensions: for fid in functions: print("Results for F{} in {}dim:".format(fid, dim)) results = findGivenInRankedBF(dim, fid, given) for ES in results: print("Rank: {0:>4}\t{1:>33}\t{2}".format( ES.rank + 1, intToRepr(ES.ES), ES.fitness)) print()
def printComparisonTable(given=None): # Add/remove choices as you wish if given is None: given = default_ESs os.chdir(ga_location) with open('ga_results.dat') as f: ga_results = cPickle.load(f) print('\\hline') print( 'F-ID & N & Brute Force & ERT & FCE & GA & ERT & FCE & Relative \\\\') print('\\hline') print('\\hline') for fid in functions: for dim in dimensions: results = findGivenInRankedBF(dim, fid, given) results.sort(key=lambda a: a.rank) bf_string = reprToString(intToRepr(results[0].ES)) bf_ERT = "{:>9.6g}".format( results[0].fitness.ERT ) if results[0].fitness.ERT is not None else " N/A" bf_FCE = results[0].fitness.FCE ga_string = reprToString(ga_results[dim][fid].ES[:11]) ga_ERT = "{:>9.6g}".format( ga_results[dim][fid].fitness.ERT ) if ga_results[dim][fid].fitness.ERT is not None else " N/A" ga_FCE = ga_results[dim][fid].fitness.FCE if results[0].fitness.ERT is not None: relative_fitness = results[0].fitness.ERT / ga_results[dim][ fid].fitness.ERT else: relative_fitness = results[0].fitness.FCE / ga_results[dim][ fid].fitness.FCE print( 'F{0:<2} & {1:>2} & {2} & {3} & {4:>9.4g} & {5} & {6} & {7:>9.4g} & {8:>8.3g} \\\\' .format(fid, dim, bf_string, bf_ERT, bf_FCE, ga_string, ga_ERT, ga_FCE, relative_fitness)) print('\\hline')
def printRelativeComparisonBestGAAndGivenBF(given=None): # Add/remove choices as you wish if given is None: given = default_ESs os.chdir(ga_location) with open('ga_results.dat') as f: ga_results = cPickle.load(f) all_relatives = [] relatives = {i: [] for i in range(len(default_ESs))} counts = [0] * len(default_ESs) for dim in dimensions: for fid in functions: print("Results for F{} in {}dim:".format(fid, dim)) results = findGivenInRankedBF(dim, fid, given) ranks = [] for i, ES in enumerate(results): if ES.fitness.ERT is not None: relative_fitness = ES.fitness.ERT / ga_results[dim][ fid].fitness.ERT relatives[i].append(relative_fitness) elif ga_results[dim][ fid].fitness.ERT is not None and ga_results[dim][ fid].fitness.FCE > ES.fitness.FCE: relative_fitness = "Unclear???" else: relative_fitness = ES.fitness.FCE / ga_results[dim][ fid].fitness.FCE all_relatives.append(relative_fitness) ranks.append(ES.rank) print("Rank: {0:>4}\t{1:>33}\t{2}".format( ES.rank + 1, intToRepr(ES.ES), relative_fitness)) for i, rank in enumerate(ranks): if rank == min(ranks): counts[i] += 1 print() print(all_relatives) print(relatives) print(counts)
def test_int_to_repr(self): for rep in self.reps: self.assertEqual(intToRepr(rep.integer), rep.representation)