Configuration file description

The configuration file is in the format described in the Python configparser documentation as “a basic configuration file parser language which provides a structure similar to what you would find on Microsoft Windows INI files.”

Most settings must be explicitly enumerated in the configuration file. (This makes it less likely that library code changes will result in your project silently using different NEAT settings. There are some defaults, as noted below, and insofar as possible new configuration parameters will default to the existing behavior.)

Note that the Config constructor also requires you to explicitly specify the types that will be used for the NEAT simulation. This, again, is to help avoid silent changes in behavior.

The configuration file is in several sections, of which at least one is required. However, there are no requirements for ordering within these sections, or for ordering of the sections themselves.

[NEAT] section

The NEAT section specifies parameters particular to the generic NEAT algorithm or the experiment itself. This section is always required, and is handled by the Config class itself.

  • fitness_criterion

    The function used to compute the termination criterion from the set of genome fitnesses. Allowable values are: min, max, and mean

  • fitness_threshold

    When the fitness computed by fitness_criterion meets or exceeds this threshold, the evolution process will terminate, with a call to any registered reporting class’ found_solution method.

Note

The found_solution method is not called if the maximum number of generations is reached without the above threshold being passed (if attention is being paid to fitness for termination in the first place - see no_fitness_termination below).

  • no_fitness_termination

    If this evaluates to True, then the fitness_criterion and fitness_threshold are ignored for termination; only valid if termination by a maximum number of generations passed to population.Population.run() is enabled, and the found_solution method is called upon generation number termination. If it evaluates to False, then fitness is used to determine termination. This defaults to “False”.

    Added in version 0.92.

  • pop_size

    The number of individuals in each generation.

  • reset_on_extinction

    If this evaluates to True, when all species simultaneously become extinct due to stagnation, a new random population will be created. If False, a CompleteExtinctionException will be thrown.

  • seed

    Optional random seed for reproducible evolution. If specified, sets the seed for Python’s random module, making evolution deterministic. If omitted or set to None, behavior is non-deterministic (different results each run). This parameter is optional and defaults to None.

    Example usage:

    [NEAT]
    pop_size = 150
    seed = 42  # Enable reproducibility
    

    The seed can also be set or overridden programmatically:

    pop = neat.Population(config, seed=42)
    

    For detailed information about reproducibility, including parallel evaluation and best practices, see Reproducibility.

    Added in version 1.1.

[DefaultStagnation] section

The DefaultStagnation section specifies parameters for the builtin DefaultStagnation class. This section is only necessary if you specify this class as the stagnation implementation when creating the Config instance; otherwise you need to include whatever configuration (if any) is required for your particular implementation.

  • species_fitness_func

    The function used to compute species fitness. This defaults to ``mean``. Allowed values are: max, min, mean, median (returns the upper-middle element for even-length inputs), and median2 (averages the two middle values for even-length inputs — the conventional statistical median).

Note

This is not used for calculating species fitness for apportioning reproduction (which always uses mean).

  • max_stagnation

    Species that have not shown improvement in more than this number of generations will be considered stagnant and removed. This defaults to 15.

  • species_elitism

    The number of species that will be protected from stagnation; mainly intended to prevent total extinctions caused by all species becoming stagnant before new species arise. For example, a species_elitism setting of 3 will prevent the 3 species with the highest species fitness from being removed for stagnation regardless of the amount of time they have not shown improvement. This defaults to 0.

[DefaultReproduction] section

The DefaultReproduction section specifies parameters for the builtin DefaultReproduction class. This section is only necessary if you specify this class as the reproduction implementation when creating the Config instance; otherwise you need to include whatever configuration (if any) is required for your particular implementation.

  • elitism

    The number of most-fit individuals in each species that will be preserved as-is from one generation to the next. This defaults to 0. Note: the effective minimum per-species population is max(min_species_size, elitism) to ensure elites are always preserved.

  • survival_threshold

    The fraction for each species allowed to reproduce each generation. This defaults to 0.2.

  • min_species_size

    The minimum number of genomes per species after reproduction. This defaults to 1. Note: the effective minimum per-species population is max(min_species_size, elitism) to ensure elites are always preserved.

  • fitness_sharing

    The method used to compute adjusted fitness for offspring allocation. Valid values are:

    • normalized - Species mean fitness is normalized to [0, 1] based on population min/max. This is the default and preserves existing behavior.

    • canonical - Species mean fitness is used directly (no normalization), matching the canonical NEAT paper. This preserves the ratio of fitness values between species, unlike normalized sharing which creates rank-like selection pressure.

    Added in version 2.1.

  • spawn_method

    The method used to allocate offspring counts across species. Valid values are:

    • smoothed - Offspring counts move halfway toward target each generation (momentum-based). This is the default and preserves existing behavior.

    • proportional - Direct proportional allocation based on adjusted fitness. Offspring counts change immediately to match fitness ratios, matching canonical NEAT.

    Added in version 2.1.

  • interspecies_crossover_prob

    The probability that an offspring’s second parent is selected from a different species. The canonical NEAT paper uses a small value (0.001). This defaults to 0.0 (disabled, preserving existing behavior).

    Added in version 2.1.

