def _runExperiments(): for ndim in Config.experiment_dims: for fid in Config.experiment_funcs: # Initialize the first individual in the population discrete_part = [np.random.randint(len(x[1])) for x in options] lamb = int(4 + np.floor(3 * np.log(parameters.n))) int_part = [lamb] float_part = [ parameters.mu, parameters.alpha_mu, parameters.c_sigma, parameters.damps, parameters.c_c, parameters.c_1, parameters.c_mu, 0.2, 0.955, 0.5, 0, 0.3, 0.5, 2 ] population = [ MixedIntIndividual(len(discrete_part) + len(int_part) + len(float_part), num_discrete=len(num_options_per_module), num_ints=len(int_part)) ] population[0].genotype = np.array(discrete_part + int_part + float_part) population[0].fitness = ESFitness() while len(population) < Config.GA_mu: population.append(copy(population[0])) parameters = Parameters(len(options) + 15, Config.GA_budget, mu=Config.GA_mu, lambda_=Config.GA_lambda) parameters.l_bound[len(options):] = np.array( [2, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]).reshape(15) parameters.u_bound[len(options):] = np.array( [200, 1, 5, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5]).reshape(15) u_bound, l_bound = create_bounds(float_part, 0.3) parameters.u_bound[len(options) + 1:] = np.array(u_bound) parameters.l_bound[len(options) + 1:] = np.array(l_bound) print("Optimizing for function ID {} in {}-dimensional space:". format(fid, ndim)) x = datetime.now() gen_sizes, sigmas, fitness, best = _MIES(n=ndim, fitnessFunction=fid, budget=Config.GA_budget, mu=Config.GA_mu, lambda_=Config.GA_lambda, parameters=parameters, population=population) y = datetime.now() z = y - x np.savez("{}final_GA_results_{}dim_f{}".format( non_bbob_datapath, ndim, fid), sigma=sigmas, best_fitness=fitness, best_result=best.genotype, generation_sizes=gen_sizes, time_spent=z)
def test_nums_dont_add_up(self): with self.assertRaises(MixedIntIndividualError): _ = MixedIntIndividual(5, None, None, None)
def test_n_too_small(self): with self.assertRaises(MixedIntIndividualError): _ = MixedIntIndividual(1, 0, 0)
def setUp(self): self.n = 10 self.individual = MixedIntIndividual(n=self.n, num_discrete=2, num_ints=3)
def _runGA(ndim=5, fid=1, run=1): x = datetime.now() # Where to store genotype-fitness information # storage_file = '{}GA_results_{}dim_f{}.tdat'.format(non_bbob_datapath, ndim, fid) storage_file = '{}MIES_results_{}dim_f{}run_{}.tdat'.format( non_bbob_datapath, ndim, fid, run) # Fitness function to be passed on to the baseAlgorithm fitnessFunction = partial(evaluateCustomizedESs, fid=fid, ndim=ndim, iids=range(Config.ES_num_runs), storage_file=storage_file) parameters = Parameters(len(options) + 15, Config.GA_budget, mu=Config.GA_mu, lambda_=Config.GA_lambda) parameters.l_bound[len(options):] = np.array( [2, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]).reshape(15) parameters.u_bound[len(options):] = np.array( [200, 1, 5, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5]).reshape(15) # Initialize the first individual in the population discrete_part = [np.random.randint(len(x[1])) for x in options] lamb = int(4 + np.floor(3 * np.log(parameters.n))) int_part = [lamb] float_part = [ parameters.mu, parameters.alpha_mu, parameters.c_sigma, parameters.damps, parameters.c_c, parameters.c_1, parameters.c_mu, 0.2, 0.955, 0.5, 0, 0.3, 0.5, 2 ] population = [ MixedIntIndividual(len(discrete_part) + len(int_part) + len(float_part), num_discrete=len(num_options_per_module), num_ints=len(int_part)) ] population[0].genotype = np.array(discrete_part + int_part + float_part) population[0].fitness = ESFitness() while len(population) < Config.GA_mu: population.append(copy(population[0])) u_bound, l_bound = create_bounds(float_part, 0.3) parameters.u_bound[len(options) + 1:] = np.array(u_bound) parameters.l_bound[len(options) + 1:] = np.array(l_bound) gen_sizes, sigmas, fitness, best = _MIES( n=ndim, fitnessFunction=fitnessFunction, budget=Config.GA_budget, mu=Config.GA_mu, lambda_=Config.GA_lambda, parameters=parameters, population=population) # This line does all the work! y = datetime.now() print() print("Best Individual: {}\n" " Fitness: {}\n" "Fitnesses over time: {}".format(best.genotype, best.fitness, fitness)) z = _displayDuration(x, y) if Config.write_output: np.savez("{}final_GA_results_{}dim_f{}_run{}".format( non_bbob_datapath, ndim, fid, run), sigma=sigmas, best_fitness=fitness, best_result=best.genotype, generation_sizes=gen_sizes, time_spent=z)