Class NeatSelection<T extends Comparable<T>>
- Type Parameters:
T
- the fitness value type (typically Double)
- All Implemented Interfaces:
SelectionPolicy
- Direct Known Subclasses:
ImmutableNeatSelection
NeatSelection implements the species-based selection mechanism that is fundamental to NEAT's ability to maintain population diversity and protect structural innovations. It organizes the population into species based on genetic compatibility, applies fitness sharing within species, and manages reproduction allocation to prevent dominant topologies from eliminating exploration.
Key features:
- Species formation: Groups genetically similar individuals using compatibility predicates
- Fitness sharing: Reduces fitness pressure within species to promote diversity
- Species preservation: Maintains minimum viable species sizes
- Reproduction allocation: Distributes offspring based on species average fitness
NEAT species-based selection process:
- Compatibility testing: Apply species predicate to group similar individuals
- Species assignment: Assign individuals to species based on genetic distance
- Fitness adjustment: Apply fitness sharing within each species
- Species filtering: Remove species below minimum size threshold
- Reproduction allocation: Determine offspring count per species
- Within-species selection: Select parents using specified selection policy
Species management parameters:
- Keep ratio: Proportion of each species to preserve for reproduction
- Minimum size: Smallest viable species size to prevent extinction
- Compatibility predicate: Function determining species membership
- Selection policy: Within-species selection strategy
Common usage patterns:
// Default NEAT selection with standard parameters
NeatSelection<Double> defaultSelection = NeatSelection.ofDefault();
// Custom compatibility threshold
BiPredicate<Individual<Double>, Individual<Double>> compatibilityPredicate =
(i1, i2) -> NeatUtils.compatibilityDistance(
i1.genotype(), i2.genotype(), 0, 2, 2, 1.0f
) < 3.0; // Higher threshold = fewer, larger species
NeatSelection<Double> customSelection = NeatSelection.<Double>builder()
.perSpeciesKeepRatio(0.8f) // Keep top 80% of each species
.minSpeciesSize(3) // Minimum 3 individuals per species
.speciesPredicate(compatibilityPredicate)
.speciesSelection(Tournament.of(5)) // Tournament size 5 within species
.build();
// Aggressive diversity preservation
NeatSelection<Double> diverseSelection = NeatSelection.of(
0.95f, // Keep 95% of each species
compatibilityPredicate,
new ProportionalSelection() // Proportional selection within species
);
Compatibility distance calculation:
- Matching genes: Genes with same innovation numbers in both individuals
- Disjoint genes: Genes in one individual within the other's innovation range
- Excess genes: Genes beyond the other individual's highest innovation number
- Weight differences: Average difference in matching gene weights
Species preservation strategies:
- Keep ratio: Ensures a proportion of each species survives selection pressure
- Minimum size: Prevents viable species from going extinct due to random drift
- Fitness sharing: Reduces competition between similar individuals
- Innovation protection: Gives new topologies time to optimize
Integration with genetic operators:
- Crossover compatibility: Species ensure genetic similarity for meaningful recombination
- Mutation guidance: Species composition can influence mutation rates
- Structural innovation: Protected evolution of different network topologies
- Population dynamics: Species formation and extinction drive exploration
Performance considerations:
- Compatibility caching: Distance calculations cached for efficiency
- Species reuse: Species structures maintained across generations
- Parallel evaluation: Species-based organization enables concurrent processing
- Memory efficiency: Efficient species membership tracking
- See Also:
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <U extends Comparable<U>>
NeatSelection.Builder<U> builder()
void
check()
int
Returns the minimum number of individuals required to maintain a species.static <U extends Comparable<U>>
NeatSelection<U> of
(float perSpeciesKeepRatio, BiPredicate<Individual<U>, Individual<U>> speciesPredicate, SelectionPolicy speciesSelection) Creates a NEAT selection policy with custom keep ratio and specified parameters.static <U extends Comparable<U>>
NeatSelection<U> of
(BiPredicate<Individual<U>, Individual<U>> speciesPredicate, SelectionPolicy speciesSelection) Creates a NEAT selection policy with default keep ratio and specified parameters.static <U extends Comparable<U>>
NeatSelection<U> Creates a NEAT selection policy with standard default parameters.float
Returns the proportion of each species to preserve for reproduction.abstract BiPredicate
<Individual<T>, Individual<T>> Returns the predicate used to determine species membership.abstract SelectionPolicy
Returns the selection policy used within each species.
-
Constructor Details
-
NeatSelection
public NeatSelection()
-
-
Method Details
-
perSpeciesKeepRatio
@Default public float perSpeciesKeepRatio()Returns the proportion of each species to preserve for reproduction.This ratio determines what fraction of each species will be retained after fitness-based culling. Higher values preserve more diversity within species but may slow convergence, while lower values increase selection pressure but may lose beneficial genetic variations.
Typical values:
- 0.9 (default): Preserve top 90% of each species
- 0.8-0.95: Balanced diversity preservation
- < 0.8: Aggressive selection pressure
- > 0.95: Minimal selection pressure, maximum diversity
- Returns:
- keep ratio between 0.0 and 1.0 (exclusive of 0.0, inclusive of 1.0)
-
minSpeciesSize
@Default public int minSpeciesSize()Returns the minimum number of individuals required to maintain a species.Species with fewer members than this threshold will be eliminated to prevent resource waste on non-viable populations. This helps focus evolutionary resources on species with sufficient genetic diversity to explore their local fitness landscape effectively.
Typical values:
- 5 (default): Balanced viability threshold
- 3-10: Reasonable range for most problems
- < 3: Very permissive, allows small species to survive
- > 10: Strict threshold, eliminates marginal species
- Returns:
- minimum species size (must be positive)
-
speciesPredicate
Returns the predicate used to determine species membership.This bi-predicate takes two individuals and returns true if they should belong to the same species based on their genetic compatibility. Typically implemented using NEAT compatibility distance with a threshold value.
Common implementations:
- Compatibility distance: Based on matching, disjoint, excess genes and weight differences
- Topological similarity: Based on network structure similarity
- Behavioral similarity: Based on network output patterns
- Custom metrics: Domain-specific similarity measures
- Returns:
- bi-predicate for determining species membership
-
speciesSelection
Returns the selection policy used within each species.After individuals are organized into species, this policy determines how parents are selected within each species for reproduction. Common choices include tournament selection, proportional selection, or rank-based selection.
Selection policy considerations:
- Tournament selection: Good balance of selection pressure and diversity
- Proportional selection: Fitness-proportionate selection within species
- Rank selection: Rank-based selection to avoid fitness scaling issues
- Elite selection: Always select best individuals within species
- Returns:
- selection policy for within-species parent selection
-
check
@Check public void check() -
builder
-
of
public static <U extends Comparable<U>> NeatSelection<U> of(float perSpeciesKeepRatio, BiPredicate<Individual<U>, Individual<U>> speciesPredicate, SelectionPolicy speciesSelection) Creates a NEAT selection policy with custom keep ratio and specified parameters.- Type Parameters:
U
- the fitness value type- Parameters:
perSpeciesKeepRatio
- proportion of each species to preserve (0.0 invalid input: '<' ratio invalid input: '<'= 1.0)speciesPredicate
- predicate for determining species membershipspeciesSelection
- selection policy for within-species parent selection- Returns:
- a new NEAT selection policy with the specified parameters
-
of
public static <U extends Comparable<U>> NeatSelection<U> of(BiPredicate<Individual<U>, Individual<U>> speciesPredicate, SelectionPolicy speciesSelection) Creates a NEAT selection policy with default keep ratio and specified parameters.- Type Parameters:
U
- the fitness value type- Parameters:
speciesPredicate
- predicate for determining species membershipspeciesSelection
- selection policy for within-species parent selection- Returns:
- a new NEAT selection policy with default keep ratio (0.9)
-
ofDefault
Creates a NEAT selection policy with standard default parameters.Default configuration:
- Keep ratio: 0.9 (preserve top 90% of each species)
- Minimum species size: 5 individuals
- Compatibility distance: Threshold of 1.0 with standard coefficients
- Species selection: Tournament selection with size 3
Compatibility distance uses:
- Weight coefficient: 1.0
- Excess gene coefficient: 2.0
- Disjoint gene coefficient: 2.0
- Distance threshold: 1.0
- Type Parameters:
U
- the fitness value type- Returns:
- a new NEAT selection policy with standard default parameters
-