Interface Connection

All Known Implementing Classes:
ImmutableConnection

@Immutable public interface Connection
Represents a neural network connection in the NEAT (NeuroEvolution of Augmenting Topologies) algorithm.

A Connection is a fundamental building block of NEAT neural networks, representing a weighted link between two nodes. Each connection carries essential information for network topology, genetic operations, and evolutionary tracking through innovation numbers. Connections can be enabled or disabled, allowing for dynamic network topology exploration during evolution.

Key properties:

  • Source and target nodes: Define the directed connection in the network graph
  • Connection weight: Determines the strength and polarity of signal transmission
  • Enabled state: Controls whether the connection participates in network computation
  • Innovation number: Unique identifier for genetic alignment and historical tracking

NEAT algorithm integration:

  • Genetic crossover: Innovation numbers enable proper gene alignment between parents
  • Structural mutations: Connections can be added, removed, or have their state toggled
  • Weight evolution: Connection weights are subject to mutation and optimization
  • Topology innovation: New connections track the historical order of structural changes

Network computation role:

  • Signal propagation: Enabled connections transmit weighted signals between nodes
  • Network evaluation: Only enabled connections participate in forward propagation
  • Topology dynamics: Enable/disable states allow topology exploration without gene loss
  • Weight optimization: Connection weights are evolved to optimize network performance

Common usage patterns:


 // Create a new connection
 Connection connection = Connection.of(
     0,      // from node index
     3,      // to node index  
     0.75f,  // connection weight
     true,   // enabled state
     42      // innovation number
 );
 
 // Builder pattern for complex construction
 Connection connection = Connection.builder()
     .fromNodeIndex(1)
     .toNodeIndex(4)
     .weight(-0.5f)
     .isEnabled(false)
     .innovation(15)
     .build();
 
 // Copy with modifications
 Connection modifiedConnection = Connection.builder()
     .from(connection)
     .weight(connection.weight() + 0.1f)
     .build();
 

Innovation number significance:

  • Historical marking: Tracks when each connection type first appeared in evolution
  • Genetic alignment: Enables meaningful crossover between different network topologies
  • Compatibility distance: Used to measure genetic similarity for speciation
  • Structural tracking: Maintains evolutionary history of network topology changes

Connection state management:

  • Enabled connections: Actively participate in network computation
  • Disabled connections: Preserved in genome but don't affect network output
  • State mutations: Can toggle between enabled/disabled states during evolution
  • Structural preservation: Disabled connections maintain genetic information

Validation and constraints:

  • Node indices: Must be non-negative and reference valid nodes in the network
  • Innovation numbers: Must be non-negative and unique within the population context
  • Self-connections: Typically not allowed (from and to nodes must be different)
  • Weight bounds: While not enforced, weights typically range within reasonable bounds
See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static class 
     
  • Method Summary

    Modifier and Type
    Method
    Description
     
    default void
     
    static Connection
    copyOf(Connection original)
    Creates a copy of the specified connection.
    int
    Returns the index of the source node for this connection.
    int
    Returns the innovation number for this connection.
    boolean
    Returns whether this connection is enabled.
    static Connection
    of(int from, int to, float weight, boolean isEnabled, int innovation)
    Creates a new connection with the specified parameters.
    int
    Returns the index of the target node for this connection.
    float
    Returns the weight of this connection.
  • Method Details

    • fromNodeIndex

      @Parameter int fromNodeIndex()
      Returns the index of the source node for this connection.
      Returns:
      the source node index (non-negative)
    • toNodeIndex

      @Parameter int toNodeIndex()
      Returns the index of the target node for this connection.
      Returns:
      the target node index (non-negative)
    • weight

      @Parameter float weight()
      Returns the weight of this connection.

      The weight determines the strength and polarity of signal transmission through this connection. Positive weights amplify signals, negative weights invert them, and zero weights effectively disable signal transmission.

      Returns:
      the connection weight
    • isEnabled

      @Parameter boolean isEnabled()
      Returns whether this connection is enabled.

      Enabled connections participate in network computation and signal propagation. Disabled connections are preserved in the genome but do not affect network output, allowing for topology exploration without gene loss.

      Returns:
      true if the connection is enabled, false otherwise
    • innovation

      @Parameter int innovation()
      Returns the innovation number for this connection.

      Innovation numbers are unique identifiers that track the historical order of structural mutations in the NEAT algorithm. They enable proper gene alignment during crossover and are used to calculate compatibility distance for speciation.

      Returns:
      the innovation number (non-negative)
    • check

      @Check default void check()
    • builder

      static Connection.Builder builder()
    • of

      static Connection of(int from, int to, float weight, boolean isEnabled, int innovation)
      Creates a new connection with the specified parameters.
      Parameters:
      from - the source node index
      to - the target node index
      weight - the connection weight
      isEnabled - whether the connection is enabled
      innovation - the innovation number
      Returns:
      a new connection instance
      Throws:
      IllegalArgumentException - if node indices or innovation number are negative
    • copyOf

      static Connection copyOf(Connection original)
      Creates a copy of the specified connection.
      Parameters:
      original - the connection to copy
      Returns:
      a new connection instance with the same properties as the original