예제 #1
0
def getbest():

    g = NEAT.Genome(0, 3, 0, 1, False,
                    NEAT.ActivationFunction.UNSIGNED_SIGMOID,
                    NEAT.ActivationFunction.UNSIGNED_SIGMOID, 0, params)
    pop = NEAT.Population(g, params, True, 1.0)

    generations = 0
    for generation in range(1000):
        genome_list = NEAT.GetGenomeList(pop)
        fitness_list = NEAT.EvaluateGenomeList_Serial(genome_list,
                                                      evaluate,
                                                      display=False)
        NEAT.ZipFitness(genome_list, fitness_list)

        best = max([x.GetLeader().GetFitness() for x in pop.Species])
        #        print 'Best fitness:', best, 'Species:', len(pop.Species)

        # test
        net = NEAT.NeuralNetwork()
        pop.Species[0].GetLeader().BuildPhenotype(net)
        img = np.zeros((250, 250, 3), dtype=np.uint8)
        img += 10
        NEAT.DrawPhenotype(img, (0, 0, 250, 250), net)

        cv2.imshow("nn_win", img)
        cv2.waitKey(1)

        pop.Epoch()
        #        print "Generation:", generation
        generations = generation
        if best > 15.5:
            break

    return generations
예제 #2
0
def getbest(i):
    g = NEAT.Genome(0, substrate.GetMinCPPNInputs(), 0,
                    substrate.GetMinCPPNOutputs(), False,
                    NEAT.ActivationFunction.TANH, NEAT.ActivationFunction.TANH,
                    0, params)

    pop = NEAT.Population(g, params, True, 1.0, i)
    pop.RNG.Seed(i)

    for generation in range(2000):
        genome_list = NEAT.GetGenomeList(pop)
        fitnesses = NEAT.EvaluateGenomeList_Serial(genome_list,
                                                   evaluate,
                                                   display=False)
        [
            genome.SetFitness(fitness)
            for genome, fitness in zip(genome_list, fitnesses)
        ]

        best = max([x.GetLeader().GetFitness() for x in pop.Species])

        pop.Epoch()
        generations = generation
        if best > 15.0:
            break

    return generations
예제 #3
0
def getbest(i):

    g = NEAT.Genome(0, 3, 0, 1, False,
                    NEAT.ActivationFunction.UNSIGNED_SIGMOID,
                    NEAT.ActivationFunction.UNSIGNED_SIGMOID, 0, params)
    pop = NEAT.Population(g, params, True, 1.0, i)
    pop.RNG.Seed(i)

    generations = 0
    for generation in range(1000):
        genome_list = NEAT.GetGenomeList(pop)
        fitness_list = NEAT.EvaluateGenomeList_Serial(genome_list,
                                                      evaluate,
                                                      display=False)
        NEAT.ZipFitness(genome_list, fitness_list)

        best = max([x.GetLeader().GetFitness() for x in pop.Species])

        pop.Epoch()

        generations = generation
        if best > 15.0:
            break

    return generations
예제 #4
0
def getbest(run):
    g = NEAT.Genome(0, 7, 1, True, NEAT.ActivationFunction.SIGNED_SIGMOID,
                    NEAT.ActivationFunction.SIGNED_SIGMOID, params)

    pop = NEAT.Population(g, params, True, 1.0, run)
    for generation in range(1000):
        #Evaluate genomes
        genome_list = NEAT.GetGenomeList(pop)

        fitnesses = NEAT.EvaluateGenomeList_Serial(genome_list,
                                                   evaluate_xor,
                                                   display=False)
        [
            genome.SetFitness(fitness)
            for genome, fitness in zip(genome_list, fitnesses)
        ]

        # Print best fitness
        #print("---------------------------")
        #print("Generation: ", generation)
        #print("max ", max([x.GetLeader().GetFitness() for x in pop.Species]))

        # Visualize best network's Genome
        '''
        net = NEAT.NeuralNetwork()
        pop.Species[0].GetLeader().BuildPhenotype(net)
        img = np.zeros((500, 500, 3), dtype=np.uint8)
        img += 10
        NEAT.DrawPhenotype(img, (0, 0, 500, 500), net )
        cv2.imshow("CPPN", img)
        # Visualize best network's Pheotype
        net = NEAT.NeuralNetwork()
        pop.Species[0].GetLeader().Build_ES_Phenotype(net, substrate, params)
        img = np.zeros((500, 500, 3), dtype=np.uint8)
        img += 10

        Utilities.DrawPhenotype(img, (0, 0, 500, 500), net, substrate=True )
        cv2.imshow("NN", img)
        cv2.waitKey(1)
        '''
        if max([x.GetLeader().GetFitness() for x in pop.Species]) > 15.0:
            break

        # Epoch
        generations = generation
        pop.Epoch()

    return generations