[DefaultSpeciesSet] section

The DefaultSpeciesSet section specifies parameters for the builtin DefaultSpeciesSet class. This section is only necessary if you specify this class as the species set implementation when creating the Config instance; otherwise you need to include whatever configuration (if any) is required for your particular implementation.

  • compatibility_threshold

    Individuals whose genomic distance is less than this threshold are considered to be in the same species.

  • target_num_species

    If set to an integer, the compatibility threshold will be dynamically adjusted after each generation to try to maintain this number of species. If set to none (the default), the threshold is static. The canonical NEAT paper describes this dynamic adjustment mechanism. This defaults to “none”.

    Added in version 2.1.

  • threshold_adjust_rate

    The amount by which the compatibility threshold is adjusted each generation when target_num_species is set. If there are too many species, the threshold increases by this amount; if too few, it decreases. This defaults to 0.1.

    Added in version 2.1.

  • threshold_min

    The minimum allowed value for the compatibility threshold during dynamic adjustment. This defaults to 0.1.

    Added in version 2.1.

  • threshold_max

    The maximum allowed value for the compatibility threshold during dynamic adjustment. This defaults to 100.0.

    Added in version 2.1.

[DefaultGenome] section

The DefaultGenome section specifies parameters for the builtin DefaultGenome class. This section is only necessary if you specify this class as the genome implementation when creating the Config instance; otherwise you need to include whatever configuration (if any) is required for your particular implementation.

  • activation_mutate_rate

    The probability that mutation will replace the node’s activation function with a randomly-determined member of the activation_options. Valid values are in [0.0, 1.0].

  • activation_options

    A space-separated list of the activation functions that may be used by nodes. This parameter is required. The built-in available functions can be found in Overview of builtin activation functions; more can be added as described in Customizing Behavior. If you only need one activation function, set activation_options to just that one name (e.g. activation_options = sigmoid) and set activation_mutate_rate = 0.0.

  • aggregation_mutate_rate

    The probability that mutation will replace the node’s aggregation function with a randomly-determined member of the aggregation_options. Valid values are in [0.0, 1.0].

  • aggregation_options

    A space-separated list of the aggregation functions that may be used by nodes. This parameter is required. The available functions (defined in aggregations) are: sum, product, min, max, mean, median, and maxabs (which returns the input value with the greatest absolute value; the returned value may be positive or negative). New aggregation functions can be defined similarly to new activation functions. (Note that the function needs to take a list or other iterable; the reduce function, as in aggregations, may be of use in this.)

    Changed in version 0.92: Moved out of genome into aggregations; maxabs, mean, and median added; method for defining new aggregation functions added.

  • bias_init_mean

    The mean of the normal/gaussian distribution, if it is used to select bias attribute values for new nodes.

  • bias_init_stdev

    The standard deviation of the normal/gaussian distribution, if it is used to select bias values for new nodes.

  • bias_init_type

    If set to gaussian or normal, then the initialization is to a normal/gaussian distribution. If set to uniform, a uniform distribution from \(\max(bias\_min\_value, (bias\_init\_mean-(bias\_init\_stdev*2)))\) to \(\min(bias\_max\_value, (bias\_init\_mean+(bias\_init\_stdev*2)))\). (Note that the standard deviation of a uniform distribution is not range/0.25, as implied by this, but the range divided by a bit over 0.288 (the square root of 12); however, this approximation makes setting the range much easier.) This defaults to “gaussian”.

    Added in version 0.92.

  • bias_max_value

    The maximum allowed bias value. Biases above this value will be clamped to this value.

  • bias_min_value

    The minimum allowed bias value. Biases below this value will be clamped to this value.

  • bias_mutate_power

    The standard deviation of the zero-centered normal/gaussian distribution from which a bias value mutation is drawn.

  • bias_mutate_rate

    The probability that mutation will change the bias of a node by adding a random value.

  • bias_replace_rate

    The probability that mutation will replace the bias of a node with a newly chosen random value (as if it were a new node).

  • compatibility_disjoint_coefficient

    The coefficient for the disjoint gene counts’ contribution to the genomic distance. Also used for excess genes unless compatibility_excess_coefficient is explicitly set.

  • compatibility_excess_coefficient

    The coefficient for the excess gene counts’ contribution to the genomic distance. Excess genes are those with innovation numbers beyond the range of the other genome. This defaults to “auto”, meaning the value of compatibility_disjoint_coefficient is used. Set to a numeric value (e.g., 1.0) to weight excess genes differently from disjoint genes, matching the canonical NEAT formula where c₁ (excess) and c₂ (disjoint) are separate coefficients.

    Added in version 2.1.

