Class FeedForwardNetwork
FeedForwardNetwork provides a computational engine for executing neural networks evolved by the NEAT algorithm. It takes a network topology defined by connections and nodes, organizes them into computational layers, and provides efficient forward propagation for fitness evaluation. The network supports arbitrary topologies with variable numbers of hidden layers and connections.
Key features:
- Dynamic topology: Supports arbitrary network structures evolved by NEAT
- Layer-based evaluation: Automatically computes optimal evaluation order
- Configurable activation: Supports any activation function for hidden and output nodes
- Efficient propagation: Optimized forward pass through network layers
Network evaluation process:
- Input assignment: Input values are assigned to input nodes
- Layer computation: Each layer is computed in topological order
- Node activation: Each node applies weighted sum followed by activation function
- Output extraction: Output values are collected from designated output nodes
Network construction workflow:
- Topology analysis: Network connections are analyzed to determine layer structure
- Layer partitioning: Nodes are organized into evaluation layers using topological sorting
- Connection mapping: Backward connections are precomputed for efficient evaluation
- Dead node removal: Unreachable nodes are excluded from computation
Common usage patterns:
// Create network from NEAT chromosome
NeatChromosome chromosome = // ... obtain from evolution
Set<Integer> inputNodes = Set.of(0, 1, 2);
Set<Integer> outputNodes = Set.of(3, 4);
Function<Float, Float> activation = Activations::sigmoid;
FeedForwardNetwork network = new FeedForwardNetwork(
inputNodes, outputNodes, chromosome.getConnections(), activation
);
// Evaluate network on input data
Map<Integer, Float> inputs = Map.of(0, 1.0f, 1, 0.5f, 2, -0.3f);
Map<Integer, Float> outputs = network.compute(inputs);
// Extract specific outputs
float output1 = outputs.get(3);
float output2 = outputs.get(4);
Activation function integration:
- Sigmoid activation: Standard logistic function for binary classification
- Tanh activation: Hyperbolic tangent for continuous outputs
- Linear activation: Identity function for regression problems
- Custom functions: Any Function<Float, Float> can be used
Performance optimizations:
- Layer precomputation: Network layers are computed once during construction
- Connection mapping: Backward connections are precomputed for fast lookup
- Dead node elimination: Unreachable nodes are excluded from evaluation
- Efficient propagation: Only enabled connections participate in computation
Error handling and validation:
- Input validation: Ensures all input nodes receive values
- Output validation: Verifies all output nodes produce values
- Topology validation: Validates network structure during construction
- Connection consistency: Ensures connection endpoints reference valid nodes
Integration with NEAT evolution:
- Chromosome evaluation: Converts NEAT chromosomes to executable networks
- Fitness computation: Provides network output for fitness evaluation
- Topology evolution: Supports networks with varying structure complexity
- Innovation tracking: Works with networks containing historical innovations
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Map
<Integer, Set<Connection>> private final List
<Connection> static final org.apache.logging.log4j.Logger
-
Constructor Summary
ConstructorsConstructorDescriptionFeedForwardNetwork
(Set<Integer> _inputNodeIndices, Set<Integer> _outputNodeIndices, List<Connection> _connections, Function<Float, Float> _activationFunction) Constructs a new feed-forward network with the specified topology and activation function. -
Method Summary
-
Field Details
-
logger
public static final org.apache.logging.log4j.Logger logger -
inputNodeIndices
-
outputNodeIndices
-
connections
-
layers
-
backwardConnections
-
activationFunction
-
-
Constructor Details
-
FeedForwardNetwork
public FeedForwardNetwork(Set<Integer> _inputNodeIndices, Set<Integer> _outputNodeIndices, List<Connection> _connections, Function<Float, Float> _activationFunction) Constructs a new feed-forward network with the specified topology and activation function.The constructor analyzes the network topology, computes evaluation layers using topological sorting, and precomputes connection mappings for efficient forward propagation. The network is immediately ready for evaluation after construction.
- Parameters:
_inputNodeIndices
- set of input node indices_outputNodeIndices
- set of output node indices_connections
- list of network connections defining the topology_activationFunction
- activation function to apply to hidden and output nodes- Throws:
IllegalArgumentException
- if any parameter is null or empty
-
-
Method Details
-
compute
Computes the network output for the given input values.This method performs forward propagation through the network, computing node activations layer by layer in topological order. Input values are assigned to input nodes, then each subsequent layer is computed by applying weighted sums and activation functions.
The computation process:
- Input values are assigned to input nodes
- For each layer (starting from first hidden layer):
- For each node in the layer:
- Compute weighted sum of inputs from previous layers
- Apply activation function to the sum
- Store the result for use in subsequent layers
- Extract and return output values from output nodes
- Parameters:
inputValues
- mapping from input node indices to their values- Returns:
- mapping from output node indices to their computed values
- Throws:
IllegalArgumentException
- if inputValues is null, has wrong size, or missing required inputs
-