faber-tweann

Topology and Weight Evolving Artificial Neural Networks for Erlang

Hex.pmDocumentationLicenseBuy Me A Coffee

Evolutionary neural networks that evolve both topology and weights, now with Liquid Time-Constant (LTC) neurons for adaptive temporal processing. Based on DXNN2 by Gene Sher.

Highlights

Quick Start

%% Add to rebar.config
{deps, [{faber_tweann, "~> 2.0"}]}.
%% Create and evolve a standard network
genotype:init_db(),
SpecieId = genotype:generate_id(specie),
AgentId = genotype:generate_id(agent),
Constraint = #constraint{morphology = xor_mimic},
genotype:construct_Agent(SpecieId, AgentId, Constraint),
genome_mutator:mutate(AgentId).
%% Use LTC dynamics directly
{NewState, Output} = ltc_dynamics:evaluate_cfc(Input, State, Tau, Bound).

LTC Neurons

Liquid Time-Constant neurons enable adaptive temporal processing with input-dependent time constants:

LTC Architecture

%% CfC evaluation (fast, closed-form)
{State1, _} = ltc_dynamics:evaluate_cfc(1.0, 0.0, 1.0, 1.0),
{State2, _} = ltc_dynamics:evaluate_cfc(1.0, State1, 1.0, 1.0).
%% State persists between evaluations - temporal memory!

Key equations:

See the LTC Neurons Guide for details.

Documentation

Features

Neural Network Evolution

LTC/CfC Neurons

Production Quality

Native Acceleration

Rust NIFs for the numeric hot paths ship with this package and are built from source at compile time. A Rust toolchain is required.

There is one edition. The faber-nn-nifs package was absorbed into faber_tweann in v2.0.0; if you depended on faber_nn_nifs directly, depend on faber_tweann instead.

tweann_nif:impl(). %% faber_nn_nifs | tweann_nif_fallback
tweann_nif:is_loaded(). %% true when the native path is active

The native path is the default. If the library is missing or fails to load, faber_tweann raises on first use rather than quietly falling back. To use the pure Erlang implementation deliberately:

[{faber_tweann, [{nif_impl, fallback}]}].

See the Native Acceleration guide.

On performance claims: earlier versions of this README quoted speedups between 30x and 200x, while the faber-nn-nifs README quoted 10-15x for the same code. Neither figure was backed by a committed measurement, and the two were mutually inconsistent. No speedup figures are published here until a benchmark runs and its output is committed. test/benchmark/bench_nif_vs_erlang.erl exists for this purpose.

Architecture

Module Dependencies

Process-based neural networks with evolutionary operators. See Architecture Guide for details.

Testing

rebar3 eunit # Unit tests (971 tests)
rebar3 dialyzer # Static analysis
rebar3 ex_doc # Generate documentation

Academic References

TWEANN/NEAT

LTC/CfC Neurons

Weight Initialization

Evolutionary Algorithms

ONNX Export

Faber Ecosystem

License

Apache License 2.0 - See LICENSE

Credits

Based on DXNN2 by Gene Sher. Adapted with LTC extensions by R.G. Lefever.