Ejemplo n.º 1
0
def evaluate_ann(ann):
    score = catandmouse.game_function(ann, True)
    return score
Ejemplo n.º 2
0
best=None
for generation in range(generations):
    for individual in population:
        individual.evaluate()
    population.sort(key=lambda x:x.fitness,reverse=True)
    population=population[0:pop_size/2]
    best=population[0]
    print generation, population[0].fitness
    new_population = [best]
    for x in range(1,pop_size):
        if random.random()<0.5:
            child=random.choice(population).mutate()
            new_population.append(child)
        else:
            p1 = random.choice(population)
            p2 = random.choice(population)
            child=p1.crossover(p2)
            new_population.append(child)
    population=new_population


from catandmouse import game_function
ann=best.create_neuron()
print game_function(ann,True)

#from pylab import *
#xlabel("Generations")
#ylabel("Avg Fitness")
#plot(fitness)
#show()