예제 #5
0
def getbest():
    g = NEAT.Genome(0, substrate.GetMinCPPNInputs(), 0,
                    substrate.GetMinCPPNOutputs(), False,
                    NEAT.ActivationFunction.SIGNED_GAUSS,
                    NEAT.ActivationFunction.SIGNED_GAUSS, 0, params)

    pop = NEAT.Population(g, params, True, 1.0)

    for generation in range(1000):
        genome_list = NEAT.GetGenomeList(pop)
        #    fitnesses = NEAT.EvaluateGenomeList_Parallel(genome_list, evaluate)
        fitnesses = NEAT.EvaluateGenomeList_Serial(genome_list,
                                                   evaluate,
                                                   display=False)
        [
            genome.SetFitness(fitness)
            for genome, fitness in zip(genome_list, fitnesses)
        ]

        best = max([x.GetLeader().GetFitness() for x in pop.Species])
        #        print 'Best fitness:', best

        # test
        net = NEAT.NeuralNetwork()
        pop.Species[0].GetLeader().BuildPhenotype(net)
        img = np.zeros((250, 250, 3), dtype=np.uint8)
        img += 10
        NEAT.DrawPhenotype(img, (0, 0, 250, 250), net)
        cv2.imshow("CPPN", img)

        net = NEAT.NeuralNetwork()
        pop.Species[0].GetLeader().BuildHyperNEATPhenotype(net, substrate)
        img = np.zeros((250, 250, 3), dtype=np.uint8)
        img += 10
        NEAT.DrawPhenotype(img, (0, 0, 250, 250), net, substrate=True)
        cv2.imshow("NN", img)

        cv2.waitKey(1)

        pop.Epoch()
        #        print "Generation:", generation
        generations = generation
        if best > 15.5:
            break

    return generations
예제 #6
0
def getbest():
    g = NEAT.Genome(0, 7, 1, False, NEAT.ActivationFunction.SIGNED_SIGMOID,
                    NEAT.ActivationFunction.SIGNED_SIGMOID, params)

    pop = NEAT.Population(g, params, True, 1.0)

    for generation in range(2000):

        genome_list = NEAT.GetGenomeList(pop)
        #    fitnesses = NEAT.EvaluateGenomeList_Parallel(genome_list, evaluate)
        fitnesses = NEAT.EvaluateGenomeList_Serial(genome_list,
                                                   evaluate_xor,
                                                   display=True)
        [
            genome.SetFitness(fitness)
            for genome, fitness in zip(genome_list, fitnesses)
        ]

        best = max([x.GetLeader().GetFitness() for x in pop.Species])

        net = NEAT.NeuralNetwork()
        pop.Species[0].GetLeader().BuildPhenotype(net)
        img = np.zeros((500, 500, 3), dtype=np.uint8)
        img += 10
        NEAT.DrawPhenotype(img, (0, 0, 500, 500), net)
        cv2.imshow("CPPN", img)

        net = NEAT.NeuralNetwork()
        pop.Species[0].GetLeader().Build_ES_Phenotype(net, substrate, params)
        img = np.zeros((500, 500, 3), dtype=np.uint8)
        img += 10

        utilities.DrawPhenotype(img, (0, 0, 500, 500), net, substrate=True)
        cv2.imshow("NN", img)
        cv2.waitKey(1)

        generations = generation

        if best > 15.0:
            break

        pop.Epoch()

    return generations
