network_factory (faber_neuroevolution v1.2.4)

View Source

Network factory wrapper for faber_tweann's network_evaluator.

This module implements the network factory interface expected by evolution strategies, delegating to the real network_evaluator from faber_tweann.

The factory interface provides: create_feedforward/1 to create a new feedforward network, mutate/2 to mutate a network's weights, crossover/2 to create offspring from two parent networks.

This abstraction enables dependency injection for testing (use mock_network_factory in tests), clean separation between evolution logic and network implementation, and future support for different network types (RNNs, LSTMs, etc.).

Summary

Functions

Compile an existing network for NIF-accelerated evaluation.

Create a NIF-compiled feedforward network for fast evaluation.

Create a new feedforward neural network.

Crossover two networks to produce offspring.

Mutate a network's weights.

Mutate a CfC network's weights and neuron parameters.

Functions

compile(Network)

-spec compile(Network) -> Result
                 when
                     Network :: network_evaluator:network(),
                     Result :: {ok, nif_network:compiled_network()} | {error, term()}.

Compile an existing network for NIF-accelerated evaluation.

Takes a network from create_feedforward/1 and compiles it for fast repeated evaluation via NIF.

create_compiled_feedforward(Topology)

-spec create_compiled_feedforward(Topology) -> Result
                                     when
                                         Topology :: {pos_integer(), [pos_integer()], pos_integer()},
                                         Result ::
                                             {ok, nif_network:compiled_network()} | {error, term()}.

Create a NIF-compiled feedforward network for fast evaluation.

Combines network creation and NIF compilation in one step. Uses the native path when configured (speedup unmeasured; see ROADMAP.md).

create_feedforward(Topology)

-spec create_feedforward(Topology) -> network_evaluator:network()
                            when Topology :: {pos_integer(), [pos_integer()], pos_integer()}.

Create a new feedforward neural network.

Delegates to network_evaluator:create_feedforward/3 from faber_tweann. Topology is {InputSize, HiddenLayers, OutputSize} where HiddenLayers is a list of layer sizes.

crossover(Parent1, Parent2)

-spec crossover(Parent1, Parent2) -> network_evaluator:network()
                   when Parent1 :: network_evaluator:network(), Parent2 :: network_evaluator:network().

Crossover two networks to produce offspring.

Performs uniform crossover: each weight in the offspring is randomly selected from either parent with equal probability.

mutate(Network, MutationStrength)

-spec mutate(Network, MutationStrength) -> network_evaluator:network()
                when Network :: network_evaluator:network(), MutationStrength :: float().

Mutate a network's weights.

Creates a copy of the network with mutated weights. The mutation applies gaussian noise to each weight with the given strength (standard deviation).

mutate_cfc(Network, MutationStrength)

-spec mutate_cfc(Network, MutationStrength) -> network_evaluator:network()
                    when Network :: network_evaluator:network(), MutationStrength :: float().

Mutate a CfC network's weights and neuron parameters.

Extends standard weight mutation with CfC-specific parameter mutations: tau values perturbed with gaussian noise clamped to [0.01, 10.0], state bounds perturbed with gaussian noise clamped to [0.1, 5.0], and a 5% chance to toggle neuron type between standard and cfc.

For standard networks (no neuron_meta), behaves identically to mutate/2.