tweann_nif_fallback (macula_tweann v0.18.1)
View SourcePure Erlang fallback implementations for TWEANN NIFs.
This module provides pure Erlang implementations of all NIF functions. These are used when the Rust NIF is not loaded or unavailable. Performance will be slower than NIF but functionality is preserved.
Copyright 2025 Macula.io Licensed under Apache-2.0
Summary
Functions
Benchmark evaluate (returns microseconds per evaluation).
Build cumulative fitness array for roulette wheel.
Compute NEAT compatibility distance.
Compile network to internal format (Erlang record).
Compute reward component with normalization.
Batch compute weighted reward.
Batch dot product.
Flat dot product.
Dot product with pre-flattened arrays.
Euclidean distance between two vectors.
Batch euclidean distance, sorted by distance.
Evaluate network with inputs.
Batch evaluate network.
Evaluate CfC (closed-form continuous-time) neuron.
Batch CfC evaluation for time series.
Evaluate CfC with custom weights.
Evaluate ODE-based LTC neuron.
Evaluate ODE with custom weights.
Compute fitness statistics in single pass.
Flatten nested weight structure.
Histogram binning.
K-nearest neighbor novelty score.
Batch KNN novelty for entire population.
Mutate weights with Gaussian perturbation. Each weight has MutationRate chance of mutation. Mutated weights are either perturbed (PerturbRate) or randomized.
Batch mutate with per-genome parameters. Each tuple: {Weights, MutationRate, PerturbRate, PerturbStrength}
Batch mutate with uniform parameters across all genomes.
Mutate weights with specific random seed for reproducibility.
Generate random weights in range [-1.0, 1.0].
Batch generate random weights. Each tuple: {Count, Mean, StdDev}
Generate random weights from Gaussian distribution.
Generate random weights with specific seed.
Roulette wheel selection with binary search.
Batch roulette selection.
Shannon entropy of a distribution.
Tournament selection.
Batch compute distances between target and multiple weight vectors. DistanceType: l1 | l2
L1 (Manhattan) distance between two weight vectors.
L2 (Euclidean) distance between two weight vectors.
Weighted moving average with exponential decay.
Z-score normalization.
Functions
-spec benchmark_evaluate(map(), [float()], pos_integer()) -> float().
Benchmark evaluate (returns microseconds per evaluation).
Build cumulative fitness array for roulette wheel.
Compute NEAT compatibility distance.
-spec compile_network(list(), non_neg_integer(), [non_neg_integer()]) -> map().
Compile network to internal format (Erlang record).
Compute reward component with normalization.
Batch compute weighted reward.
Batch dot product.
Flat dot product.
Dot product with pre-flattened arrays.
Euclidean distance between two vectors.
-spec euclidean_distance_batch([float()], [[float()]]) -> [{non_neg_integer(), float()}].
Batch euclidean distance, sorted by distance.
Evaluate network with inputs.
Batch evaluate network.
Evaluate CfC (closed-form continuous-time) neuron.
Batch CfC evaluation for time series.
-spec evaluate_cfc_with_weights(float(), float(), float(), float(), [float()], [float()]) -> {float(), float()}.
Evaluate CfC with custom weights.
Evaluate ODE-based LTC neuron.
-spec evaluate_ode_with_weights(float(), float(), float(), float(), float(), [float()], [float()]) -> {float(), float()}.
Evaluate ODE with custom weights.
Compute fitness statistics in single pass.
-spec flatten_weights([{term(), [{float(), float(), float(), list()}]}]) -> {[float()], [non_neg_integer()]}.
Flatten nested weight structure.
-spec histogram([float()], pos_integer(), float(), float()) -> [non_neg_integer()].
Histogram binning.
-spec knn_novelty([float()], [[float()]], [[float()]], pos_integer()) -> float().
K-nearest neighbor novelty score.
-spec knn_novelty_batch([[float()]], [[float()]], pos_integer()) -> [float()].
Batch KNN novelty for entire population.
Mutate weights with Gaussian perturbation. Each weight has MutationRate chance of mutation. Mutated weights are either perturbed (PerturbRate) or randomized.
Batch mutate with per-genome parameters. Each tuple: {Weights, MutationRate, PerturbRate, PerturbStrength}
Batch mutate with uniform parameters across all genomes.
Mutate weights with specific random seed for reproducibility.
-spec random_weights(non_neg_integer()) -> [float()].
Generate random weights in range [-1.0, 1.0].
-spec random_weights_batch([{non_neg_integer(), float(), float()}]) -> [[float()]].
Batch generate random weights. Each tuple: {Count, Mean, StdDev}
-spec random_weights_gaussian(non_neg_integer(), float(), float()) -> [float()].
Generate random weights from Gaussian distribution.
-spec random_weights_seeded(non_neg_integer(), integer()) -> [float()].
Generate random weights with specific seed.
-spec roulette_select([float()], float(), float()) -> non_neg_integer().
Roulette wheel selection with binary search.
-spec roulette_select_batch([float()], float(), [float()]) -> [non_neg_integer()].
Batch roulette selection.
Shannon entropy of a distribution.
-spec tournament_select([non_neg_integer()], [float()]) -> non_neg_integer().
Tournament selection.
Batch compute distances between target and multiple weight vectors. DistanceType: l1 | l2
L1 (Manhattan) distance between two weight vectors.
L2 (Euclidean) distance between two weight vectors.
Weighted moving average with exponential decay.
Z-score normalization.