예제 #7
0
파일: fool.py 프로젝트: yazici/fobj
def objective_driven(seed):
    i = seed
    g = NEAT.Genome(0, 6, 0, 4, False, NEAT.ActivationFunction.SIGNED_SIGMOID,
                    NEAT.ActivationFunction.SIGNED_SIGMOID, 0, params)
    pop = NEAT.Population(g, params, True, 1.0, i)
    #pop.RNG.Seed(i)

    generations = 0
    for generation in range(250):
        genome_list = NEAT.GetGenomeList(pop)
        fitness_list = NEAT.EvaluateGenomeList_Serial(genome_list,
                                                      evaluate,
                                                      display=False)
        fitness_list = [k[0] for k in fitness_list]
        NEAT.ZipFitness(genome_list, fitness_list)

        best_fits = [x.GetLeader().GetFitness() for x in pop.Species]
        best = max(best_fits)
        idx = best_fits.index(best)
        print best, pop.Species[idx].GetLeader().GetFitness()
        imgs, res = evaluate(pop.Species[idx].GetLeader(),
                             debug=True,
                             save="gen%d.ply" % generation)

        plt.ion()
        plt.clf()
        subfig = 1
        t_imgs = len(imgs)
        for img in imgs:
            plt.subplot(t_imgs, 1, subfig)
            plt.title("Confidence: %0.2f%%" %
                      (res[subfig - 1, target_class] * 100.0))
            plt.imshow(img)
            subfig += 1
        plt.draw()
        plt.pause(0.1)
        plt.savefig("out%d.png" % generation)
        pop.Epoch()

        generations = generation

    return generations
예제 #8
0
                print(k, '= %3.4f' % v, end=', ')
            else:
                print(k, '= {0}'.format(v), end=', ')
        print()
    print('Links:')
    for tr in g.GetLinkTraits():
        print(tr[0], tr[1], end=': ')
        for k, v in tr[2].items():
            if isinstance(v, float):
                print(k, '= %3.4f' % v, end=', ')
            else:
                print(k, '= {0}'.format(v), end=', ')
        print()
    print()


for generation in range(1000):

    genome_list = NEAT.GetGenomeList(pop)
    fitness_list = NEAT.EvaluateGenomeList_Serial(genome_list,
                                                  evaluate,
                                                  display=False)
    NEAT.ZipFitness(genome_list, fitness_list)

    PrintGenomeTraits(pop.GetBestGenome())
    print()
    print('Fitnesss:', max(fitness_list), 'Generation:', generation)
    print()

    pop.Epoch()
예제 #9
0
rng = NEAT.RNG()
#rng.TimeSeed()
rng.TimeSeed()

g = NEAT.Genome(0, substrate.GetMinCPPNInputs(), 0,
                substrate.GetMinCPPNOutputs(), False,
                NEAT.ActivationFunction.TANH, NEAT.ActivationFunction.TANH, 0,
                params)

pop = NEAT.Population(g, params, True, 1.0)

for generation in range(1000):
    genome_list = NEAT.GetGenomeList(pop)
    #    fitnesses, elapsed = NEAT.EvaluateGenomeList_Parallel(genome_list, evaluate, 4)
    fitnesses, elapsed = NEAT.EvaluateGenomeList_Serial(genome_list, evaluate)
    [
        genome.SetFitness(fitness)
        for genome, fitness in zip(genome_list, fitnesses)
    ]

    print 'Best fitness:', max(
        [x.GetLeader().GetFitness() for x in pop.Species])

    # test
    net = NEAT.NeuralNetwork()
    pop.Species[0].GetLeader().BuildPhenotype(net)
    img = np.zeros((250, 250, 3), dtype=np.uint8)
    img += 10
    NEAT.DrawPhenotype(img, (0, 0, 250, 250), net)
    cv2.imshow("CPPN", img)