species_identifier (macula_tweann v0.18.1)
View SourceSpecies identification and behavioral fingerprinting.
This module implements speciation - grouping similar agents into species to preserve diversity and prevent premature convergence. Agents compete primarily within their own species, allowing diverse strategies to coexist.
Speciation Strategy
Behavioral Fingerprinting: - Records agent behavior across standard test scenarios - Fingerprint is a vector of behavioral responses - Example: For XOR, fingerprint = [output(0,0), output(0,1), output(1,0), output(1,1)]
Distance Calculation: - Euclidean distance between behavioral fingerprints - Lower distance = more similar behavior - Threshold-based grouping into species
Species Assignment: - Compare agent fingerprint to species representatives - Assign to closest species if distance less than threshold - Create new species if too different from all existing species
Benefits of Speciation
- Preserves diversity (prevents single strategy dominance) - Protects innovation (new mutations get time to optimize) - Parallel search (multiple strategies explored simultaneously) - Better exploration of fitness landscape
Implementation Notes
Species are identified by their champion (best performer). Distance threshold controls speciation granularity: - Low threshold = many small species (high diversity) - High threshold = few large species (low diversity)
Summary
Functions
Calculate combined distance using both behavior and LTC parameters.
Calculate behavioral distance between two fingerprints.
Calculate distance based on LTC parameters between two agents.
Create behavioral fingerprint for an agent.
Extract LTC signature from an agent's genome.
Assign agents to species based on behavioral similarity.
Functions
Calculate combined distance using both behavior and LTC parameters.
Combines behavioral fingerprint distance with LTC parameter distance to create a comprehensive compatibility metric. This enables speciation that considers both what agents do (behavior) and how they do it (temporal dynamics).
Formula: (BehaviorWeight * BehaviorDist) + (LtcWeight * LtcDist)
Calculate behavioral distance between two fingerprints.
Uses Euclidean distance to measure behavioral similarity. Lower distance indicates more similar behavior.
Formula: sqrt(sum((F1[i] - F2[i])^2))
Example: F1 = [0.0, 1.0, 1.0, 0.0] F2 = [0.1, 0.9, 0.8, 0.1] Distance = calculate_distance(F1, F2) Distance ≈ 0.244 (quite similar)
Calculate distance based on LTC parameters between two agents.
Compares LTC signatures (neuron types, time constants, state bounds) between agents. Agents with similar LTC configurations will have lower distance, enabling speciation by temporal dynamics.
LTC Signature Components: - Proportion of LTC/CfC neurons vs standard neurons - Average time constant (tau) of LTC neurons - Average state bound (A) of LTC neurons - Standard deviation of tau values (diversity measure)
Create behavioral fingerprint for an agent.
Runs the agent through standard test scenarios and records the behavioral responses. The fingerprint is a vector of output values across all test inputs.
For morphologies with well-defined test sets (like XOR), the fingerprint is deterministic. For stochastic environments, multiple runs may be averaged.
Example for XOR: AgentId = {1.0, agent} Fingerprint = create_fingerprint(AgentId) Fingerprint = [0.02, 0.98, 0.97, 0.03] % Outputs for inputs: (0,0), (0,1), (1,0), (1,1)
Extract LTC signature from an agent's genome.
Analyzes all neurons in the agent's network and extracts statistics about LTC parameter usage. This creates a compact representation of the agent's temporal dynamics characteristics.
Signature Components: - ltc_ratio: Proportion of LTC/CfC neurons (0.0 to 1.0) - avg_tau: Average time constant of LTC neurons - avg_bound: Average state bound of LTC neurons - tau_std: Standard deviation of tau values - ltc_count: Number of LTC/CfC neurons - total_count: Total number of neurons
-spec identify_species([{term(), [float()]}], float(), #{term() => {[float()], [term()]}}) -> #{term() => [term()]}.
Assign agents to species based on behavioral similarity.
Takes a list of agents with their fingerprints and groups them into species. Agents are compared to existing species representatives, and assigned to the closest species if within the distance threshold. If no species is close enough, a new species is created.
Example: AgentFingerprints = [ {agent1, [0.1, 0.9, 0.8, 0.2]}, {agent2, [0.0, 1.0, 1.0, 0.1]}, % Similar to agent1 {agent3, [0.9, 0.1, 0.2, 0.8]} % Very different ] Threshold = 0.5 ExistingSpecies = #{}
Result = identify_species(AgentFingerprints, Threshold, ExistingSpecies) Result might be: #{ specie1 => [agent1, agent2], % Similar agents specie2 => [agent3] % Different agent }