예제 #1
0
파일: afpo.py 프로젝트: akloumann/Bot
    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)
예제 #2
0
    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]
예제 #3
0
파일: afpo5t.py 프로젝트: akloumann/Bot
    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)
예제 #4
0
    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)
예제 #5
0
파일: afpo2.py 프로젝트: akloumann/Bot
    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)
예제 #6
0
파일: afpo3.py 프로젝트: akloumann/Bot
    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()
예제 #7
0
    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)
예제 #8
0
파일: afpo.py 프로젝트: akloumann/evo-bot
    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)
예제 #9
0
파일: garef.py 프로젝트: akloumann/Bot
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]