Class InnovationManager

java.lang.Object
net.bmahe.genetics4j.neat.InnovationManager

public class InnovationManager extends Object
Manages innovation numbers for the NEAT (NeuroEvolution of Augmenting Topologies) algorithm.

The InnovationManager is a critical component of the NEAT algorithm that tracks structural innovations in neural networks through unique innovation numbers. This system enables NEAT to perform meaningful genetic crossover between neural networks with different topologies while preserving historical information about when specific connections were first added to the population.

Key responsibilities:

  • Innovation tracking: Assigns unique numbers to each new connection type (from-to node pair)
  • Historical marking: Maintains consistent innovation numbers across the population
  • Crossover support: Enables alignment of neural network structures during recombination
  • Cache management: Provides efficient lookup and generation of innovation numbers

NEAT innovation number system:

  • Unique identification: Each unique connection (from-node → to-node) gets one innovation number
  • Population consistency: Same connection type across individuals gets same innovation number
  • Temporal ordering: Innovation numbers reflect the historical order of structural mutations
  • Crossover alignment: Enables gene alignment during genetic recombination

Innovation number workflow:

  1. Mutation occurs: Add-connection mutation creates new connection type
  2. Innovation check: Manager checks if this connection type was seen before
  3. Number assignment: New types get new innovation numbers, existing types reuse numbers
  4. Population tracking: All individuals with same connection type share same innovation number
  5. Crossover alignment: Innovation numbers enable proper gene alignment during recombination

Common usage patterns:


 // Create innovation manager for new evolution run
 InnovationManager innovationManager = new InnovationManager();
 
 // During add-connection mutation
 int fromNode = 0, toNode = 3;
 int innovationNumber = innovationManager.computeNewId(fromNode, toNode);
 Connection newConnection = Connection.of(fromNode, toNode, weight, innovationNumber, true);
 
 // Reset cache between generations if needed
 innovationManager.resetCache();
 
 // Start with specific innovation number
 InnovationManager manager = new InnovationManager(1000);
 

Cache management strategy:

  • Per-generation caching: Cache innovation numbers within each generation
  • Cross-generation persistence: Innovation numbers remain consistent across generations
  • Memory management: Reset cache periodically to prevent memory growth
  • Concurrent access: Thread-safe operations for parallel genetic operations

Performance considerations:

  • O(1) lookup: Fast innovation number retrieval through hash map caching
  • Memory efficiency: Cache only unique connection types seen in current generation
  • Thread safety: Concurrent operations supported for parallel evolution
  • Cache lifecycle: Reset cache between evolution runs to prevent memory leaks

Integration with NEAT algorithm:

  • Structural mutations: Add-connection mutations use innovation manager
  • Genetic crossover: Innovation numbers enable gene alignment
  • Compatibility distance: Innovation numbers used to identify matching, excess, and disjoint genes
  • Population management: Shared innovation manager across entire population
See Also:
  • Field Details

  • Constructor Details

    • InnovationManager

      public InnovationManager(int initialValue)
      Constructs an innovation manager with the specified initial innovation number.
      Parameters:
      initialValue - the starting innovation number for new innovations
    • InnovationManager

      public InnovationManager()
      Constructs an innovation manager with the default initial innovation number (0).
  • Method Details

    • computeNewId

      public int computeNewId(int from, int to)
      Computes or retrieves the innovation number for a connection between two nodes.

      If this connection type (from-node → to-node) has been seen before, returns the existing innovation number from the cache. Otherwise, generates a new innovation number and caches it for future use. This ensures that the same connection type across different individuals in the population receives the same innovation number.

      Parameters:
      from - the source node index of the connection
      to - the target node index of the connection
      Returns:
      the innovation number for this connection type
      Throws:
      IllegalArgumentException - if from equals to (self-connections not allowed)
    • resetCache

      public void resetCache()
      Resets the innovation cache, clearing all cached connection-to-innovation-number mappings.

      This method should be called between evolution runs or generations to prevent memory growth and ensure that innovation number assignment starts fresh. Note that this does not reset the current innovation number counter, so new innovations will continue to receive unique numbers.