pyneat.population module

Implements the core of the evolutionary algorithm.

exception pyneat.population.CompleteExtinctionException[source]

Bases: Exception

class pyneat.population.Population(config, initial_state=None)[source]

Bases: object

This class implements the core evolution algorithm.

The steps of the algorithm are as follows:
  1. Evaluate fitness of all genomes.
  2. Check to see if the termination criterion is satisfied; exit if it is.
  3. Generate the next generation from the current population.
  4. Partition the new generation into species based on genetic similarity.
  5. Go to 1.
reporters

The set of reporters used for logging.

Type:ReporterSet
config

The global configuration settings for the entire algorithm.

Type:CustomConfig
reproduction

The reproduction scheme for generating genomes.

Type:Reproduction
innovation_store

The store for innovation records for tracking structural mutations.

Type:InnovationStore
fitness_criterion

The fitness function to assess the population with to test for termination.

Type:function
population

The population of individuals. A dictionary of genome key, genome pairs.

Type:dict
species

The speciation scheme for dividing the population into species.

Type:SpeciesSet
generation

The generation number.

Type:int
best_genome

The best genome discovered so far (according to fitness).

Type:Genome
add_reporter(reporter)[source]

Add a new reporter to the reporter set.

Parameters:reporter (Reporter) – The reporter to add to the reporter set.
remove_reporter(reporter)[source]

Remove a reporter from the reporter set.

Parameters:reporter (Reporter) – The reporter to remove from the reporter set.
run(fitness_function, n=None, **kwargs)[source]

Runs NEAT’s genetic algorithm for at most n generations. If n is None, run until solution is found or extinction occurs.

The user-provided fitness_function must take only two arguments:
  1. The population as a list of (genome id, genome) tuples.
  2. The current configuration object.

The return value of the fitness function is ignored, but it must assign a Python float to the fitness member of each genome.

The fitness function is free to maintain external state, perform evaluations in parallel, etc.

It is assumed that fitness_function does not modify the list of genomes, the genomes themselves (apart from updating the fitness member), or the configuration object.

Parameters:
  • fitness_function (function) – The fitness function to assess genomes with.
  • n (int) – The maximum number of generations to run for.
  • **kwargs – Extra arguments that are passed to the fitness function.
Returns:

The best genome found during the run(s).

Return type:

Genome