Customizing Behavior

NEAT-Python allows the user to provide drop-in replacements for some parts of the NEAT algorithm, which hopefully makes it easier to implement common variations of the algorithm as mentioned in the literature. If you find that you’d like to be able to customize something not shown here, please submit an issue on GitHub.

New activation functions

New activation functions are registered with your Config instance, prior to creation of the Population instance, as follows:

def sinc(x):
    return 1.0 if x == 0 else sin(x) / x

config.genome_config.add_activation('my_sinc_function', sinc)

The first argument to add_activation is the name by which this activation function will be referred to in the configuration settings file.

This is demonstrated in the memory-fixed example.

Note

This method is only valid when using the DefaultGenome implementation, with the method being found in the DefaultGenomeConfig implementation; different genome implementations may require a different method of registration.

Reporting/logging

The Population class makes calls to a collection of zero or more reporters at fixed points during the evolution process. The user can add a custom reporter to this collection by calling Population.add_reporter and providing it with an object which implements the same interface as BaseReporter (in reporting.py), probably partially by subclassing it.

StdOutReporter, StatisticsReporter, and Checkpointer may be useful as examples of the behavior you can add using a reporter.

New genome types

To use a different genome type, you can create a custom class whose interface matches that of DefaultGenome and pass this as the genome_type argument to the Config constructor. The minimum genome type interface is documented here: Genome Interface.

This is demonstrated in the circuit evolution example.

Alternatively, you can subclass DefaultGenome in cases where you need to just add some extra behavior. This is done in the OpenAI lander example to add an evolvable per-genome reward discount value. It is also done in the iznn setup, with IZGenome.

Speciation scheme

To use a different speciation scheme, you can create a custom class whose interface matches that of DefaultSpeciesSet and pass this as the species_set_type argument to the Config constructor.

Note

TODO: Further document species set interface (some done in module_summaries)

Note

TODO: Include example

Species stagnation scheme

The default species stagnation scheme is a simple fixed stagnation limit–when a species exhibits no improvement for a fixed number of generations, all its members are removed from the simulation. This behavior is encapsulated in the DefaultStagnation class.

To use a different species stagnation scheme, you must create a custom class whose interface matches that of DefaultStagnation, and provide it as the stagnation_type argument to the Config constructor.

This is demonstrated in the interactive 2D image example.

Reproduction scheme

The default reproduction scheme uses explicit fitness sharing. This behavior is encapsulated in the DefaultReproduction class. The minimum reproduction type interface is documented here: Reproduction Interface

To use a different reproduction scheme, you must create a custom class whose interface matches that of DefaultReproduction, and provide it as the reproduction_type argument to the Config constructor.

Note

TODO: Include example