Note

It is currently possible for two homologous nodes or connections to have a higher contribution to the genomic distance than a disjoint or excess node or connection, depending on their attributes and the settings of the above parameters.

  • compatibility_include_node_genes

    If True, node gene differences contribute to the genomic distance. If False, only connection genes are used, matching the canonical NEAT distance formula. This defaults to True.

    Added in version 2.1.

  • compatibility_enable_penalty

    The penalty added to the distance between two homologous connections when their enabled/disabled states differ. The canonical NEAT paper does not include this penalty. Set to 0.0 to disable it. This defaults to 1.0.

    Added in version 2.1.

  • conn_add_prob

    The probability that mutation will add a connection between existing nodes. Valid values are in [0.0, 1.0].

  • conn_delete_prob

    The probability that mutation will delete an existing connection. Valid values are in [0.0, 1.0].

  • enabled_default

    The default enabled attribute of newly created connections. Valid values are True and False (and their case-insensitive equivalents 1/0, on/off, yes/no) for a fixed initial state, or random (alias none) to give each new connection an independent 50/50 enabled/disabled state.

Note

“Newly created connections” include ones in newly-created genomes, if those have initial connections (from the setting of the initial_connection variable).

  • enabled_mutate_rate

    The probability that mutation will replace (50/50 chance of True or False) the enabled status of a connection. Valid values are in [0.0, 1.0].

  • enabled_rate_to_false_add

    Adds to the enabled_mutate_rate if the connection is currently enabled.

  • enabled_rate_to_true_add

    Adds to the enabled_mutate_rate if the connection is currently not enabled.

    Added in version 0.92: enabled_rate_to_false_add and enabled_rate_to_true_add

  • feed_forward

    If this evaluates to True, generated networks will not be allowed to have recurrent connections (they will be feedforward). Otherwise they may be (but are not forced to be) recurrent.

  • initial_connection

    Specifies the initial connectivity of newly-created genomes. (Note the effects on settings other than unconnected of the enabled_default parameter.) There are seven primary values:

    • unconnected - No connections are initially present. This is the default.

    • fs_neat_nohidden - One randomly-chosen input node has one connection to each output node. (This is one version of the FS-NEAT scheme; “FS” stands for “Feature Selection”.)

    • fs_neat_hidden - One randomly-chosen input node has one connection to each hidden and output node. (This is another version of the FS-NEAT scheme. If there are no hidden nodes, it is the same as fs_neat_nohidden.)

    • full_nodirect - Each input node is connected to all hidden nodes, if there are any, and each hidden node is connected to all output nodes; otherwise, each input node is connected to all output nodes. Genomes with feed_forward set to False will also have recurrent (loopback, in this case) connections from each hidden or output node to itself.

    • full_direct - Each input node is connected to all hidden and output nodes, and each hidden node is connected to all output nodes. Genomes with feed_forward set to False will also have recurrent (loopback, in this case) connections from each hidden or output node to itself.

    • partial_nodirect # - As for full_nodirect, but each connection has a probability of being present determined by the number (valid values are in [0.0, 1.0]).

    • partial_direct # - As for full_direct, but each connection has a probability of being present determined by the number (valid values are in [0.0, 1.0]).

    Older versions of the documentation sometimes referred to this setting as none when no initial connections are present; the correct configuration value is unconnected. The string none is not a valid value for initial_connection.

    In addition, the following legacy aliases are accepted for backward compatibility but are deprecated and will be removed in a future version:

    • fs_neat - Behaves like fs_neat_nohidden; when hidden nodes are present it emits a warning and connects only inputs to outputs.

    • full - Behaves like full_nodirect; when hidden nodes are present it emits a warning and creates no direct input-output connections.

    • partial - Behaves like partial_nodirect (typically used as partial <fraction>); when hidden nodes are present it emits a warning and creates no direct input-output connections.

