genome_crossover (macula_tweann v0.18.1)
View SourceNEAT-style crossover for variable topology neural networks.
This module implements crossover operations that work with networks of different topologies by aligning genes via innovation numbers.
Key concepts from NEAT (Stanley and Miikkulainen, 2002): - Matching genes: Same innovation in both parents, randomly inherit - Disjoint genes: Present in one parent within the other's range - Excess genes: Present in one parent beyond the other's max innovation
For speciation, compatibility distance measures structural difference using weighted sum of disjoint/excess counts and weight differences.
Summary
Functions
Align two genomes by innovation number.
Calculate compatibility distance between two genomes.
Perform NEAT-style crossover between two genomes.
Extract connection genes from an agent's neural network.
Types
-type alignment_result() :: {Matching :: [{connection_gene(), connection_gene()}], Disjoint1 :: [connection_gene()], Disjoint2 :: [connection_gene()], Excess1 :: [connection_gene()], Excess2 :: [connection_gene()]}.
-type connection_gene() :: #connection_gene{innovation :: pos_integer() | undefined, from_id :: term(), to_id :: term(), weight :: float(), enabled :: boolean()}.
-type fitter_parent() :: 1 | 2 | equal.
-type genome() :: [connection_gene()].
Functions
-spec align_genomes(genome(), genome()) -> alignment_result().
Align two genomes by innovation number.
Categorizes genes into: - Matching: Same innovation in both parents - Disjoint: Present in one parent, within the other's innovation range - Excess: Present in one parent, beyond the other's max innovation
-spec compatibility_distance(genome(), genome(), #compatibility_config{c1 :: float(), c2 :: float(), c3 :: float()}) -> float().
Calculate compatibility distance between two genomes.
Uses the NEAT formula: delta = (c1 * E / N) + (c2 * D / N) + (c3 * W)
Where: - E = number of excess genes - D = number of disjoint genes - N = number of genes in larger genome (normalized, min 1) - W = average weight difference in matching genes - c1, c2, c3 = coefficients
-spec crossover(genome(), genome(), fitter_parent()) -> genome().
Perform NEAT-style crossover between two genomes.
Matching genes are randomly inherited from either parent. Disjoint and excess genes are inherited from the fitter parent. When parents are equally fit, all genes are inherited with random selection for conflicts.
Extract connection genes from an agent's neural network.
Converts the input_idps format to connection genes with innovations. This enables NEAT-style crossover on existing networks.