Class NeatChromosomeAddConnection
- All Implemented Interfaces:
ChromosomeMutationHandler<NeatChromosome>
NeatChromosomeAddConnection implements the add-connection structural mutation for NEAT chromosomes, which increases network connectivity by creating new weighted links between existing nodes. This mutation is essential for NEAT's ability to explore different network topologies and discover optimal connectivity patterns.
Add-connection mutation process:
- Node selection: Randomly select source and target nodes from all available nodes
- Validity checking: Ensure the connection doesn't violate network constraints
- Duplicate prevention: Verify the connection doesn't already exist
- Innovation assignment: Assign unique innovation number via InnovationManager
- Weight initialization: Set random weight within chromosome bounds
- Connection creation: Add enabled connection to the chromosome
Connection constraints:
- No self-connections: Source and target nodes must be different
- No duplicate connections: Connection between same nodes cannot already exist
- Feed-forward topology: Output nodes cannot be sources, input nodes cannot be targets
- Valid node references: Both nodes must exist in the network
Node selection strategy:
- Available nodes: All input, output, and hidden nodes are potential connection endpoints
- Dynamic range: Node range adapts to include any hidden nodes created by add-node mutations
- Uniform selection: All valid nodes have equal probability of being selected
- Constraint filtering: Invalid connections are rejected and no mutation occurs
Common usage patterns:
// Create add-connection mutation handler
RandomGenerator randomGen = RandomGenerator.getDefault();
InnovationManager innovationManager = new InnovationManager();
NeatChromosomeAddConnection handler = new NeatChromosomeAddConnection(
randomGen, innovationManager
);
// Check if handler can process mutation
AddConnection mutationPolicy = AddConnection.of(0.1);
NeatChromosomeSpec chromosomeSpec = NeatChromosomeSpec.of(3, 2, -1.0f, 1.0f);
boolean canHandle = handler.canHandle(mutationPolicy, chromosomeSpec);
// Apply mutation to chromosome
NeatChromosome originalChromosome = // ... existing chromosome
NeatChromosome mutatedChromosome = handler.mutate(mutationPolicy, originalChromosome);
// Result: chromosome may have one additional connection (if valid connection found)
Integration with NEAT algorithm:
- Innovation tracking: Uses InnovationManager for consistent innovation number assignment
- Population consistency: Same connection types get same innovation numbers across population
- Genetic alignment: Innovation numbers enable proper crossover alignment
- Structural diversity: Increases topological diversity in the population
Weight initialization:
- Random weights: New connections get random weights within chromosome bounds
- Uniform distribution: Weights uniformly distributed between min and max values
- Immediate activation: New connections are enabled and immediately affect network behavior
- Bounded values: Weights respect chromosome's min/max weight constraints
Performance considerations:
- Efficient validation: Fast checks for connection existence and validity
- Innovation caching: Leverages InnovationManager's O(1) innovation lookup
- Memory efficiency: Minimal allocation during mutation
- Failed mutation handling: Gracefully handles cases where no valid connection can be added
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final InnovationManager
static final org.apache.logging.log4j.Logger
private final RandomGenerator
-
Constructor Summary
ConstructorsConstructorDescriptionNeatChromosomeAddConnection
(RandomGenerator _randomGenerator, InnovationManager _innovationManager) Constructs a new add-connection mutation handler with the specified components. -
Method Summary
Modifier and TypeMethodDescriptionboolean
canHandle
(MutationPolicy mutationPolicy, ChromosomeSpec chromosome) Determines whether this handler can process the given mutation policy and chromosome specification.mutate
(MutationPolicy mutationPolicy, Chromosome chromosome) Applies add-connection mutation to a NEAT chromosome.
-
Field Details
-
logger
public static final org.apache.logging.log4j.Logger logger -
randomGenerator
-
innovationManager
-
-
Constructor Details
-
NeatChromosomeAddConnection
public NeatChromosomeAddConnection(RandomGenerator _randomGenerator, InnovationManager _innovationManager) Constructs a new add-connection mutation handler with the specified components.The random generator is used for node selection and weight initialization. The innovation manager provides unique innovation numbers for new connections, ensuring consistent tracking across the population.
- Parameters:
_randomGenerator
- random number generator for stochastic operations_innovationManager
- innovation manager for tracking structural changes- Throws:
IllegalArgumentException
- if randomGenerator or innovationManager is null
-
-
Method Details
-
canHandle
Determines whether this handler can process the given mutation policy and chromosome specification.This handler specifically processes AddConnection mutations applied to NeatChromosomeSpec specifications, ensuring type compatibility for NEAT neural network connection addition.
- Specified by:
canHandle
in interfaceChromosomeMutationHandler<NeatChromosome>
- Parameters:
mutationPolicy
- the mutation policy to checkchromosome
- the chromosome specification to check- Returns:
- true if policy is AddConnection and chromosome is NeatChromosomeSpec, false otherwise
- Throws:
IllegalArgumentException
- if any parameter is null
-
mutate
Applies add-connection mutation to a NEAT chromosome.This method attempts to add a new connection between two randomly selected nodes in the neural network. The mutation may fail if no valid connection can be found (e.g., all possible connections already exist or violate network constraints).
Mutation algorithm:
- Determine the range of available nodes (inputs, outputs, and hidden nodes)
- Randomly select source and target nodes
- Validate the connection doesn't violate constraints
- If valid, create new connection with innovation number and random weight
- Add connection to chromosome and return modified chromosome
- If invalid, return chromosome unchanged
- Specified by:
mutate
in interfaceChromosomeMutationHandler<NeatChromosome>
- Parameters:
mutationPolicy
- the add-connection mutation policychromosome
- the NEAT chromosome to mutate- Returns:
- a new chromosome with potentially one additional connection
- Throws:
IllegalArgumentException
- if policy is not AddConnection or chromosome is not NeatChromosome
-