High-performance Rust NIFs (Native Implemented Functions) for Macula Neuroevolution.
This is an enterprise-only package that provides 10-15x performance improvements over pure Erlang fallbacks for compute-intensive neuroevolution operations.
Add to your rebar.config:
{deps, [
{macula_tweann, "0.6.0"},
{macula_nn_nifs, {git, "[email protected]:macula-io/macula-nn-nifs.git", {tag, "0.1.0"}}}
]}.The NIFs are automatically detected and used by macula_tweann. No code changes required.
- Erlang/OTP 26+
- Rust 1.70+ (for building NIFs)
- Cargo (Rust package manager)
rebar3 compileThis automatically:
- Compiles the Rust NIF library via Cargo
- Copies the compiled
.so/.dylib/.dlltopriv/ - Compiles the Erlang wrapper module
1> macula_nn_nifs:is_loaded().
true
2> macula_nn_nifs:random_weights(5).
[0.123, -0.456, 0.789, -0.234, 0.567]compile_network/3- Compile network topology for fast evaluationevaluate/2- Forward propagation through compiled networkevaluate_batch/2- Batch evaluation for multiple inputscompatibility_distance/5- NEAT speciation distancebenchmark_evaluate/3- Performance benchmarking
dot_product_flat/3- Fast weighted sum with biasdot_product_batch/1- Batch weighted sumsdot_product_preflattened/3- Pre-optimized dot productflatten_weights/1- Weight structure optimization
evaluate_cfc/4- Closed-form continuous-time evaluationevaluate_cfc_with_weights/6- CfC with custom weightsevaluate_ode/5- ODE-based LTC evaluationevaluate_ode_with_weights/7- ODE with custom weightsevaluate_cfc_batch/4- Batch CfC for time series
euclidean_distance/2- Vector distanceeuclidean_distance_batch/2- Batch distancesknn_novelty/4- K-nearest neighbor novelty scoreknn_novelty_batch/3- Batch novelty computation
fitness_stats/1- Single-pass min/max/mean/variance/stddev/sumweighted_moving_average/2- WMA computationshannon_entropy/1- Entropy calculationhistogram/4- Histogram binning
build_cumulative_fitness/1- Roulette wheel setuproulette_select/3- Single roulette selectionroulette_select_batch/3- Batch selectiontournament_select/2- Tournament selection
z_score/3- Z-score normalizationcompute_reward_component/2- Reward signal computationcompute_weighted_reward/1- Multi-component rewards
mutate_weights/4- Gaussian weight mutationmutate_weights_seeded/5- Reproducible mutationmutate_weights_batch/1- Batch mutation with per-genome paramsmutate_weights_batch_uniform/4- Batch with uniform paramsrandom_weights/1- Generate random weights [-1, 1]random_weights_seeded/2- Seeded random weightsrandom_weights_gaussian/3- Gaussian distributed weightsrandom_weights_batch/1- Batch weight generationweight_distance_l1/2- L1 (Manhattan) distanceweight_distance_l2/2- L2 (Euclidean) distanceweight_distance_batch/3- Batch distance computation
Typical speedups over pure Erlang:
| Operation | Speedup |
|---|---|
| Network evaluate | ~10x |
| Batch mutation | ~13x |
| KNN novelty | ~12x |
| Fitness stats | ~12x |
| Weight distance | ~15x |
The tweann_nif module in macula_tweann automatically detects this package:
%% Priority order:
%% 1. macula_nn_nifs (enterprise - this package)
%% 2. Bundled NIF in macula_tweann
%% 3. Pure Erlang fallback
detect_impl_module() ->
case code:which(macula_nn_nifs) of
non_existing -> tweann_nif_fallback;
_ ->
case macula_nn_nifs:is_loaded() of
true -> macula_nn_nifs;
false -> tweann_nif_fallback
end
end.rebar3 eunitApache-2.0
Enterprise license required for commercial use. Contact [email protected] for details.
- macula_tweann - Community edition on hex.pm
- Documentation