Constructor
new Config(configObj = {})
Creates a new configuration object with default values that can be overridden by the provided configuration object.
| Parameter | Type | Description |
|---|
| configObj | Object | Optional object containing configuration parameters to override defaults |
// Create a configuration with default values
const config = new Config();
// Create a configuration with custom values
const customConfig = new Config({
inputSize: 4,
outputSize: 2,
activationFunction: 'ReLU',
populationSize: 200,
allowRecurrentConnections: false
});
// Set values explicitly
customConfig.generations = 100;
Configuration Parameters
Network Structure
| Parameter | Type | Default | Description |
|---|
| inputSize | Number | 2 | Number of input nodes in the network |
| outputSize | Number | 1 | Number of output nodes in the network |
| activationFunction | String/Object | 'Sigmoid' | Activation function for the nodes. Can be specified as a string name from available functions or as a custom function object |
| weightInitialization | Object | { type: 'Random', params: [-1, 1] } | Strategy for initializing connection weights. Can be specified as an object with type and parameters |
| minWeight | Number | -4.0 | Minimum allowed weight value for connections |
| maxWeight | Number | 4.0 | Maximum allowed weight value for connections |
| allowRecurrentConnections | Boolean | true | Whether recurrent connections are allowed in the network |
| recurrentConnectionRate | Number | 1.0 | Rate for forming recurrent connections when they are allowed |
Bias Settings
| Parameter | Type | Default | Description |
|---|
| bias | Number | 1.0 | The value for bias inputs (typically 1.0) |
| connectBias | Boolean | true | When true, automatically connects the bias node to all output nodes during network construction |
| biasMode | String | 'WEIGHTED_NODE' | Determines how bias is applied in the network. Options include:- WEIGHTED_NODE: Uses weights with bias (sum += biasWeight * bias)
- DIRECT_NODE: Uses connections but not weights (sum += bias if connected)
- CONSTANT: Traditional approach adding bias to every node (sum += bias)
- DISABLED: Disables bias entirely
|
Evolution Parameters
| Parameter | Type | Default | Description |
|---|
| populationSize | Number | 150 | Size of the population |
| generations | Number | 100 | Maximum number of generations for evolution |
| fitnessFunction | String/Object | 'XOR' | Function to evaluate genome fitness. Can be specified as a string name from available functions or as a custom function object |
| survivalRate | Number | 0.2 | Proportion of genomes in species that survives each generation |
| numOfElite | Number | 10 | Number of elite individuals to preserve unchanged in each generation |
| populationStagnationLimit | Number | 20 | Maximum number of generations without fitness improvement before population is considered stagnant |
| interspeciesMatingRate | Number | 0.001 | Rate of mating between individuals from different species |
| mutateOnlyProb | Number | 0.25 | Probability of producing offspring through mutation only (without crossover) |
Speciation Parameters
| Parameter | Type | Default | Description |
|---|
| c1 | Number | 1.0 | Coefficient for excess genes in compatibility distance calculation |
| c2 | Number | 1.0 | Coefficient for disjoint genes in compatibility distance calculation |
| c3 | Number | 0.4 | Coefficient for weight differences in compatibility distance calculation |
| compatibilityThreshold | Number | 3.0 | Maximum compatibility distance for genomes to be considered part of the same species |
| dropOffAge | Number | 15 | Maximum age for a species before it is removed if no fitness improvement is observed |
Mutation Parameters
| Parameter | Type | Default | Description |
|---|
| mutationRate | Number | 1.0 | Overall probability of applying mutation to offspring |
| weightMutationRate | Number | 0.8 | Probability of mutating connection weights |
| addConnectionMutationRate | Number | 0.05 | Probability of adding a new connection |
| addNodeMutationRate | Number | 0.03 | Probability of adding a new node |
| minPerturb | Number | -0.5 | Minimum perturbation value when mutating weights |
| maxPerturb | Number | 0.5 | Maximum perturbation value when mutating weights |
| reinitializeWeightRate | Number | 0.1 | Chance of reinitializing a weight when weight mutation is selected (each weight is evaluated individually) |
| keepDisabledOnCrossOverRate | Number | 0.75 | Probability of keeping connections disabled during crossover if they are disabled in either parent |
Available Built-in Functions
Activation Functions
| Name | Description |
|---|
| 'Sigmoid' | Standard sigmoid function: f(x) = 1 / (1 + e^(-x)) |
| 'NEATSigmoid' | Modified sigmoid function as used in the original NEAT paper |
| 'Tanh' | Hyperbolic tangent: f(x) = tanh(x) |
| 'ReLU' | Rectified Linear Unit: f(x) = max(0, x) |
| 'LeakyReLU' | Leaky Rectified Linear Unit: f(x) = x if x > 0, else αx |
| 'Gaussian' | Gaussian function: f(x) = e^(-x²) |
Weight Initializations
| Name | Parameters | Description |
|---|
| 'Random' | [min, max] | Initializes weights randomly within the specified range |
Fitness Functions
| Name | Description |
|---|
| 'XOR' | Evaluates fitness based on the XOR problem (built-in test case) |
Using Custom Functions
Custom Activation Function
// Create a custom activation function
class CustomActivation {
constructor(param = 1.0) {
this.param = param;
}
apply(x) {
return Math.sin(x * this.param);
}
}
// Use the custom activation function in configuration
const config = new Config({
activationFunction: new CustomActivation(0.5)
});
Custom Fitness Function
// Create a custom fitness function
class CartPoleFunction {
constructor(simulationSteps = 500) {
this.simulationSteps = simulationSteps;
}
calculateFitness(genome) {
let fitness = 0;
// Run cart-pole simulation with the genome
// ...
return fitness;
}
}
// Use the custom fitness function in configuration
const config = new Config({
inputSize: 4, // Cart position, velocity, pole angle, pole velocity
outputSize: 1, // Force direction
fitnessFunction: new CartPoleFunction(1000)
});