Class NeatSelectorImpl<T extends Number & Comparable<T>>
- Type Parameters:
T
- the fitness value type (typically Double)
- All Implemented Interfaces:
Selector<T>
NeatSelectorImpl implements the core 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, manages species lifecycle, and allocates reproduction opportunities across species.
NEAT selection process:
- Species assignment: Organize population into species using compatibility predicate
- Species trimming: Remove lower-performing individuals within each species
- Species filtering: Eliminate species below minimum viable size
- Reproduction allocation: Determine number of offspring for each species
- Parent selection: Select parents within species using configured selector
- Species maintenance: Update species representatives for next generation
Key features:
- Genetic compatibility: Groups individuals with similar network topologies
- Fitness sharing: Reduces competition between similar individuals
- Innovation protection: Allows new topologies time to optimize
- Population diversity: Maintains multiple species exploring different solutions
Species management:
- Species formation: Creates new species when compatibility threshold exceeded
- Species growth: Assigns compatible individuals to existing species
- Species extinction: Eliminates species that fall below minimum size
- Species continuity: Maintains species representatives across generations
Common usage patterns:
// Create NEAT selector implementation
RandomGenerator randomGen = RandomGenerator.getDefault();
SpeciesIdGenerator speciesIdGen = new SpeciesIdGenerator();
// Configure species predicate for compatibility
BiPredicate<Individual<Double>, Individual<Double>> speciesPredicate =
(i1, i2) -> NeatUtils.compatibilityDistance(
i1.genotype(), i2.genotype(), 0, 2, 2, 1.0f
) < 3.0; // Compatibility threshold
// Configure NEAT selection policy
NeatSelection<Double> neatSelection = NeatSelection.<Double>builder()
.perSpeciesKeepRatio(0.8f) // Keep top 80% of each species
.minSpeciesSize(5) // Minimum 5 individuals per species
.speciesPredicate(speciesPredicate)
.speciesSelection(Tournament.of(3)) // Tournament within species
.build();
// Create within-species selector
Selector<Double> speciesSelector = new TournamentSelector<>(randomGen, 3);
// Create NEAT selector
NeatSelectorImpl<Double> selector = new NeatSelectorImpl<>(
randomGen, neatSelection, speciesIdGen, speciesSelector
);
// Use in population selection
Population<Double> selectedPopulation = selector.select(
eaConfiguration, population, 100 // Select 100 individuals
);
Species lifecycle management:
- Initialization: Empty species list for first generation
- Assignment: Individuals assigned to species based on compatibility
- Trimming: Poor performers removed while preserving species diversity
- Reproduction: Offspring allocated proportionally to species average fitness
- Evolution: Species composition changes as population evolves
Fitness sharing mechanism:
- Within-species competition: Individuals primarily compete within their species
- Species-based allocation: Reproduction opportunities distributed across species
- Diversity protection: Prevents single topology from dominating population
- Innovation preservation: New structural innovations get time to optimize
Performance considerations:
- Compatibility caching: Species assignment optimized for repeated use
- Efficient trimming: In-place species membership updates
- Memory management: Species structures reused across generations
- Parallel processing: Species-based organization enables concurrent operations
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final org.apache.logging.log4j.Logger
private final NeatSelection
<T> private final RandomGenerator
private final SpeciesIdGenerator
-
Constructor Summary
ConstructorsConstructorDescriptionNeatSelectorImpl
(RandomGenerator _randomGenerator, NeatSelection<T> _neatSelection, SpeciesIdGenerator _speciesIdGenerator, Selector<T> _speciesSelector) Constructs a new NEAT selector implementation with the specified components. -
Method Summary
Modifier and TypeMethodDescriptioneliminateLowestPerformers
(AbstractEAConfiguration<T> eaConfiguration, List<Species<T>> allSpecies) Eliminates the lowest-performing individuals from all species while maintaining species diversity.select
(AbstractEAConfiguration<T> eaConfiguration, int numIndividuals, List<Genotype> genotypes, List<T> fitnessScore) Selects a specified number of individuals from the given population based on their fitness values.trimSpecies
(Species<T> species, Comparator<Individual<T>> comparator, int minSpeciesSize, float perSpeciesKeepRatio) Trims a species by removing lower-performing individuals while preserving minimum viable size.
-
Field Details
-
logger
public static final org.apache.logging.log4j.Logger logger -
randomGenerator
-
neatSelection
-
speciesIdGenerator
-
speciesSelector
-
previousSpecies
-
-
Constructor Details
-
NeatSelectorImpl
public NeatSelectorImpl(RandomGenerator _randomGenerator, NeatSelection<T> _neatSelection, SpeciesIdGenerator _speciesIdGenerator, Selector<T> _speciesSelector) Constructs a new NEAT selector implementation with the specified components.The selector uses the random generator for stochastic decisions, the NEAT selection policy for species management parameters, the species ID generator for creating new species, and the species selector for within-species parent selection.
- Parameters:
_randomGenerator
- random number generator for stochastic selection operations_neatSelection
- NEAT selection policy defining species management parameters_speciesIdGenerator
- generator for unique species identifiers_speciesSelector
- selector for choosing parents within each species- Throws:
IllegalArgumentException
- if any parameter is null
-
-
Method Details
-
trimSpecies
protected Species<T> trimSpecies(Species<T> species, Comparator<Individual<T>> comparator, int minSpeciesSize, float perSpeciesKeepRatio) Trims a species by removing lower-performing individuals while preserving minimum viable size.This method applies fitness-based selection within a species, keeping the best performers while ensuring the species maintains sufficient size for genetic diversity. The number of individuals kept is the maximum of the minimum species size and the keep ratio applied to the current species size.
- Parameters:
species
- the species to trimcomparator
- comparator for ranking individuals by fitnessminSpeciesSize
- minimum number of individuals to keepperSpeciesKeepRatio
- proportion of current species to preserve- Returns:
- a new species containing only the selected individuals
- Throws:
IllegalArgumentException
- if species is null
-
eliminateLowestPerformers
protected List<Species<T>> eliminateLowestPerformers(AbstractEAConfiguration<T> eaConfiguration, List<Species<T>> allSpecies) Eliminates the lowest-performing individuals from all species while maintaining species diversity.This method applies the species trimming process to all species in the population, removing poor performers within each species while preserving the overall species structure. Species that become empty after trimming are filtered out.
- Parameters:
eaConfiguration
- evolutionary algorithm configuration containing fitness comparatorallSpecies
- list of all species in the population- Returns:
- list of species after trimming, with empty species removed
- Throws:
IllegalArgumentException
- if any parameter is null
-
select
public Population<T> select(AbstractEAConfiguration<T> eaConfiguration, int numIndividuals, List<Genotype> genotypes, List<T> fitnessScore) Description copied from interface:Selector
Selects a specified number of individuals from the given population based on their fitness values.This method implements the core selection logic, choosing individuals according to the specific selection strategy. The selection process typically involves evaluating fitness values and applying probabilistic or deterministic rules to choose parents for reproduction.
The selection process should:
- Consider fitness values when making selection decisions
- Return exactly the requested number of individuals
- Allow for the possibility of selecting the same individual multiple times
- Maintain the integrity of the original population
- Specified by:
select
in interfaceSelector<T extends Number & Comparable<T>>
- Parameters:
eaConfiguration
- the evolutionary algorithm configuration containing selection parametersnumIndividuals
- the number of individuals to select from the populationgenotypes
- the list of genotypes in the current populationfitnessScore
- the list of fitness values corresponding to each genotype- Returns:
- a new population containing the selected individuals
-