Genome
The Genome class is the core genetic representation in NEAT. It encodes the structure and parameters of a neural network, including nodes (neurons) and connections between them. Each genome can be expressed as a neural network for evaluation, and can undergo genetic operations like mutation and crossover.
Properties
Property | Type | Description |
---|---|---|
ID | Number | Unique identifier for the genome |
nodeGenes | Array | Collection of nodes in the genome |
connectionGenes | Array | Collection of connections between nodes |
inputNodes | Array | Collection of input nodes |
outputNodes | Array | Collection of output nodes |
biasNode | Node | Bias node (if available) |
fitness | Number | The genome's fitness score (higher is better) |
populationID | String/Number | ID of the population this genome belongs to |
Constructor
Creates a new genome with the specified nodes, connections, configuration, and population ID.
Parameter | Type | Description |
---|---|---|
nodeGenes | Array | Array of node genes (InputNode, HiddenNode, OutputNode, BiasNode) |
connectionGenes | Array | Array of connection genes (ConnectionGene) |
config | Object | Configuration parameters for the genome |
populationID | String/Number | ID of the population this genome belongs to |
Methods
propagate
Activates the neural network represented by the genome with the given inputs and returns the outputs.
Parameter | Type | Description |
---|---|---|
inputs | Array | Array of input values for the network |
Returns | Type | Description |
---|---|---|
outputs | Array | Array of output values produced by the network |
resetState
Resets the internal state of all nodes in the network. This is particularly useful when working with recurrent networks.
mutate
Applies random mutations to the genome according to the rates defined in the configuration. Mutations can include weight changes, adding connections, or adding nodes.
mutateWeights
Mutates the weights of existing connections. Each connection's weight may be either perturbed or completely reinitialized according to the configuration parameters.
mutateAddConnection
Attempts to add a new connection between two existing nodes. Checks for existing connections and potential recursion before adding.
mutateAddNode
Adds a new hidden node by splitting an existing connection. The original connection is disabled, and two new connections are created.
reinitializeWeights
Reinitializes all connection weights according to the weight initialization method in the configuration.
copy
Creates a deep copy of the genome with the same structure and weights but as a separate object.
Returns | Type | Description |
---|---|---|
newGenome | Genome | A new genome identical to the original |
equalsGenome
Compares this genome with another to check if they are structurally and parametrically identical.
Parameter | Type | Description |
---|---|---|
genome | Genome | The genome to compare with |
Returns | Type | Description |
---|---|---|
isEqual | Boolean | True if the genomes are identical, false otherwise |
crossover
Performs crossover between this genome and another parent genome to create an offspring. Genes are inherited from both parents according to their fitness values.
Parameter | Type | Description |
---|---|---|
parent2 | Genome | The second parent genome |
Returns | Type | Description |
---|---|---|
offspring | Genome | A new genome created from the genetic material of both parents |
evaluateFitness
Evaluates the genome's fitness using the fitness function specified in the configuration. If no fitness function is provided, fitness must be assigned manually.
toJSON
Converts the genome to a JSON string representation for storage or transmission.
Returns | Type | Description |
---|---|---|
jsonString | String | JSON string representation of the genome |
prune
Removes disconnected hidden nodes from the genome to optimize its structure. This can be useful after several mutations to clean up the network.