Exemplo n.º 1
0
    def evaluate_network(self, evaluation_function):
        print "Evaluating the networks..."

        # Reset statistics.
        self.evaluation = []
        self.max_fitness = []
        self.node_count = []
        self.link_count = []

        # Load population.
        population = neat.loadFromPopulation(self.filename)

        # Go through each generation, build the best network, and evaluate the completion results.
        for generation in xrange(population.getGenerationCount()):
            # First individual is always the most fit.
            ind = population.getIndividual(0, generation)
            self.max_fitness.append(ind.getFitness())
            self.node_count.append(ind.getNodesCount())
            self.link_count.append(ind.getLinksCount())

            # Build network.
            net = ind.spawnFastPhenotypeStack()

            # Evaluate the network.
            self.evaluation.append(evaluation_function(net))
Exemplo n.º 2
0
    def evaluate_network( self, evaluation_function ):
        print "Evaluating the networks..."

        # Reset statistics.
        self.evaluation = []
        self.max_fitness = []
        self.node_count = []
        self.link_count = []

        # Load population.
        population = neat.loadFromPopulation( self.filename )

        # Go through each generation, build the best network, and evaluate the completion results.
        for generation in xrange(population.getGenerationCount()):
           # First individual is always the most fit.
           ind = population.getIndividual( 0, generation )
           self.max_fitness.append( ind.getFitness() )
           self.node_count.append( ind.getNodesCount() )
           self.link_count.append( ind.getLinksCount() )

           # Build network.
           net = ind.spawnFastPhenotypeStack()

           # Evaluate the network.
           self.evaluation.append( evaluation_function(net) )
Exemplo n.º 3
0
import PyHyperNEAT as neat
import sys

file = sys.argv[1]
pop = neat.loadFromPopulation( file )
generations = pop.getGenerationCount()
individuals = pop.getIndividualCount(generations-1)

print "Loaded population from '%s'..." % file
print " - Generations: %d" % generations
print " - Ind/gen:     %d" % individuals

print "Determining maximum fitness..."

speciesIDs = set()
max_fit = -1
max_fit_id = -1
max_fit_species = -1
for i in xrange(individuals):
    ind = pop.getIndividual( i, generations-1 )
    fitness = ind.getFitness()
    speciesID = ind.getSpeciesID()
    if speciesID not in speciesIDs:
        print " - Found new species ID: %d" % speciesID
        speciesIDs.add( speciesID )
        speciesIDs.add(speciesID)
    print " - Evaluating individual %d (fitness %f; species %d)..." % (i, fitness, speciesID)
    if fitness > max_fit:
        print "   - Found new fitness leader! %f -> %f" % (max_fit, fitness)
        max_fit = fitness
        max_fit_id = i