Changed in version 0.92: fs_neat split into fs_neat_nohidden and fs_neat_hidden; full, partial split into full_nodirect, full_direct, partial_nodirect, partial_direct

  • node_add_prob

    The probability that mutation will add a new node (essentially replacing an existing connection, the enabled status of which will be set to False). Valid values are in [0.0, 1.0].

  • node_delete_prob

    The probability that mutation will delete an existing node (and all connections to it). Valid values are in [0.0, 1.0].

  • num_hidden

    The number of hidden nodes to add to each genome in the initial population.

  • num_inputs

    The number of input nodes, through which the network receives inputs.

  • num_outputs

    The number of output nodes, to which the network delivers outputs.

  • response_init_mean

    The mean of the normal/gaussian distribution, if it is used to select response multiplier attribute values for new nodes.

  • response_init_stdev

    The standard deviation of the normal/gaussian distribution, if it is used to select response multipliers for new nodes.

  • response_init_type

    If set to gaussian or normal, then the initialization is to a normal/gaussian distribution. If set to uniform, a uniform distribution from \(\max(response\_min\_value, (response\_init\_mean-(response\_init\_stdev*2)))\) to \(\min(response\_max\_value, (response\_init\_mean+(response\_init\_stdev*2)))\). (Note that the standard deviation of a uniform distribution is not range/0.25, as implied by this, but the range divided by a bit over 0.288 (the square root of 12); however, this approximation makes setting the range much easier.) This defaults to “gaussian”.

    Added in version 0.92.

  • response_max_value

    The maximum allowed response multiplier. Response multipliers above this value will be clamped to this value.

  • response_min_value

    The minimum allowed response multiplier. Response multipliers below this value will be clamped to this value.

  • response_mutate_power

    The standard deviation of the zero-centered normal/gaussian distribution from which a response multiplier mutation is drawn.

  • response_mutate_rate

    The probability that mutation will change the response multiplier of a node by adding a random value.

  • response_replace_rate

    The probability that mutation will replace the response multiplier of a node with a newly chosen random value (as if it were a new node).

  • time_constant_init_mean

    The mean of the normal/gaussian distribution used to select time constant values for new nodes. Default: 1.0. Only relevant for CTRNN networks; for feedforward and discrete-time recurrent networks this attribute is unused.

  • time_constant_init_stdev

    The standard deviation of the distribution used to select time constant values for new nodes. Default: 0.0 (all new nodes start with the mean value).

  • time_constant_init_type

    If set to gaussian or normal, time constant initialization uses a normal/gaussian distribution. If set to uniform, a uniform distribution over the range derived from time_constant_init_mean and time_constant_init_stdev, clamped by time_constant_min_value and time_constant_max_value. Default: “gaussian”. Only relevant for CTRNN networks.

  • time_constant_max_value

    The maximum allowed time constant value. Default: 10.0.

  • time_constant_min_value

    The minimum allowed time constant value. Default: 0.01.

  • time_constant_mutate_power

    The standard deviation of the zero-centered normal/gaussian distribution from which a time constant mutation value is drawn. Default: 0.0 (no mutation).

  • time_constant_mutate_rate

    The probability that mutation will change the time constant of a node by adding a random value. Default: 0.0 (no mutation).

  • time_constant_replace_rate

    The probability that mutation will replace the time constant of a node with a newly chosen random value. Default: 0.0 (no replacement).

Added in version 2.0.

  • single_structural_mutation

    If this evaluates to True, only one structural mutation (the addition or removal of a node or connection) will be allowed per genome per generation. (If the probabilities for conn_add_prob, conn_delete_prob, node_add_prob, and node_delete_prob add up to over 1, the chances of each are proportional to the appropriate configuration value.) This defaults to “False”.

    Added in version 0.92.

  • structural_mutation_surer

    If this evaluates to True, then an attempt to add a node to a genome lacking connections will result in adding a connection instead; furthermore, if an attempt to add a connection tries to add a connection that already exists, that connection will be enabled. If this is set to default, then it acts as if it had the same value as single_structural_mutation (above). This defaults to “default”.

    Added in version 0.92.

  • weight_init_stdev

    The standard deviation of the normal/gaussian distribution used to select weight values for new connections.

  • weight_init_type

    If set to gaussian or normal, then the initialization is to a normal/gaussian distribution. If set to uniform, a uniform distribution from \(\max(weight\_min\_value, (weight\_init\_mean-(weight\_init\_stdev*2)))\) to \(\min(weight\_max\_value, (weight\_init\_mean+(weight\_init\_stdev*2)))\). (Note that the standard deviation of a uniform distribution is not range/0.25, as implied by this, but the range divided by a bit over 0.288 (the square root of 12); however, this approximation makes setting the range much easier.) This defaults to “gaussian”.

    Added in version 0.92.

  • weight_max_value

    The maximum allowed weight value. Weights above this value will be clamped to this value.

  • weight_min_value

    The minimum allowed weight value. Weights below this value will be clamped to this value.

  • weight_mutate_power

    The standard deviation of the zero-centered normal/gaussian distribution from which a weight value mutation is drawn.

  • weight_mutate_rate

    The probability that mutation will change the weight of a connection by adding a random value.

  • weight_replace_rate

    The probability that mutation will replace the weight of a connection with a newly chosen random value (as if it were a new connection).

Table of Contents