def main(self): self.af_pareto_math(self.xsd, self.ysd, self.ymax) print('\n############# test graph done #############\n') num_rand = c.num_rand_phc envs = ENVIRONMENTS() print('envs to run:', c.envsToRun, ' pop init:', num_rand + len(self.fit_ids)) parents = POPULATION(c.num_rand_phc + len(self.fit_ids)) parents.InitializeRandomPop() parents = self.phc_ga(parents, envs, 1) print('\n############# phc done #############\n') for i in range(0, len(parents.p)): parents.p[i].age += i for i in range(0, len(parents.p)): print('p[' + str(i) + '].age =', parents.p[i].age) # 3rd arg gens=2 by default parents = self.af_pareto_ga(parents, envs) # print('parents fits:') # parents.Print() for j in range(0, len(parents.p)): raw_input('press enter to continue...') for e in c.envsToRun: # for j in range(0, 1): parents.p[j].Start_Evaluation(envs.envs[e], pp=True, pb=False, send=True)
def simple_ga(self, envs): def inner(parents, envs, i): # children = POPULATION(len(parents.p)) children = copy.deepcopy(parents) children.FillFrom(parents) children.Evaluate(envs, False, True) print("\n*** Generation", i, "***") print("\n*** Parents ***") parents.Print() print("*** Children ***") children.Print() print() parents = children return parents envs = ENVIRONMENTS() parents = POPULATION(c.popsize_simple_ga) print('envs:', c.envsToRun, ' pop init:', c.popsize_simple_ga) parents.InitializeRandomPop() parents.Evaluate(envs, False, True) # if c.gen_mode == 'time': # t_end = time.time() + 60 * c.minutes # i = 0 # while(time.time() < t_end): # parents = inner(parents, envs, i) # i += 1 # elif c.gen_mode == 'gens': # for i in range(0, c.gens): # parents = inner(parents, envs, i) for i in range(0, c.numGensDivPop): parents = inner(parents, envs, i) return parents.p[0]
def afpo(self): envs = ENVIRONMENTS() print('envs to run:', c.envsToRun, ' pop init:', c.num_rand_phc + len(self.fit_ids)) parents = POPULATION(c.num_rand_phc + len(self.fit_ids)) parents.InitializeRandomPop() # parents = self.phc_ga(parents, envs, c.afpo2_phc_gens) # print('\n############# phc done #############\n') parents.Evaluate(envs, False, True) for i in range(0, len(parents.p)): parents.p[i].age += i # for i in range(0, len(parents.p)): # print('p[' + str(i) + '].age =', parents.p[i].age) print("Initial population age adjusted") parents.Print() finalpop = self.af_pareto_ga(parents, envs) frontinds = self.af_pareto_math(finalpop.GetAges(), finalpop.GetFits()) finalpopfront = POPULATION(len(frontinds)) for i in range(0, len(frontinds)): finalpopfront.p[i] = finalpop.p[frontinds[i]] finalpopfront.Pickling618() self.ShowEvaluatePop(finalpopfront, envs, pp=True, pb=False)
def main(self): envs = ENVIRONMENTS() parents = POPULATION(c.num_rand_phc + len(self.fit_ids)) print('envs:', c.envsToRun, ' pop init:', c.num_rand_phc + len(self.fit_ids)) parents.InitializeRandomPop() parents.Evaluate(envs, False, True) for i in range(0, len(parents.p)): parents.p[i].age += i self.afpo(parents, envs)
def main(self): t_end = time.time() + 60 * c.minutes envs = ENVIRONMENTS() print('envs to run:', c.envsToRun, ' initial popsize:', c.num_rand_phc) parents = POPULATION(c.num_rand_phc + len(self.fit_ids)) parents.InitializeRandomPop() parents.Evaluate(envs, pp=False, pb=True) parents.Print() if c.alg == 'afpo2': self.afpo() elif c.alg == 'garef': parents = self.garef(c.numGensDivPop, envs, parents, t_end) self.ShowEvaluatePop(parents, envs)
def afpo(self): envs = ENVIRONMENTS() print('envs to run:', c.envsToRun, ' pop init:', c.num_rand_phc + len(self.fit_ids)) parents = POPULATION(c.num_rand_phc + len(self.fit_ids)) parents.InitializeRandomPop() parents = self.phc_ga(parents, envs, c.afpo2_phc_gens) print('\n############# phc done #############\n') for i in range(0, len(parents.p)): parents.p[i].age += i for i in range(0, len(parents.p)): print('p[' + str(i) + '].age =', parents.p[i].age) # 3rd arg gens=2 by default parents = self.af_pareto_ga(parents, envs, c.afpo2_afpo_gens) parents.Pickling618()
def combo_simple_phc_ga(self): envs = ENVIRONMENTS() # parents = POPULATION(c.num_rand_phc) # print('envs:', c.envsToRun, ' pop init:', c.num_rand_phc) # parents.InitializeRandomPop() # parents.Evaluate(envs, False, True) pop_phc = POPULATION(c.combo_ga_num_slots) for k in range(0, c.combo_ga_num_slots): print("***** Slot number", k, "*****") pop_phc.p[k] = self.simple_ga(envs) pop_phc.p[k].ID = k pop_phc = self.phc_ga(pop_phc, envs) pop_phc.Pickling618() self.ShowEvaluatePop(pop_phc, envs, True, False)
def main(self): num_rand = c.num_rand envs = ENVIRONMENTS() print('envs to run', c.envsToRun) parents = POPULATION(c.num_rand + len(self.fit_ids), 0) parents.InitializeRandomPop() for ind in range(0, num_rand + len(self.fit_ids)): print('ind', ind) self.af_pareto(self.xs, self.ys, self.popsize, self.ymax) parents = self.phc_ga(parents, envs, 3) # like phc for j in range(0, len(parents.p)): raw_input('press enter to continue...') for e in c.envsToRun: # for j in range(0, 1): parents.p[j].Start_Evaluation(envs.envs[e], pp=True, pb=False, send=True)
import random import copy import pickle ### new # parents0 = POPULATION(100) # parents0.Initialize() # parents0.Evaluate(envs, pp=False, pb=True) # parents0.Print() # print('********************* done') ### new end i = 0 t_end = time.time() + 60 * c.minutes envs = ENVIRONMENTS() parentsF = POPULATION(len(c.fit_labels)) fit_labels = copy.deepcopy(c.fit_labels) num_rand = c.num_rand_phc print('fit labels', fit_labels) print('envs to run', c.envsToRun) for k in range(0, len(c.fit_labels) + num_rand): print('**********************\nindividual num', k, 'begin\n**********************') parents = POPULATION(c.popSize) if k < num_rand: first = np.random.random_sample((c.numInputs, c.numHidden)) * 2 - 1 second = np.random.random_sample((c.numHidden, c.numOutputs)) * 2 - 1 genome = [first, second]