pyneat.population module¶
Implements the core of the evolutionary algorithm.
-
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:
- Evaluate fitness of all genomes.
- Check to see if the termination criterion is satisfied; exit if it is.
- Generate the next generation from the current population.
- Partition the new generation into species based on genetic similarity.
- 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
-
species
¶ The speciation scheme for dividing the population into species.
Type: SpeciesSet
-
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:
- The population as a list of (genome id, genome) tuples.
- 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: