Class AddNodePolicyHandler<T extends Comparable<T>>

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

public class AddNodePolicyHandler<T extends Comparable<T>> extends Object implements MutationPolicyHandler<T>
Mutation policy handler for NEAT (NeuroEvolution of Augmenting Topologies) add-node mutations.

AddNodePolicyHandler manages the structural mutation that adds new hidden nodes to NEAT neural networks by splitting existing connections. This is one of the most important structural mutations in NEAT as it enables the evolution of increasingly complex network topologies.

Add-node mutation process:

  1. Connection selection: Choose an existing enabled connection to split
  2. Connection disabling: Disable the original connection
  3. Node creation: Create a new hidden node between the connection endpoints
  4. Connection replacement: Create two new connections through the new node
  5. Innovation tracking: Assign innovation numbers to new connections
  6. Weight preservation: Set weights to preserve network function

Key characteristics:

  • Topology complexity: Increases network depth and node count
  • Function preservation: Maintains network behavior through careful weight setting
  • Innovation tracking: New connections receive unique innovation numbers
  • Gradual growth: Incrementally increases network complexity

Network transformation:

  • Before: Direct connection A → B with weight W
  • After: Path A → NewNode → B with weights W₁ and W₂
  • Weight strategy: Often W₁ = 1.0, W₂ = W to preserve function
  • Node placement: New node gets next available index

Common usage patterns:


 // Create add-node mutation policy
 AddNode addNodePolicy = AddNode.of(0.05);  // 5% mutation rate
 
 // Create policy handler
 RandomGenerator randomGen = RandomGenerator.getDefault();
 AddNodePolicyHandler<Double> handler = new AddNodePolicyHandler<>(randomGen);
 
 // Check if handler can process the policy
 boolean canHandle = handler.canHandle(resolver, addNodePolicy);
 
 // Create mutator for the policy
 Mutator mutator = handler.createMutator(
     executionContext, configuration, resolver, addNodePolicy
 );
 
 // Apply mutation to population
 List<Individual<Double>> mutatedPopulation = mutator.mutate(
     configuration, population
 );
 

Integration with NEAT algorithm:

  • Innovation management: Coordinates with InnovationManager for new connections
  • Chromosome mutation: Delegates to NeatChromosomeAddNodeMutationHandler
  • Population evolution: Applied based on configured mutation probability
  • Complexity growth: Primary mechanism for increasing network complexity

Structural impact:

  • Hidden layer growth: Creates new hidden nodes that can form layers
  • Computational depth: Increases potential computational complexity
  • Feature detection: New nodes can detect intermediate features
  • Representation power: Enhances network's representational capacity

Performance considerations:

  • Conservative application: Typically applied less frequently than weight mutations
  • Innovation caching: Leverages InnovationManager for efficient tracking
  • Memory efficiency: Minimal allocation during mutation operations
  • Function preservation: Weight setting strategies maintain network behavior
See Also:
  • Field Details

  • Constructor Details

    • AddNodePolicyHandler

      public AddNodePolicyHandler(RandomGenerator _randomGenerator)
      Constructs a new add-node policy handler with the specified random generator.

      The random generator is used for stochastic decisions during mutation application, including selection of individuals to mutate and selection of connections to split.

      Parameters:
      _randomGenerator - random number generator for stochastic mutation operations
      Throws:
      IllegalArgumentException - if randomGenerator is null
  • Method Details

    • canHandle

      public boolean canHandle(MutationPolicyHandlerResolver<T> mutationPolicyHandlerResolver, MutationPolicy mutationPolicy)
      Determines whether this handler can process the given mutation policy.

      This handler specifically processes AddNode mutation policies, which configure the parameters for adding new hidden nodes to NEAT neural networks.

      Specified by:
      canHandle in interface MutationPolicyHandler<T extends Comparable<T>>
      Parameters:
      mutationPolicyHandlerResolver - resolver for nested mutation policies
      mutationPolicy - the mutation policy to check
      Returns:
      true if the policy is an AddNode instance, false otherwise
      Throws:
      IllegalArgumentException - if any parameter is null
    • createMutator

      public Mutator createMutator(AbstractEAExecutionContext<T> eaExecutionContext, AbstractEAConfiguration<T> eaConfiguration, MutationPolicyHandlerResolver<T> mutationPolicyHandlerResolver, MutationPolicy mutationPolicy)
      Creates a concrete mutator for add-node mutations.

      This method resolves the appropriate chromosome mutation handlers for NEAT chromosomes and creates a generic mutator that applies add-node mutations according to the specified policy parameters.

      Mutator creation process:

      1. Extract population mutation probability from the policy
      2. Resolve chromosome-specific mutation handlers
      3. Create generic mutator with resolved components
      4. Return configured mutator ready for population application
      Specified by:
      createMutator in interface MutationPolicyHandler<T extends Comparable<T>>
      Parameters:
      eaExecutionContext - execution context containing NEAT-specific components
      eaConfiguration - evolutionary algorithm configuration
      mutationPolicyHandlerResolver - resolver for chromosome mutation handlers
      mutationPolicy - the add-node mutation policy
      Returns:
      a configured mutator for applying add-node mutations
      Throws:
      IllegalArgumentException - if any parameter is null