Class NeatSelectionPolicyHandler<T extends Number & Comparable<T>>

java.lang.Object
net.bmahe.genetics4j.neat.selection.NeatSelectionPolicyHandler<T>
Type Parameters:
T - the fitness value type (typically Double)
All Implemented Interfaces:
SelectionPolicyHandler<T>

public class NeatSelectionPolicyHandler<T extends Number & Comparable<T>> extends Object implements SelectionPolicyHandler<T>
Selection policy handler for NEAT (NeuroEvolution of Augmenting Topologies) species-based selection.

NeatSelectionPolicyHandler implements the species-based selection mechanism that is fundamental to the NEAT algorithm. It organizes the population into species based on genetic compatibility, applies fitness sharing within species, and manages reproduction allocation across species to maintain population diversity and protect innovative topologies.

Key responsibilities:

  • Species formation: Groups genetically similar individuals into species
  • Fitness sharing: Adjusts individual fitness based on species membership
  • Reproduction allocation: Distributes offspring across species based on average fitness
  • Diversity preservation: Protects innovative topologies from elimination by established forms

NEAT species-based selection process:

  1. Compatibility calculation: Measure genetic distance between individuals
  2. Species assignment: Assign individuals to species based on compatibility thresholds
  3. Fitness adjustment: Apply fitness sharing within each species
  4. Species evaluation: Calculate average fitness for each species
  5. Reproduction allocation: Determine offspring count for each species
  6. Within-species selection: Select parents within each species for reproduction

Species management features:

  • Dynamic speciation: Species boundaries adjust as population evolves
  • Species extinction: Poor-performing species are eliminated
  • Representative tracking: Maintains species representatives for compatibility testing
  • Population diversity: Prevents single topology from dominating

Common usage patterns:


 // Create NEAT selection policy handler
 RandomGenerator randomGen = RandomGenerator.getDefault();
 SpeciesIdGenerator speciesIdGen = new SpeciesIdGenerator();
 
 NeatSelectionPolicyHandler<Double> handler = new NeatSelectionPolicyHandler<>(
     randomGen, speciesIdGen
 );
 
 // Configure NEAT selection policy
 NeatSelection<Double> neatSelection = NeatSelection.<Double>builder()
     .compatibilityThreshold(3.0)
     .speciesSelection(new TournamentSelection(3))  // Within-species selection
     .build();
 
 // Resolve selector for EA execution
 Selector<Double> selector = handler.resolve(
     executionContext, configuration, resolverRegistry, neatSelection
 );
 

Integration with genetic operators:

  • Crossover compatibility: Species ensure genetic compatibility for meaningful recombination
  • Mutation guidance: Species composition influences structural mutation rates
  • Innovation protection: New topologies get time to optimize within their species
  • Diversity maintenance: Multiple species explore different regions of topology space

Performance considerations:

  • Compatibility caching: Genetic distances cached for efficiency
  • Species reuse: Species structures maintained across generations
  • Parallel processing: Species-based selection enables concurrent evaluation
  • Memory management: Efficient species membership tracking

Selection policy delegation:

  • Within-species selection: Delegates to standard selection policies (tournament, roulette, etc.)
  • Composable policies: Can combine with any standard selection mechanism
  • Flexible configuration: Different species can use different selection strategies
  • Performance optimization: Leverages existing high-performance selectors
See Also:
  • Field Details

    • logger

      public static final org.apache.logging.log4j.Logger logger
    • randomGenerator

      private final RandomGenerator randomGenerator
    • speciesIdGenerator

      private final SpeciesIdGenerator speciesIdGenerator
  • Constructor Details

    • NeatSelectionPolicyHandler

      public NeatSelectionPolicyHandler(RandomGenerator _randomGenerator, SpeciesIdGenerator _speciesIdGenerator)
      Constructs a new NEAT selection policy handler with the specified components.

      The random generator is used for stochastic operations during species formation and selection. The species ID generator provides unique identifiers for newly created species throughout the evolutionary process.

      Parameters:
      _randomGenerator - random number generator for stochastic operations
      _speciesIdGenerator - generator for unique species identifiers
      Throws:
      IllegalArgumentException - if randomGenerator or speciesIdGenerator is null
  • Method Details

    • canHandle

      public boolean canHandle(SelectionPolicy selectionPolicy)
      Determines whether this handler can process the given selection policy.

      This handler specifically processes NeatSelection policies, which configure species-based selection with compatibility thresholds and within-species selection strategies.

      Specified by:
      canHandle in interface SelectionPolicyHandler<T extends Number & Comparable<T>>
      Parameters:
      selectionPolicy - the selection policy to check
      Returns:
      true if the policy is a NeatSelection instance, false otherwise
      Throws:
      IllegalArgumentException - if selectionPolicy is null
    • resolve

      public Selector<T> resolve(AbstractEAExecutionContext<T> eaExecutionContext, AbstractEAConfiguration<T> eaConfiguration, SelectionPolicyHandlerResolver<T> selectionPolicyHandlerResolver, SelectionPolicy selectionPolicy)
      Resolves a NEAT selection policy into a concrete selector implementation.

      This method creates a NeatSelectorImpl that implements the species-based selection mechanism. It resolves the within-species selection policy using the provided resolver and configures the selector with the necessary NEAT components.

      Resolution process:

      1. Extract the within-species selection policy from the NEAT selection configuration
      2. Resolve the within-species selection policy to a concrete selector
      3. Create a NeatSelectorImpl with all necessary components
      4. Return the configured selector ready for use in evolution
      Specified by:
      resolve in interface SelectionPolicyHandler<T extends Number & Comparable<T>>
      Parameters:
      eaExecutionContext - the execution context for the evolutionary algorithm
      eaConfiguration - the configuration for the evolutionary algorithm
      selectionPolicyHandlerResolver - resolver for nested selection policies
      selectionPolicy - the NEAT selection policy to resolve
      Returns:
      a configured selector implementing NEAT species-based selection
      Throws:
      IllegalArgumentException - if selectionPolicy is null or not a NeatSelection