genome_crossover (macula_tweann v0.18.1)

View Source

NEAT-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

alignment_result/0

-type alignment_result() ::
          {Matching :: [{connection_gene(), connection_gene()}],
           Disjoint1 :: [connection_gene()],
           Disjoint2 :: [connection_gene()],
           Excess1 :: [connection_gene()],
           Excess2 :: [connection_gene()]}.

connection_gene/0

-type connection_gene() ::
          #connection_gene{innovation :: pos_integer() | undefined,
                           from_id :: term(),
                           to_id :: term(),
                           weight :: float(),
                           enabled :: boolean()}.

fitter_parent/0

-type fitter_parent() :: 1 | 2 | equal.

genome/0

-type genome() :: [connection_gene()].

Functions

align_genomes(Genome1, Genome2)

-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

compatibility_distance(Genome1, Genome2, Compatibility_config)

-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

crossover(Genome1, Genome2, FitterParent)

-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(AgentId)

-spec extract_connection_genes(term()) -> genome().

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.