pulsatrix
Loading...
Searching...
No Matches
pulsatrix::NEATGenome Class Reference

A NEAT genome: its node and connection genes, growable via structural mutation. More...

#include <neat_genome.hpp>

Public Member Functions

 NEATGenome (int num_inputs, int num_outputs, bool has_bias, InnovationTracker &tracker)
 Constructs the minimal starting topology: num_inputs input nodes (+1 bias node if has_bias), num_outputs output nodes, every input(+bias) node directly connected to every output node – NEAT's own "complexify from minimal structure" starting point, not a large fixed topology later pruned.
 
const std::vector< NodeGene > & nodes () const
 
const std::vector< ConnectionGene > & connections () const
 
void SetConnectionWeight (int innovation, double weight)
 Directly sets an existing connection's weight by innovation number – needed infrastructure found necessary by Phase 3 Mission 1 (deterministic phenotype- evaluation tests need an exact, controllable weight; a future crossover mission will need the same capability to copy weights between genomes), logged here as a small scope addition beyond Mission 0's own original scope.
 
void AddConnectionBetween (int in_node, int out_node, double weight, InnovationTracker &tracker)
 Pure core: adds a new enabled connection gene (in_node, out_node, weight), assigning its innovation number via tracker (reused if this exact connection has already been created on any genome sharing the tracker).
 
template<typename RNG >
bool AddConnection (InnovationTracker &tracker, RNG &rng)
 RNG-driven wrapper: proposes a random, currently-nonexistent, feedforward-safe (cannot create a cycle – checked via reachability, not merely assumed) pair of nodes and adds the connection with a small random initial weight. A no-op (returns false) if no such pair exists (e.g. the genome is already fully connected in every safe direction).
 
void AddNodeSplitting (int connection_innovation, InnovationTracker &tracker)
 Pure core: splits the enabled connection with the given innovation number – disables it (kept, not removed), adds a new hidden node, and adds two new connections: in_node -> new_node (weight 1.0) and new_node -> out_node (weight = the disabled connection's own original weight). Per the original paper's own convention: this specific weight choice keeps the network's immediate behavior close to what it was right before the mutation, minimizing initial disruption.
 
template<typename RNG >
bool AddNode (InnovationTracker &tracker, RNG &rng)
 RNG-driven wrapper: splits a uniformly-randomly chosen enabled connection. A no-op (returns false) if no enabled connection exists.
 
template<typename RNG >
void MutateWeights (double sigma, double mutation_probability, RNG &rng)
 Non-structural mutation: perturbs every enabled connection's weight independently with probability mutation_probability by adding N(0, sigma^2) noise – not part of NEAT's own named "structural mutation" pair, but genuinely necessary infrastructure for any real evolutionary run (a genome that only ever grows topology, never adjusts weights, cannot meaningfully learn); added here as a small, logged scope extension beyond this mission's literal title.
 

Detailed Description

A NEAT genome: its node and connection genes, growable via structural mutation.

Constructor & Destructor Documentation

◆ NEATGenome()

pulsatrix::NEATGenome::NEATGenome ( int  num_inputs,
int  num_outputs,
bool  has_bias,
InnovationTracker &  tracker 
)
inline

Constructs the minimal starting topology: num_inputs input nodes (+1 bias node if has_bias), num_outputs output nodes, every input(+bias) node directly connected to every output node – NEAT's own "complexify from minimal structure" starting point, not a large fixed topology later pruned.

Exceptions
std::invalid_argumentif num_inputs or num_outputs is 0.

Member Function Documentation

◆ AddConnection()

template<typename RNG >
bool pulsatrix::NEATGenome::AddConnection ( InnovationTracker &  tracker,
RNG &  rng 
)
inline

RNG-driven wrapper: proposes a random, currently-nonexistent, feedforward-safe (cannot create a cycle – checked via reachability, not merely assumed) pair of nodes and adds the connection with a small random initial weight. A no-op (returns false) if no such pair exists (e.g. the genome is already fully connected in every safe direction).

◆ AddConnectionBetween()

void pulsatrix::NEATGenome::AddConnectionBetween ( int  in_node,
int  out_node,
double  weight,
InnovationTracker &  tracker 
)
inline

Pure core: adds a new enabled connection gene (in_node, out_node, weight), assigning its innovation number via tracker (reused if this exact connection has already been created on any genome sharing the tracker).

Exceptions
std::invalid_argumentif in_node or out_node doesn't exist in this genome, or a connection between them (in either direction) already exists.

◆ AddNode()

template<typename RNG >
bool pulsatrix::NEATGenome::AddNode ( InnovationTracker &  tracker,
RNG &  rng 
)
inline

RNG-driven wrapper: splits a uniformly-randomly chosen enabled connection. A no-op (returns false) if no enabled connection exists.

◆ AddNodeSplitting()

void pulsatrix::NEATGenome::AddNodeSplitting ( int  connection_innovation,
InnovationTracker &  tracker 
)
inline

Pure core: splits the enabled connection with the given innovation number – disables it (kept, not removed), adds a new hidden node, and adds two new connections: in_node -> new_node (weight 1.0) and new_node -> out_node (weight = the disabled connection's own original weight). Per the original paper's own convention: this specific weight choice keeps the network's immediate behavior close to what it was right before the mutation, minimizing initial disruption.

Exceptions
std::invalid_argumentif no enabled connection with that innovation number exists in this genome.

◆ connections()

const std::vector< ConnectionGene > & pulsatrix::NEATGenome::connections ( ) const
inline

◆ MutateWeights()

template<typename RNG >
void pulsatrix::NEATGenome::MutateWeights ( double  sigma,
double  mutation_probability,
RNG &  rng 
)
inline

Non-structural mutation: perturbs every enabled connection's weight independently with probability mutation_probability by adding N(0, sigma^2) noise – not part of NEAT's own named "structural mutation" pair, but genuinely necessary infrastructure for any real evolutionary run (a genome that only ever grows topology, never adjusts weights, cannot meaningfully learn); added here as a small, logged scope extension beyond this mission's literal title.

Exceptions
std::invalid_argumentif sigma < 0 or mutation_probability is outside [0, 1].

◆ nodes()

const std::vector< NodeGene > & pulsatrix::NEATGenome::nodes ( ) const
inline

◆ SetConnectionWeight()

void pulsatrix::NEATGenome::SetConnectionWeight ( int  innovation,
double  weight 
)
inline

Directly sets an existing connection's weight by innovation number – needed infrastructure found necessary by Phase 3 Mission 1 (deterministic phenotype- evaluation tests need an exact, controllable weight; a future crossover mission will need the same capability to copy weights between genomes), logged here as a small scope addition beyond Mission 0's own original scope.

Exceptions
std::invalid_argumentif no connection with that innovation number exists.

The documentation for this class was generated from the following file: