genotype (macula_tweann v0.13.0)
View SourceGenotype representation for TWEANN networks.
This module provides the genetic encoding for neural networks using ETS for in-memory storage. A genotype describes the network topology and parameters that can be evolved, then converted to a running phenotype.
Based on DXNN2 by Gene Sher ("Handbook of Neuroevolution through Erlang").
Genotype Structure
A genotype is a collection of interconnected elements stored in Mnesia:
- Agent - Top-level container for a neural network - Cortex - Network coordinator, references sensors/neurons/actuators - Sensor - Input interface with fanout connections - Neuron - Processing unit with weighted inputs and outputs - Actuator - Output interface with fanin connections
ID Format
Each element has a unique ID in the format: {{LayerCoord, UniqueFloat}, Type}
Layer coordinates: - Sensors: -1.0 - Hidden neurons: 0.0 to 1.0 - Actuators: 1.0 - Cortex: origin
Weight Format
Neuron input weights use the tuple format: {Weight, DeltaWeight, LearningRate, ParameterList}
Summary
Functions
Clone an agent and all its components.
Construct a new agent with neural network.
Delete a record from ETS.
Delete an agent and all its components.
Read a record directly from ETS (same as read/1 for ETS).
Generate an ID for a specific element type.
Generate a unique float identifier.
Initialize ETS tables for genotype storage.
Select a random element from a list.
Read a record from ETS.
Reset database by clearing all tables.
Update agent fingerprint for speciation.
Write a record to ETS.
Functions
Clone an agent and all its components.
-spec construct_Agent(term(), term(), #constraint{morphology :: term(), connection_architecture :: term(), neural_afs :: term(), neural_pfns :: term(), substrate_plasticities :: term(), substrate_linkforms :: term(), neural_aggr_fs :: term(), tuning_selection_fs :: term(), tuning_duration_f :: term(), annealing_parameters :: term(), perturbation_ranges :: term(), agent_encoding_types :: term(), heredity_types :: term(), mutation_operators :: term(), tot_topological_mutations_fs :: term(), population_evo_alg_f :: term(), population_fitness_postprocessor_f :: term(), population_selection_f :: term(), specie_distinguishers :: term(), hof_distinguishers :: term(), objectives :: term()}) -> term().
Construct a new agent with neural network.
Creates a complete agent genotype based on the species constraint. The morphology in the constraint defines sensors and actuators.
-spec delete(tuple()) -> ok.
Delete a record from ETS.
-spec delete_Agent(term()) -> ok.
Delete an agent and all its components.
Read a record directly from ETS (same as read/1 for ETS).
This function exists for API compatibility with the old Mnesia interface.
Generate an ID for a specific element type.
Creates a properly formatted ID tuple based on the element type: - sensor: {{-1, UniqueFloat}, sensor} - neuron: {{0, UniqueFloat}, neuron} (hidden layer) - actuator: {{1, UniqueFloat}, actuator} - cortex: {{origin, UniqueFloat}, cortex} - agent: {UniqueFloat, agent}
-spec generate_UniqueId() -> float().
Generate a unique float identifier.
-spec init_db() -> ok.
Initialize ETS tables for genotype storage.
Creates ETS tables for all genotype elements. Should be called once at application startup. ETS tables are faster than Mnesia for this workload since we don't need distribution or disk persistence.
-spec random_element([T]) -> T when T :: term().
Select a random element from a list.
Read a record from ETS.
Key format: {Table, RecordKey} where RecordKey is the record's id field.
-spec reset_db() -> ok.
Reset database by clearing all tables.
-spec update_fingerprint(term()) -> ok.
Update agent fingerprint for speciation.
-spec write(tuple()) -> ok.
Write a record to ETS.
The record type determines which table to use (first element of record tuple). For agent records, the evo_hist is capped to prevent unbounded growth.