config.ts

config

NeatapticConfig

Global NeatapticTS configuration contract & default instance.

WHY THIS EXISTS

A central config object offers a convenient, documented surface for end-users (and tests) to tweak library behaviour without digging through scattered constants. Centralization also lets us validate & evolve feature flags in a single place.

USAGE PATTERN

import { config } from 'neataptic-ts'; config.warnings = true; // enable runtime warnings config.deterministicChainMode = true // opt into deterministic deep path construction

Adjust BEFORE constructing networks / invoking evolutionary loops so that subsystems read the intended values while initializing internal buffers / metadata.

DESIGN NOTES

neat.ts

neat

NeatOptions

Options

Configuration options for Neat evolutionary runs.

Each property is optional and the class applies sensible defaults when a field is not provided. Options control population size, mutation rates, compatibility coefficients, selection strategy and other behavioral knobs.

Example: const opts: NeatOptions = { popsize: 100, mutationRate: 0.5 }; const neat = new Neat(3, 1, fitnessFn, opts);

Note: this type is intentionally permissive to support staged migration and legacy callers; prefer providing a typed options object where possible.

default

_adaptivePruneLevel

Adaptive prune level for complexity control (optional).

_applyFitnessSharing

() => void

Apply fitness sharing within species. When sharingSigma > 0 this uses a kernel-based sharing; otherwise it falls back to classic per-species averaging. Sharing reduces effective fitness for similar genomes to promote diversity.

_bestScoreLastGen

Best score observed in the last generation (used for improvement detection).

_compatIntegral

Integral accumulator used by adaptive compatibility controllers.

_compatSpeciesEMA

Exponential moving average for compatibility threshold (adaptive speciation).

_computeDiversityStats

() => void

Compute and cache diversity statistics used by telemetry & tests.

_connInnovations

Map of connection innovations keyed by a string identifier.

_diversityStats

Cached diversity metrics (computed lazily).

_getObjectives

() => import("/home/runner/work/NeatapticTS/NeatapticTS/src/neat/neat.types").ObjectiveDescriptor[]

Internal: return cached objective descriptors, building if stale.

_invalidateGenomeCaches

(genome: any) => void

Invalidate per-genome caches (compatibility distance, forward pass, etc.).

_lastAncestorUniqAdjustGen

Generation when ancestor uniqueness adjustment was last applied.

_lastEpsilonAdjustGen

Generation when epsilon compatibility was last adjusted.

_lastEvalDuration

Duration of the last evaluation run (ms).

_lastEvolveDuration

Duration of the last evolve run (ms).

_lastGlobalImproveGeneration

Generation index where the last global improvement occurred.

_lastInbreedingCount

Last observed count of inbreeding (used for detecting excessive cloning).

_lastOffspringAlloc

Last allocated offspring set (used by adaptive allocators).

_lineageEnabled

Whether lineage metadata should be recorded on genomes.

_mcThreshold

Adaptive minimal criterion threshold (optional).

_nextGenomeId

Counter for assigning unique genome ids.

_nextGlobalInnovation

Counter for issuing global innovation numbers when explicit numbers are used.

_nodeSplitInnovations

Map of node-split innovations used to reuse innovation ids for node splits.

_noveltyArchive

Novelty archive used by novelty search (behavior representatives).

_objectiveAges

Map tracking ages for objectives by key.

_objectiveEvents

Queue of recent objective activation/deactivation events for telemetry.

_objectivesList

Cached list of registered objectives.

_objectiveStale

Map tracking stale counts for objectives by key.

_operatorStats

Operator statistics used by adaptive operator selection.

_paretoArchive

Archive of Pareto front metadata for multi-objective tracking.

_paretoObjectivesArchive

Archive storing Pareto objectives snapshots.

_pendingObjectiveAdds

Pending objective keys to add during safe phases.

_pendingObjectiveRemoves

Pending objective keys to remove during safe phases.

_phase

Optional phase marker for multi-stage experiments.

_prevInbreedingCount

Previous inbreeding count snapshot.

_prevSpeciesMembers

Map of species id -> set of member genome ids from previous generation.

_rng

Cached RNG function; created lazily and seeded from _rngState when used.

_rngState

Internal numeric state for the deterministic xorshift RNG when no user RNG is provided. Stored as a 32-bit unsigned integer.

_sortSpeciesMembers

(sp: { members: import("/home/runner/work/NeatapticTS/NeatapticTS/src/architecture/network").default[]; }) => void

Sort members of a species in-place by descending score.

Parameters:

_speciate

() => void

Assign genomes into species based on compatibility distance and maintain species structures. This function creates new species for unassigned genomes and prunes empty species. It also records species-level history used for telemetry and adaptive controllers.

_species

Array of current species (internal representation).

_speciesCreated

Map of speciesId -> creation generation for bookkeeping.

_speciesHistory

Time-series history of species stats (for exports/telemetry).

_speciesLastStats

Last recorded stats per species id.

_structuralEntropy

(genome: import("/home/runner/work/NeatapticTS/NeatapticTS/src/architecture/network").default) => number

Compatibility wrapper retained for tests that reference (neat as any)._structuralEntropy

_telemetry

Telemetry buffer storing diagnostic snapshots per generation.

_updateSpeciesStagnation

() => void

Update species stagnation tracking and remove species that exceeded the allowed stagnation.

_warnIfNoBestGenome

() => void

Emit a standardized warning when evolution loop finds no valid best genome (test hook).

addGenome

(genome: import("/home/runner/work/NeatapticTS/NeatapticTS/src/architecture/network").default, parents: number[] | undefined) => void

Register an externally-created genome into the Neat population.

Use this method when code constructs or mutates a Network outside of the usual reproduction pipeline and needs to insert it into neat.population while preserving lineage, id assignment, and structural invariants. The method performs best-effort safety actions and falls back to pushing the genome even if invariant enforcement throws, which mirrors the forgiving behavior used in dynamic population expansion.

Behavior summary:

Note: Because depth estimation requires parent objects to be discoverable in this.population, callers that generate intermediate parent genomes should register them via addGenome before relying on automatic depth estimation for their children.

Parameters:

applyAdaptivePruning

() => void

Run the adaptive pruning controller once. This adjusts the internal _adaptivePruneLevel based on the configured metric (nodes or connections) and invokes per-genome pruning when an adjustment is warranted.

Educational usage: Allows step-wise observation of how the adaptive controller converges population complexity toward a target sparsity.

applyEvolutionPruning

() => void

Manually apply evolution-time pruning once using the current generation index and configuration in options.evolutionPruning.

Educational usage: While pruning normally occurs automatically inside the evolve loop, exposing this method lets learners trigger the pruning logic in isolation to observe its effect on network sparsity.

Implementation detail: Delegates to the migrated helper in neat.pruning.ts so the core class surface remains thin.

clearObjectives

() => void

Register a custom objective for multi-objective optimization.

Educational context: multi-objective optimization lets you optimize for multiple, potentially conflicting goals (e.g., maximize fitness while minimizing complexity). Each objective is identified by a unique key and an accessor function mapping a genome to a numeric score. Registering an objective makes it visible to the internal MO pipeline and clears any cached objective list so changes take effect immediately.

Parameters:

clearParetoArchive

() => void

Clear the Pareto archive.

Removes any stored Pareto-front snapshots retained by the algorithm.

clearTelemetry

() => void

Export telemetry as CSV with flattened columns for common nested fields.

createPool

(network: import("/home/runner/work/NeatapticTS/NeatapticTS/src/architecture/network").default | null) => void

Create initial population pool. Delegates to helpers if present.

ensureMinHiddenNodes

(network: import("/home/runner/work/NeatapticTS/NeatapticTS/src/architecture/network").default, multiplierOverride: number | undefined) => void

Ensure a network has the minimum number of hidden nodes according to configured policy. Delegates to migrated helper implementation.

Parameters:

ensureNoDeadEnds

(network: import("/home/runner/work/NeatapticTS/NeatapticTS/src/architecture/network").default) => void

Delegate ensureNoDeadEnds to mutation module (added for backward compat).

evolve

() => Promise<import("/home/runner/work/NeatapticTS/NeatapticTS/src/architecture/network").default>

Evolves the population by selecting, mutating, and breeding genomes. This method is delegated to src/neat/neat.evolve.ts during the migration.

export

() => any[]

Exports the current population as an array of JSON objects. Useful for saving the state of the population for later use.

Returns: An array of JSON representations of the population.

exportParetoFrontJSONL

(maxEntries: number) => string

Export Pareto front archive as JSON Lines for external analysis.

Each line is a JSON object representing one archived Pareto snapshot.

Parameters:

Returns: Newline-separated JSON objects.

exportRNGState

() => number | undefined

Export the current RNG state for external persistence or tests.

exportSpeciesHistoryCSV

(maxEntries: number) => string

Return an array of {id, parents} for the first limit genomes in population.

exportSpeciesHistoryJSONL

(maxEntries: number) => string

Export species history as JSON Lines for storage and analysis.

Each line is a JSON object containing a generation index and per-species stats recorded at that generation. Useful for long-term tracking.

Parameters:

Returns: Newline-separated JSON objects.

exportState

() => any

Convenience: export full evolutionary state (meta + population genomes). Combines innovation registries and serialized genomes for easy persistence.

exportTelemetryCSV

(maxEntries: number) => string

Export recent telemetry entries as CSV.

The exporter attempts to flatten commonly-used nested fields (complexity, perf, lineage) into columns. This is a best-effort exporter intended for human inspection and simple ingestion.

Parameters:

Returns: CSV string (may be empty when no telemetry present).

exportTelemetryJSONL

() => string

Export telemetry as JSON Lines (one JSON object per line).

Useful for piping telemetry to external loggers or analysis tools.

Returns: A newline-separated string of JSON objects.

getAverage

() => number

Calculates the average fitness score of the population. Ensures that the population is evaluated before calculating the average.

Returns: The average fitness score of the population.

getDiversityStats

() => any

Return the latest cached diversity statistics.

Educational context: diversity metrics summarize how genetically and behaviorally spread the population is. They can include lineage depth, pairwise genetic distances, and other aggregated measures used by adaptive controllers, novelty search, and telemetry. This accessor returns whatever precomputed diversity object the Neat instance holds (may be undefined if not computed for the current generation).

Returns: Arbitrary diversity summary object or undefined.

getFittest

() => import("/home/runner/work/NeatapticTS/NeatapticTS/src/architecture/network").default

Retrieves the fittest genome from the population. Ensures that the population is evaluated and sorted before returning the result.

Returns: The fittest genome in the population.

getLineageSnapshot

(limit: number) => { id: number; parents: number[]; }[]

Get recent objective add/remove events.

getMinimumHiddenSize

(multiplierOverride: number | undefined) => number

Minimum hidden size considering explicit minHidden or multiplier policy.

getMultiObjectiveMetrics

() => { rank: number; crowding: number; score: number; nodes: number; connections: number; }[]

Returns compact multi-objective metrics for each genome in the current population. The metrics include Pareto rank and crowding distance (if computed), along with simple size and score measures useful in instructional contexts.

Returns: Array of per-genome MO metric objects.

getNoveltyArchiveSize

() => number

Returns the number of entries currently stored in the novelty archive.

Educational context: The novelty archive stores representative behaviors used by behavior-based novelty search. Monitoring its size helps teach how behavioral diversity accumulates over time and can be used to throttle archive growth.

Returns: Number of archived behaviors.

getObjectiveKeys

() => string[]

Public helper returning just the objective keys (tests rely on).

getObjectives

() => { key: string; direction: "max" | "min"; }[]

Clear all collected telemetry entries.

getOffspring

() => import("/home/runner/work/NeatapticTS/NeatapticTS/src/architecture/network").default

Generates an offspring by crossing over two parent networks. Uses the crossover method described in the Instinct algorithm.

Returns: A new network created from two parents.

getOperatorStats

() => { name: string; success: number; attempts: number; }[]

Returns a summary of mutation/operator statistics used by operator adaptation and bandit selection.

Educational context: Operator statistics track how often mutation operators are attempted and how often they succeed. These counters are used by adaptation mechanisms to bias operator selection towards successful operators.

Returns: Array of { name, success, attempts } objects.

getParent

() => import("/home/runner/work/NeatapticTS/NeatapticTS/src/architecture/network").default

Selects a parent genome for breeding based on the selection method. Supports multiple selection strategies, including POWER, FITNESS_PROPORTIONATE, and TOURNAMENT.

Returns: The selected parent genome.

getParetoArchive

(maxEntries: number) => any[]

Get recent Pareto archive entries (meta information about archived fronts).

Educational context: when performing multi-objective search we may store representative Pareto-front snapshots over time. This accessor returns the most recent archive entries up to the provided limit.

Parameters:

Returns: Array of archived Pareto metadata entries.

getParetoFronts

(maxFronts: number) => import("/home/runner/work/NeatapticTS/NeatapticTS/src/architecture/network").default[][]

Export species history as CSV.

Produces rows for each recorded per-species stat entry within the specified window. Useful for quick inspection or spreadsheet analysis.

Parameters:

Returns: CSV string (may be empty).

getPerformanceStats

() => { lastEvalMs: number | undefined; lastEvolveMs: number | undefined; }

Return recent performance statistics (durations in milliseconds) for the most recent evaluation and evolve operations.

Provides wall-clock timing useful for profiling and teaching how runtime varies with network complexity or population settings.

Returns: Object with { lastEvalMs, lastEvolveMs }.

getSpeciesHistory

() => import("/home/runner/work/NeatapticTS/NeatapticTS/src/neat/neat.types").SpeciesHistoryEntry[]

Returns the historical species statistics recorded each generation.

Educational context: Species history captures per-generation snapshots of species-level metrics (size, best score, last improvement) and is useful for plotting trends, teaching about speciation dynamics, and driving adaptive controllers.

The returned array contains entries with a generation index and a stats array containing per-species summaries recorded at that generation.

Returns: An array of generation-stamped species stat snapshots.

getSpeciesStats

() => { id: number; size: number; bestScore: number; lastImproved: number; }[]

Return a concise summary for each current species.

Educational context: In NEAT, populations are partitioned into species based on genetic compatibility. Each species groups genomes that are similar so selection and reproduction can preserve diversity between groups. This accessor provides a lightweight view suitable for telemetry, visualization and teaching examples without exposing full genome objects.

The returned array contains objects with these fields:

Notes for learners:

Returns: An array of species summary objects.

getTelemetry

() => any[]

Return the internal telemetry buffer.

Telemetry entries are produced per-generation when telemetry is enabled and include diagnostic metrics (diversity, performance, lineage, etc.). This accessor returns the raw buffer for external inspection or export.

Returns: Array of telemetry snapshot objects.

import

(json: any[]) => void

Imports a population from an array of JSON objects. Replaces the current population with the imported one.

Parameters:

importRNGState

(state: any) => void

Import an RNG state (alias for restore; kept for compatibility).

Parameters:

importState

(bundle: any, fitness: (n: import("/home/runner/work/NeatapticTS/NeatapticTS/src/architecture/network").default) => number) => import("/home/runner/work/NeatapticTS/NeatapticTS/src/neat").default

Convenience: restore full evolutionary state previously produced by exportState().

Parameters:

mutate

() => void

Applies mutations to the population based on the mutation rate and amount. Each genome is mutated using the selected mutation methods. Slightly increases the chance of ADD_CONN mutation for more connectivity.

resetNoveltyArchive

() => void

Reset the novelty archive (clear entries).

The novelty archive is used to keep representative behaviors for novelty search. Clearing it removes stored behaviors.

restoreRNGState

(state: any) => void

Restore a previously-snapshotted RNG state. This restores the internal seed but does not re-create the RNG function until next use.

Parameters:

sampleRandom

(count: number) => number[]

Produce count deterministic random samples using instance RNG.

selectMutationMethod

(genome: import("/home/runner/work/NeatapticTS/NeatapticTS/src/architecture/network").default, rawReturnForTest: boolean) => any

Selects a mutation method for a given genome based on constraints. Ensures that the mutation respects the maximum nodes, connections, and gates.

Parameters:

Returns: The selected mutation method or null if no valid method is available.

snapshotRNGState

() => number | undefined

Return the current opaque RNG numeric state used by the instance. Useful for deterministic test replay and debugging.

sort

() => void

Sorts the population in descending order of fitness scores. Ensures that the fittest genomes are at the start of the population array.

spawnFromParent

(parent: import("/home/runner/work/NeatapticTS/NeatapticTS/src/architecture/network").default, mutateCount: number) => import("/home/runner/work/NeatapticTS/NeatapticTS/src/architecture/network").default

Spawn a new genome derived from a single parent while preserving Neat bookkeeping.

This helper performs a canonical "clone + slight mutation" workflow while keeping Neat's internal invariants intact. It is intended for callers that want a child genome derived from a single parent but do not want to perform the bookkeeping and registration steps manually. The function deliberately does NOT add the returned child to this.population so callers are free to inspect or further modify the child and then register it via addGenome() (or push it directly if they understand the consequences).

Behavior summary:

Important: the returned child is not registered in Neat.population — call addGenome(child, [parentId]) to insert it and keep telemetry/lineage consistent.

Parameters:

Returns: A new Network instance derived from parent. The child is unregistered.

toJSON

() => any

Import a previously exported state bundle and rehydrate a Neat instance.

neataptic.ts

neataptic

Network (Evolvable / Trainable Graph)

Represents a directed neural computation graph used both as a NEAT genome phenotype and (optionally) as a gradient‑trainable model. The class binds together specialized modules (topology, pruning, serialization, slab packing) to keep the core surface approachable for learners.

Educational Highlights:

Typical Usage:

const net = new Network(4, 2);           // create network
const out = net.activate([0.1,0.3,0.2,0.9]);
net.addNodeBetween();                    // structural mutation
const slab = (net as any).getConnectionSlab(); // inspect packed arrays
const clone = net.clone();               // deep copy

Performance Guidance:

Serialization:

default

_activateCore

(withTrace: boolean, input: number | undefined) => number

Internal shared implementation for activate/noTraceActivate.

Parameters:

_adaptivePruneLevel

Adaptive prune level for complexity control (optional).

_applyFitnessSharing

() => void

Apply fitness sharing within species. When sharingSigma > 0 this uses a kernel-based sharing; otherwise it falls back to classic per-species averaging. Sharing reduces effective fitness for similar genomes to promote diversity.

_applyGradientClipping

(cfg: { mode: "norm" | "percentile" | "layerwiseNorm" | "layerwisePercentile"; maxNorm?: number | undefined; percentile?: number | undefined; }) => void

Trains the network on a given dataset subset for one pass (epoch or batch). Performs activation and backpropagation for each item in the set. Updates weights based on batch size configuration.

Parameters:

Returns: The average error calculated over the provided dataset subset.

_bestScoreLastGen

Best score observed in the last generation (used for improvement detection).

_compatIntegral

Integral accumulator used by adaptive compatibility controllers.

_compatSpeciesEMA

Exponential moving average for compatibility threshold (adaptive speciation).

_computeDiversityStats

() => void

Compute and cache diversity statistics used by telemetry & tests.

_connInnovations

Map of connection innovations keyed by a string identifier.

_diversityStats

Cached diversity metrics (computed lazily).

_flags

Packed state flags (private for future-proofing hidden class): bit0 => enabled gene expression (1 = active) bit1 => DropConnect active mask (1 = not dropped this forward pass) bit2 => hasGater (1 = symbol field present) bit3 => plastic (plasticityRate > 0) bits4+ reserved.

_getObjectives

() => import("/home/runner/work/NeatapticTS/NeatapticTS/src/neat/neat.types").ObjectiveDescriptor[]

Internal: return cached objective descriptors, building if stale.

_globalNodeIndex

Global index counter for assigning unique indices to nodes.

_invalidateGenomeCaches

(genome: any) => void

Invalidate per-genome caches (compatibility distance, forward pass, etc.).

_lastAncestorUniqAdjustGen

Generation when ancestor uniqueness adjustment was last applied.

_lastEpsilonAdjustGen

Generation when epsilon compatibility was last adjusted.

_lastEvalDuration

Duration of the last evaluation run (ms).

_lastEvolveDuration

Duration of the last evolve run (ms).

_lastGlobalImproveGeneration

Generation index where the last global improvement occurred.

_lastInbreedingCount

Last observed count of inbreeding (used for detecting excessive cloning).

_lastOffspringAlloc

Last allocated offspring set (used by adaptive allocators).

_lineageEnabled

Whether lineage metadata should be recorded on genomes.

_mcThreshold

Adaptive minimal criterion threshold (optional).

_nextGenomeId

Counter for assigning unique genome ids.

_nextGlobalInnovation

Counter for issuing global innovation numbers when explicit numbers are used.

_nodeSplitInnovations

Map of node-split innovations used to reuse innovation ids for node splits.

_noveltyArchive

Novelty archive used by novelty search (behavior representatives).

_objectiveAges

Map tracking ages for objectives by key.

_objectiveEvents

Queue of recent objective activation/deactivation events for telemetry.

_objectivesList

Cached list of registered objectives.

_objectiveStale

Map tracking stale counts for objectives by key.

_operatorStats

Operator statistics used by adaptive operator selection.

_paretoArchive

Archive of Pareto front metadata for multi-objective tracking.

_paretoObjectivesArchive

Archive storing Pareto objectives snapshots.

_pendingObjectiveAdds

Pending objective keys to add during safe phases.

_pendingObjectiveRemoves

Pending objective keys to remove during safe phases.

_phase

Optional phase marker for multi-stage experiments.

_prevInbreedingCount

Previous inbreeding count snapshot.

_prevSpeciesMembers

Map of species id -> set of member genome ids from previous generation.

_rng

Cached RNG function; created lazily and seeded from _rngState when used.

_rngState

Internal numeric state for the deterministic xorshift RNG when no user RNG is provided. Stored as a 32-bit unsigned integer.

_safeUpdateWeight

(connection: import("/home/runner/work/NeatapticTS/NeatapticTS/src/architecture/connection").default, delta: number) => void

Internal helper to safely update a connection weight with clipping and NaN checks.

_sortSpeciesMembers

(sp: { members: import("/home/runner/work/NeatapticTS/NeatapticTS/src/architecture/network").default[]; }) => void

Sort members of a species in-place by descending score.

Parameters:

_speciate

() => void

Assign genomes into species based on compatibility distance and maintain species structures. This function creates new species for unassigned genomes and prunes empty species. It also records species-level history used for telemetry and adaptive controllers.

_species

Array of current species (internal representation).

_speciesCreated

Map of speciesId -> creation generation for bookkeeping.

_speciesHistory

Time-series history of species stats (for exports/telemetry).

_speciesLastStats

Last recorded stats per species id.

_structuralEntropy

(genome: import("/home/runner/work/NeatapticTS/NeatapticTS/src/architecture/network").default) => number

Compatibility wrapper retained for tests that reference (neat as any)._structuralEntropy

_telemetry

Telemetry buffer storing diagnostic snapshots per generation.

_updateSpeciesStagnation

() => void

Update species stagnation tracking and remove species that exceeded the allowed stagnation.

_warnIfNoBestGenome

() => void

Emit a standardized warning when evolution loop finds no valid best genome (test hook).

acquire

(from: import("/home/runner/work/NeatapticTS/NeatapticTS/src/architecture/node").default, to: import("/home/runner/work/NeatapticTS/NeatapticTS/src/architecture/node").default, weight: number | undefined) => import("/home/runner/work/NeatapticTS/NeatapticTS/src/architecture/connection").default

Acquire a Connection from the pool (or construct new). Fields are fully reset & given a fresh sequential innovation id. Prefer this in evolutionary algorithms that mutate topology frequently to reduce GC pressure.

Parameters:

Returns: Reinitialized connection instance.

activate

(input: number[], training: boolean, maxActivationDepth: number) => number[]

Activates the network using the given input array. Performs a forward pass through the network, calculating the activation of each node.

Parameters:

Returns: An array of numerical values representing the activations of the network's output nodes.

activate

(input: number | undefined) => number

Activates the node, calculating its output value based on inputs and state. This method also calculates eligibility traces (xtrace) used for training recurrent connections.

The activation process involves:

  1. Calculating the node's internal state (this.state) based on:
    • Incoming connections' weighted activations.
    • The recurrent self-connection's weighted state from the previous timestep (this.old).
    • The node's bias.
  2. Applying the activation function (this.squash) to the state to get the activation (this.activation).
  3. Applying the dropout mask (this.mask).
  4. Calculating the derivative of the activation function.
  5. Updating the gain of connections gated by this node.
  6. Calculating and updating eligibility traces for incoming connections.

Parameters:

Returns: The calculated activation value of the node.

activate

(value: number[] | undefined, training: boolean) => number[]

Activates all nodes within the layer, computing their output values.

If an input value array is provided, it's used as the initial activation for the corresponding nodes in the layer. Otherwise, nodes compute their activation based on their incoming connections.

During training, layer-level dropout is applied, masking all nodes in the layer together. During inference, all masks are set to 1.

Parameters:

Returns: An array containing the activation value of each node in the layer after activation.

activate

(value: number[] | undefined) => number[]

Activates all nodes in the group. If input values are provided, they are assigned sequentially to the nodes before activation. Otherwise, nodes activate based on their existing states and incoming connections.

Parameters:

Returns: An array containing the activation value of each node in the group, in order.

activateBatch

(inputs: number[][], training: boolean) => number[][]

Activate the network over a batch of input vectors (micro-batching).

Currently iterates sample-by-sample while reusing the network's internal fast-path allocations. Outputs are cloned number[] arrays for API compatibility. Future optimizations can vectorize this path.

Parameters:

Returns: Array of output vectors, each length equals this.output

activateRaw

(input: number[], training: boolean, maxActivationDepth: number) => any

Raw activation that can return a typed array when pooling is enabled (zero-copy). If reuseActivationArrays=false falls back to standard activate().

activation

The output value of the node after applying the activation function. This is the value transmitted to connected nodes.

addGenome

(genome: import("/home/runner/work/NeatapticTS/NeatapticTS/src/architecture/network").default, parents: number[] | undefined) => void

Register an externally-created genome into the Neat population.

Use this method when code constructs or mutates a Network outside of the usual reproduction pipeline and needs to insert it into neat.population while preserving lineage, id assignment, and structural invariants. The method performs best-effort safety actions and falls back to pushing the genome even if invariant enforcement throws, which mirrors the forgiving behavior used in dynamic population expansion.

Behavior summary:

Note: Because depth estimation requires parent objects to be discoverable in this.population, callers that generate intermediate parent genomes should register them via addGenome before relying on automatic depth estimation for their children.

Parameters:

adjustRateForAccumulation

(rate: number, accumulationSteps: number, reduction: "average" | "sum") => number

Utility: adjust rate for accumulation mode (use result when switching to 'sum' to mimic 'average').

applyAdaptivePruning

() => void

Run the adaptive pruning controller once. This adjusts the internal _adaptivePruneLevel based on the configured metric (nodes or connections) and invokes per-genome pruning when an adjustment is warranted.

Educational usage: Allows step-wise observation of how the adaptive controller converges population complexity toward a target sparsity.

applyBatchUpdates

(momentum: number) => void

Applies accumulated batch updates to incoming and self connections and this node's bias. Uses momentum in a Nesterov-compatible way: currentDelta = accumulated + momentum * previousDelta. Resets accumulators after applying. Safe to call on any node type.

Parameters:

applyBatchUpdatesWithOptimizer

(opts: { type: "sgd" | "rmsprop" | "adagrad" | "adam" | "adamw" | "amsgrad" | "adamax" | "nadam" | "radam" | "lion" | "adabelief" | "lookahead"; momentum?: number | undefined; beta1?: number | undefined; beta2?: number | undefined; eps?: number | undefined; weightDecay?: number | undefined; lrScale?: number | undefined; t?: number | undefined; baseType?: any; la_k?: number | undefined; la_alpha?: number | undefined; }) => void

Extended batch update supporting multiple optimizers.

Applies accumulated (batch) gradients stored in totalDeltaWeight / totalDeltaBias to the underlying weights and bias using the selected optimization algorithm. Supports both classic SGD (with Nesterov-style momentum via preceding propagate logic) and a collection of adaptive optimizers. After applying an update, gradient accumulators are reset to 0.

Supported optimizers (type):

Options:

Internal per-connection temp fields (created lazily):

Safety: We clip extreme weight / bias magnitudes and guard against NaN/Infinity.

Parameters:

applyEvolutionPruning

() => void

Manually apply evolution-time pruning once using the current generation index and configuration in options.evolutionPruning.

Educational usage: While pruning normally occurs automatically inside the evolve loop, exposing this method lets learners trigger the pruning logic in isolation to observe its effect on network sparsity.

Implementation detail: Delegates to the migrated helper in neat.pruning.ts so the core class surface remains thin.

attention

(size: number, heads: number) => import("/home/runner/work/NeatapticTS/NeatapticTS/src/architecture/layer").default

Creates a multi-head self-attention layer (stub implementation).

Parameters:

Returns: A new Layer instance representing an attention layer.

batchNorm

(size: number) => import("/home/runner/work/NeatapticTS/NeatapticTS/src/architecture/layer").default

Creates a batch normalization layer. Applies batch normalization to the activations of the nodes in this layer during activation.

Parameters:

Returns: A new Layer instance configured as a batch normalization layer.

bias

The bias value of the node. Added to the weighted sum of inputs before activation. Input nodes typically have a bias of 0.

clear

() => void

Clears the internal state of all nodes in the network. Resets node activation, state, eligibility traces, and extended traces to their initial values (usually 0). This is typically done before processing a new input sequence in recurrent networks or between training epochs if desired.

clearObjectives

() => void

Register a custom objective for multi-objective optimization.

Educational context: multi-objective optimization lets you optimize for multiple, potentially conflicting goals (e.g., maximize fitness while minimizing complexity). Each objective is identified by a unique key and an accessor function mapping a genome to a numeric score. Registering an objective makes it visible to the internal MO pipeline and clears any cached objective list so changes take effect immediately.

Parameters:

clearParetoArchive

() => void

Clear the Pareto archive.

Removes any stored Pareto-front snapshots retained by the algorithm.

clearTelemetry

() => void

Export telemetry as CSV with flattened columns for common nested fields.

clone

() => import("/home/runner/work/NeatapticTS/NeatapticTS/src/architecture/network").default

Creates a deep copy of the network.

Returns: A new Network instance that is a clone of the current network.

connect

(from: import("/home/runner/work/NeatapticTS/NeatapticTS/src/architecture/node").default, to: import("/home/runner/work/NeatapticTS/NeatapticTS/src/architecture/node").default, weight: number | undefined) => import("/home/runner/work/NeatapticTS/NeatapticTS/src/architecture/connection").default[]

Creates a connection between two nodes in the network. Handles both regular connections and self-connections. Adds the new connection object(s) to the appropriate network list (connections or selfconns).

Parameters:

Returns: An array containing the newly created connection object(s). Typically contains one connection, but might be empty or contain more in specialized node types.

connect

(target: import("/home/runner/work/NeatapticTS/NeatapticTS/src/architecture/node").default | { nodes: import("/home/runner/work/NeatapticTS/NeatapticTS/src/architecture/node").default[]; }, weight: number | undefined) => import("/home/runner/work/NeatapticTS/NeatapticTS/src/architecture/connection").default[]

Creates a connection from this node to a target node or all nodes in a group.

Parameters:

Returns: An array containing the newly created Connection object(s).

connect

(target: import("/home/runner/work/NeatapticTS/NeatapticTS/src/architecture/node").default | import("/home/runner/work/NeatapticTS/NeatapticTS/src/architecture/layer").default | import("/home/runner/work/NeatapticTS/NeatapticTS/src/architecture/group").default, method: any, weight: number | undefined) => any[]

Connects this layer's output to a target component (Layer, Group, or Node).

This method delegates the connection logic primarily to the layer's output group or the target layer's input method. It establishes the forward connections necessary for signal propagation.

Parameters:

Returns: An array containing the newly created connection objects.

connections

Stores incoming, outgoing, gated, and self-connections for this node.

construct

(list: (import("/home/runner/work/NeatapticTS/NeatapticTS/src/architecture/node").default | import("/home/runner/work/NeatapticTS/NeatapticTS/src/architecture/layer").default | import("/home/runner/work/NeatapticTS/NeatapticTS/src/architecture/group").default)[]) => import("/home/runner/work/NeatapticTS/NeatapticTS/src/architecture/network").default

Constructs a Network instance from an array of interconnected Layers, Groups, or Nodes.

This method processes the input list, extracts all unique nodes, identifies connections, gates, and self-connections, and determines the network's input and output sizes based on the type property ('input' or 'output') set on the nodes. It uses Sets internally for efficient handling of unique elements during construction.

Parameters:

Returns: A Network object representing the constructed architecture.

conv1d

(size: number, kernelSize: number, stride: number, padding: number) => import("/home/runner/work/NeatapticTS/NeatapticTS/src/architecture/layer").default

Creates a 1D convolutional layer (stub implementation).

Parameters:

Returns: A new Layer instance representing a 1D convolutional layer.

createMLP

(inputCount: number, hiddenCounts: number[], outputCount: number) => import("/home/runner/work/NeatapticTS/NeatapticTS/src/architecture/network").default

Creates a fully connected, strictly layered MLP network.

Parameters:

Returns: A new, fully connected, layered MLP

createPool

(network: import("/home/runner/work/NeatapticTS/NeatapticTS/src/architecture/network").default | null) => void

Create initial population pool. Delegates to helpers if present.

crossOver

(network1: import("/home/runner/work/NeatapticTS/NeatapticTS/src/architecture/network").default, network2: import("/home/runner/work/NeatapticTS/NeatapticTS/src/architecture/network").default, equal: boolean) => import("/home/runner/work/NeatapticTS/NeatapticTS/src/architecture/network").default

Creates a new offspring network by performing crossover between two parent networks. This method implements the crossover mechanism inspired by the NEAT algorithm and described in the Instinct paper, combining genes (nodes and connections) from both parents. Fitness scores can influence the inheritance process. Matching genes are inherited randomly, while disjoint/excess genes are typically inherited from the fitter parent (or randomly if fitness is equal or equal flag is set).

Parameters:

Returns: A new Network instance representing the offspring.

dcMask

DropConnect active mask: 1 = not dropped (active), 0 = dropped for this stochastic pass.

dense

(size: number) => import("/home/runner/work/NeatapticTS/NeatapticTS/src/architecture/layer").default

Creates a standard fully connected (dense) layer.

All nodes in the source layer/group will connect to all nodes in this layer when using the default ALL_TO_ALL connection method via layer.input().

Parameters:

Returns: A new Layer instance configured as a dense layer.

derivative

The derivative of the activation function evaluated at the node's current state. Used in backpropagation.

deserialize

(data: any[], inputSize: number | undefined, outputSize: number | undefined) => import("/home/runner/work/NeatapticTS/NeatapticTS/src/architecture/network").default

Creates a Network instance from serialized data produced by serialize(). Reconstructs the network structure and state based on the provided arrays.

Parameters:

Returns: A new Network instance reconstructed from the serialized data.

disconnect

(from: import("/home/runner/work/NeatapticTS/NeatapticTS/src/architecture/node").default, to: import("/home/runner/work/NeatapticTS/NeatapticTS/src/architecture/node").default) => void

Disconnects two nodes, removing the connection between them. Handles both regular connections and self-connections. If the connection being removed was gated, it is also ungated.

Parameters:

disconnect

(target: import("/home/runner/work/NeatapticTS/NeatapticTS/src/architecture/node").default, twosided: boolean) => void

Removes the connection from this node to the target node.

Parameters:

disconnect

(target: import("/home/runner/work/NeatapticTS/NeatapticTS/src/architecture/node").default | import("/home/runner/work/NeatapticTS/NeatapticTS/src/architecture/group").default, twosided: boolean | undefined) => void

Removes connections between this layer's nodes and a target Group or Node.

Parameters:

disconnect

(target: import("/home/runner/work/NeatapticTS/NeatapticTS/src/architecture/node").default | import("/home/runner/work/NeatapticTS/NeatapticTS/src/architecture/group").default, twosided: boolean) => void

Removes connections between nodes in this group and a target Group or Node.

Parameters:

dropConnectActiveMask

Convenience alias for DropConnect mask with clearer naming.

dropout

Dropout rate for this layer (0 to 1). If > 0, all nodes in the layer are masked together during training. Layer-level dropout takes precedence over node-level dropout for nodes in this layer.

eligibility

Standard eligibility trace (e.g., for RTRL / policy gradient credit assignment).

enabled

Whether the gene (connection) is currently expressed (participates in forward pass).

enableWeightNoise

(stdDev: number | { perHiddenLayer: number[]; }) => void

Enable weight noise. Provide a single std dev number or { perHiddenLayer: number[] }.

enforceMinimumHiddenLayerSizes

(network: import("/home/runner/work/NeatapticTS/NeatapticTS/src/architecture/network").default) => import("/home/runner/work/NeatapticTS/NeatapticTS/src/architecture/network").default

Enforces the minimum hidden layer size rule on a network.

This ensures that all hidden layers have at least min(input, output) + 1 nodes, which is a common heuristic to ensure networks have adequate representation capacity.

Parameters:

Returns: The same network with properly sized hidden layers

ensureMinHiddenNodes

(network: import("/home/runner/work/NeatapticTS/NeatapticTS/src/architecture/network").default, multiplierOverride: number | undefined) => void

Ensure a network has the minimum number of hidden nodes according to configured policy. Delegates to migrated helper implementation.

Parameters:

ensureNoDeadEnds

(network: import("/home/runner/work/NeatapticTS/NeatapticTS/src/architecture/network").default) => void

Delegate ensureNoDeadEnds to mutation module (added for backward compat).

error

Stores error values calculated during backpropagation.

evolve

() => Promise<import("/home/runner/work/NeatapticTS/NeatapticTS/src/architecture/network").default>

Evolves the population by selecting, mutating, and breeding genomes. This method is delegated to src/neat/neat.evolve.ts during the migration.

export

() => any[]

Exports the current population as an array of JSON objects. Useful for saving the state of the population for later use.

Returns: An array of JSON representations of the population.

exportParetoFrontJSONL

(maxEntries: number) => string

Export Pareto front archive as JSON Lines for external analysis.

Each line is a JSON object representing one archived Pareto snapshot.

Parameters:

Returns: Newline-separated JSON objects.

exportRNGState

() => number | undefined

Export the current RNG state for external persistence or tests.

exportSpeciesHistoryCSV

(maxEntries: number) => string

Return an array of {id, parents} for the first limit genomes in population.

exportSpeciesHistoryJSONL

(maxEntries: number) => string

Export species history as JSON Lines for storage and analysis.

Each line is a JSON object containing a generation index and per-species stats recorded at that generation. Useful for long-term tracking.

Parameters:

Returns: Newline-separated JSON objects.

exportState

() => any

Convenience: export full evolutionary state (meta + population genomes). Combines innovation registries and serialized genomes for easy persistence.

exportTelemetryCSV

(maxEntries: number) => string

Export recent telemetry entries as CSV.

The exporter attempts to flatten commonly-used nested fields (complexity, perf, lineage) into columns. This is a best-effort exporter intended for human inspection and simple ingestion.

Parameters:

Returns: CSV string (may be empty when no telemetry present).

exportTelemetryJSONL

() => string

Export telemetry as JSON Lines (one JSON object per line).

Useful for piping telemetry to external loggers or analysis tools.

Returns: A newline-separated string of JSON objects.

fastSlabActivate

(input: number[]) => number[]

Public wrapper for fast slab forward pass (primarily for tests / benchmarking). Prefer using standard activate(); it will auto dispatch when eligible. Falls back internally if prerequisites not met.

firstMoment

First moment estimate (Adam / AdamW) (was opt_m).

from

The source (pre-synaptic) node supplying activation.

fromJSON

(json: any) => import("/home/runner/work/NeatapticTS/NeatapticTS/src/architecture/network").default

Reconstructs a network from a JSON object (latest standard). Handles formatVersion, robust error handling, and index-based references.

Parameters:

Returns: The reconstructed network.

fromJSON

(json: { bias: number; type: string; squash: string; mask: number; }) => import("/home/runner/work/NeatapticTS/NeatapticTS/src/architecture/node").default

Creates a Node instance from a JSON object.

Parameters:

Returns: A new Node instance configured according to the JSON object.

gain

Multiplicative modulation applied after weight. Default is 1 (neutral). We only store an internal symbol-keyed property when the gain is non-neutral, reducing memory usage across large populations where most connections are ungated.

gate

(node: import("/home/runner/work/NeatapticTS/NeatapticTS/src/architecture/node").default, connection: import("/home/runner/work/NeatapticTS/NeatapticTS/src/architecture/connection").default) => void

Gates a connection with a specified node. The activation of the node (gater) will modulate the weight of the connection. Adds the connection to the network's gates list.

Parameters:

gate

(connections: import("/home/runner/work/NeatapticTS/NeatapticTS/src/architecture/connection").default | import("/home/runner/work/NeatapticTS/NeatapticTS/src/architecture/connection").default[]) => void

Makes this node gate the provided connection(s). The connection's gain will be controlled by this node's activation value.

Parameters:

gate

(connections: any[], method: any) => void

Applies gating to a set of connections originating from this layer's output group.

Gating allows the activity of nodes in this layer (specifically, the output group) to modulate the flow of information through the specified connections.

Parameters:

gate

(connections: any, method: any) => void

Configures nodes within this group to act as gates for the specified connection(s). Gating allows the output of a node in this group to modulate the flow of signal through the gated connection.

Parameters:

gater

Optional gating node whose activation can modulate effective weight (symbol-backed).

geneId

Stable per-node gene identifier for NEAT innovation reuse

getAverage

() => number

Calculates the average fitness score of the population. Ensures that the population is evaluated before calculating the average.

Returns: The average fitness score of the population.

getDiversityStats

() => any

Return the latest cached diversity statistics.

Educational context: diversity metrics summarize how genetically and behaviorally spread the population is. They can include lineage depth, pairwise genetic distances, and other aggregated measures used by adaptive controllers, novelty search, and telemetry. This accessor returns whatever precomputed diversity object the Neat instance holds (may be undefined if not computed for the current generation).

Returns: Arbitrary diversity summary object or undefined.

getFittest

() => import("/home/runner/work/NeatapticTS/NeatapticTS/src/architecture/network").default

Retrieves the fittest genome from the population. Ensures that the population is evaluated and sorted before returning the result.

Returns: The fittest genome in the population.

getLastGradClipGroupCount

() => number

Returns last gradient clipping group count (0 if no clipping yet).

getLineageSnapshot

(limit: number) => { id: number; parents: number[]; }[]

Get recent objective add/remove events.

getLossScale

() => number

Returns current mixed precision loss scale (1 if disabled).

getMinimumHiddenSize

(multiplierOverride: number | undefined) => number

Minimum hidden size considering explicit minHidden or multiplier policy.

getMultiObjectiveMetrics

() => { rank: number; crowding: number; score: number; nodes: number; connections: number; }[]

Returns compact multi-objective metrics for each genome in the current population. The metrics include Pareto rank and crowding distance (if computed), along with simple size and score measures useful in instructional contexts.

Returns: Array of per-genome MO metric objects.

getNoveltyArchiveSize

() => number

Returns the number of entries currently stored in the novelty archive.

Educational context: The novelty archive stores representative behaviors used by behavior-based novelty search. Monitoring its size helps teach how behavioral diversity accumulates over time and can be used to throttle archive growth.

Returns: Number of archived behaviors.

getObjectiveKeys

() => string[]

Public helper returning just the objective keys (tests rely on).

getObjectives

() => { key: string; direction: "max" | "min"; }[]

Clear all collected telemetry entries.

getOffspring

() => import("/home/runner/work/NeatapticTS/NeatapticTS/src/architecture/network").default

Generates an offspring by crossing over two parent networks. Uses the crossover method described in the Instinct algorithm.

Returns: A new network created from two parents.

getOperatorStats

() => { name: string; success: number; attempts: number; }[]

Returns a summary of mutation/operator statistics used by operator adaptation and bandit selection.

Educational context: Operator statistics track how often mutation operators are attempted and how often they succeed. These counters are used by adaptation mechanisms to bias operator selection towards successful operators.

Returns: Array of { name, success, attempts } objects.

getParent

() => import("/home/runner/work/NeatapticTS/NeatapticTS/src/architecture/network").default

Selects a parent genome for breeding based on the selection method. Supports multiple selection strategies, including POWER, FITNESS_PROPORTIONATE, and TOURNAMENT.

Returns: The selected parent genome.

getParetoArchive

(maxEntries: number) => any[]

Get recent Pareto archive entries (meta information about archived fronts).

Educational context: when performing multi-objective search we may store representative Pareto-front snapshots over time. This accessor returns the most recent archive entries up to the provided limit.

Parameters:

Returns: Array of archived Pareto metadata entries.

getParetoFronts

(maxFronts: number) => import("/home/runner/work/NeatapticTS/NeatapticTS/src/architecture/network").default[][]

Export species history as CSV.

Produces rows for each recorded per-species stat entry within the specified window. Useful for quick inspection or spreadsheet analysis.

Parameters:

Returns: CSV string (may be empty).

getPerformanceStats

() => { lastEvalMs: number | undefined; lastEvolveMs: number | undefined; }

Return recent performance statistics (durations in milliseconds) for the most recent evaluation and evolve operations.

Provides wall-clock timing useful for profiling and teaching how runtime varies with network complexity or population settings.

Returns: Object with { lastEvalMs, lastEvolveMs }.

getRawGradientNorm

() => number

Returns last recorded raw (pre-update) gradient L2 norm.

getSpeciesHistory

() => import("/home/runner/work/NeatapticTS/NeatapticTS/src/neat/neat.types").SpeciesHistoryEntry[]

Returns the historical species statistics recorded each generation.

Educational context: Species history captures per-generation snapshots of species-level metrics (size, best score, last improvement) and is useful for plotting trends, teaching about speciation dynamics, and driving adaptive controllers.

The returned array contains entries with a generation index and a stats array containing per-species summaries recorded at that generation.

Returns: An array of generation-stamped species stat snapshots.

getSpeciesStats

() => { id: number; size: number; bestScore: number; lastImproved: number; }[]

Return a concise summary for each current species.

Educational context: In NEAT, populations are partitioned into species based on genetic compatibility. Each species groups genomes that are similar so selection and reproduction can preserve diversity between groups. This accessor provides a lightweight view suitable for telemetry, visualization and teaching examples without exposing full genome objects.

The returned array contains objects with these fields:

Notes for learners:

Returns: An array of species summary objects.

getTelemetry

() => any[]

Return the internal telemetry buffer.

Telemetry entries are produced per-generation when telemetry is enabled and include diagnostic metrics (diversity, performance, lineage, etc.). This accessor returns the raw buffer for external inspection or export.

Returns: Array of telemetry snapshot objects.

getTrainingStats

() => { gradNorm: number; gradNormRaw: number; lossScale: number; optimizerStep: number; mp: { good: number; bad: number; overflowCount: number; scaleUps: number; scaleDowns: number; lastOverflowStep: number; }; }

Consolidated training stats snapshot.

gradientAccumulator

Generic gradient accumulator (RMSProp / AdaGrad) (was opt_cache).

gru

(size: number) => import("/home/runner/work/NeatapticTS/NeatapticTS/src/architecture/layer").default

Creates a Gated Recurrent Unit (GRU) layer.

GRUs are another type of recurrent neural network cell, often considered simpler than LSTMs but achieving similar performance on many tasks. They use an update gate and a reset gate to manage information flow.

Parameters:

Returns: A new Layer instance configured as a GRU layer.

gru

(layers: number[]) => import("/home/runner/work/NeatapticTS/NeatapticTS/src/architecture/network").default

Creates a Gated Recurrent Unit (GRU) network. GRUs are another type of recurrent neural network, similar to LSTMs but often simpler. This constructor uses Layer.gru to create the core GRU blocks.

Parameters:

Returns: The constructed GRU network.

hasGater

Whether a gater node is assigned (modulates gain); true if the gater symbol field is present.

hopfield

(size: number) => import("/home/runner/work/NeatapticTS/NeatapticTS/src/architecture/network").default

Creates a Hopfield network. Hopfield networks are a form of recurrent neural network often used for associative memory tasks. This implementation creates a simple, fully connected structure.

Parameters:

Returns: The constructed Hopfield network.

import

(json: any[]) => void

Imports a population from an array of JSON objects. Replaces the current population with the imported one.

Parameters:

importRNGState

(state: any) => void

Import an RNG state (alias for restore; kept for compatibility).

Parameters:

importState

(bundle: any, fitness: (n: import("/home/runner/work/NeatapticTS/NeatapticTS/src/architecture/network").default) => number) => import("/home/runner/work/NeatapticTS/NeatapticTS/src/neat").default

Convenience: restore full evolutionary state previously produced by exportState().

Parameters:

index

Optional index, potentially used to identify the node's position within a layer or network structure. Not used internally by the Node class itself.

infinityNorm

Adamax: Exponential moving infinity norm (was opt_u).

innovation

Unique historical marking (auto-increment) for evolutionary alignment.

innovationID

(sourceNodeId: number, targetNodeId: number) => number

Deterministic Cantor pairing function for a (sourceNodeId, targetNodeId) pair. Useful when you want a stable innovation id without relying on global mutable counters (e.g., for hashing or reproducible experiments).

NOTE: For large indices this can overflow 53-bit safe integer space; keep node indices reasonable.

Parameters:

Returns: Unique non-negative integer derived from the ordered pair.

input

(from: import("/home/runner/work/NeatapticTS/NeatapticTS/src/architecture/layer").default | import("/home/runner/work/NeatapticTS/NeatapticTS/src/architecture/group").default, method: any, weight: number | undefined) => any[]

Handles the connection logic when this layer is the target of a connection.

It connects the output of the from layer or group to this layer's primary input mechanism (which is often the output group itself, but depends on the layer type). This method is usually called by the connect method of the source layer/group.

Parameters:

Returns: An array containing the newly created connection objects.

isActivating

Internal flag to detect cycles during activation

isConnectedTo

(target: import("/home/runner/work/NeatapticTS/NeatapticTS/src/architecture/node").default) => boolean

Checks if this node is connected to another node.

Parameters:

Returns: True if connected, otherwise false.

isGroup

(obj: any) => boolean

Type guard to check if an object is likely a Group.

This is a duck-typing check based on the presence of expected properties (set method and nodes array). Used internally where layer.nodes might contain Group instances (e.g., in Memory layers).

Parameters:

Returns: true if the object has set and nodes properties matching a Group, false otherwise.

isProjectedBy

(node: import("/home/runner/work/NeatapticTS/NeatapticTS/src/architecture/node").default) => boolean

Checks if the given node has a direct outgoing connection to this node. Considers both regular incoming connections and the self-connection.

Parameters:

Returns: True if the given node projects to this node, false otherwise.

isProjectingTo

(node: import("/home/runner/work/NeatapticTS/NeatapticTS/src/architecture/node").default) => boolean

Checks if this node has a direct outgoing connection to the given node. Considers both regular outgoing connections and the self-connection.

Parameters:

Returns: True if this node projects to the target node, false otherwise.

layerNorm

(size: number) => import("/home/runner/work/NeatapticTS/NeatapticTS/src/architecture/layer").default

Creates a layer normalization layer. Applies layer normalization to the activations of the nodes in this layer during activation.

Parameters:

Returns: A new Layer instance configured as a layer normalization layer.

lookaheadShadowWeight

Lookahead: shadow (slow) weight parameter (was _la_shadowWeight).

lstm

(size: number) => import("/home/runner/work/NeatapticTS/NeatapticTS/src/architecture/layer").default

Creates a Long Short-Term Memory (LSTM) layer.

LSTMs are a type of recurrent neural network (RNN) cell capable of learning long-range dependencies. This implementation uses standard LSTM architecture with input, forget, and output gates, and a memory cell.

Parameters:

Returns: A new Layer instance configured as an LSTM layer.

lstm

(layerArgs: (number | { inputToOutput?: boolean | undefined; })[]) => import("/home/runner/work/NeatapticTS/NeatapticTS/src/architecture/network").default

Creates a Long Short-Term Memory (LSTM) network. LSTMs are a type of recurrent neural network (RNN) capable of learning long-range dependencies. This constructor uses Layer.lstm to create the core LSTM blocks.

Parameters:

Returns: The constructed LSTM network.

mask

A mask factor (typically 0 or 1) used for implementing dropout. If 0, the node's output is effectively silenced.

maxSecondMoment

AMSGrad: Maximum of past second moment (was opt_vhat).

memory

(size: number, memory: number) => import("/home/runner/work/NeatapticTS/NeatapticTS/src/architecture/layer").default

Creates a Memory layer, designed to hold state over a fixed number of time steps.

This layer consists of multiple groups (memory blocks), each holding the state from a previous time step. The input connects to the most recent block, and information propagates backward through the blocks. The layer's output concatenates the states of all memory blocks.

Parameters:

Returns: A new Layer instance configured as a Memory layer.

mutate

() => void

Applies mutations to the population based on the mutation rate and amount. Each genome is mutated using the selected mutation methods. Slightly increases the chance of ADD_CONN mutation for more connectivity.

mutate

(method: any) => void

Mutates the network's structure or parameters according to the specified method. This is a core operation for neuro-evolutionary algorithms (like NEAT). The method argument should be one of the mutation types defined in methods.mutation.

Parameters:

narx

(inputSize: number, hiddenLayers: number | number[], outputSize: number, previousInput: number, previousOutput: number) => import("/home/runner/work/NeatapticTS/NeatapticTS/src/architecture/network").default

Creates a Nonlinear AutoRegressive network with eXogenous inputs (NARX). NARX networks are recurrent networks often used for time series prediction. They predict the next value of a time series based on previous values of the series and previous values of external (exogenous) input series.

Parameters:

Returns: The constructed NARX network.

nodes

An array containing all the nodes (neurons or groups) that constitute this layer. The order of nodes might be relevant depending on the layer type and its connections.

noTraceActivate

(input: number[]) => number[]

Activates the network without calculating eligibility traces. This is a performance optimization for scenarios where backpropagation is not needed, such as during testing, evaluation, or deployment (inference).

Parameters:

Returns: An array of numerical values representing the activations of the network's output nodes.

noTraceActivate

(input: number | undefined) => number

Activates the node without calculating eligibility traces (xtrace). This is a performance optimization used during inference (when the network is just making predictions, not learning) as trace calculations are only needed for training.

Parameters:

Returns: The calculated activation value of the node.

old

The node's state from the previous activation cycle. Used for recurrent self-connections.

output

Represents the primary output group of nodes for this layer. This group is typically used when connecting this layer to another layer or group. It might be null if the layer is not yet fully constructed or is an input layer.

perceptron

(layers: number[]) => import("/home/runner/work/NeatapticTS/NeatapticTS/src/architecture/network").default

Creates a standard Multi-Layer Perceptron (MLP) network. An MLP consists of an input layer, one or more hidden layers, and an output layer, fully connected layer by layer.

Parameters:

Returns: The constructed MLP network.

plastic

Whether this connection participates in plastic adaptation (rate > 0).

plasticityRate

Per-connection plasticity / learning rate (0 means non-plastic). Setting >0 marks plastic flag.

previousDeltaBias

The change in bias applied in the previous training iteration. Used for calculating momentum.

previousDeltaWeight

Last applied delta weight (used by classic momentum).

propagate

(rate: number, momentum: number, update: boolean, target: number[], regularization: number, costDerivative: ((target: number, output: number) => number) | undefined) => void

Propagates the error backward through the network (backpropagation). Calculates the error gradient for each node and connection. If update is true, it adjusts the weights and biases based on the calculated gradients, learning rate, momentum, and optional L2 regularization.

The process starts from the output nodes and moves backward layer by layer (or topologically for recurrent nets).

Parameters:

propagate

(rate: number, momentum: number, update: boolean, regularization: number | { type: "L1" | "L2"; lambda: number; } | ((weight: number) => number), target: number | undefined) => void

Back-propagates the error signal through the node and calculates weight/bias updates.

This method implements the backpropagation algorithm, including:

  1. Calculating the node's error responsibility based on errors from subsequent nodes (projected error) and errors from connections it gates (gated error).
  2. Calculating the gradient for each incoming connection's weight using eligibility traces (xtrace).
  3. Calculating the change (delta) for weights and bias, incorporating:
    • Learning rate.
    • L1/L2/custom regularization.
    • Momentum (using Nesterov Accelerated Gradient - NAG).
  4. Optionally applying the calculated updates immediately or accumulating them for batch training.

Parameters:

propagate

(rate: number, momentum: number, target: number[] | undefined) => void

Propagates the error backward through all nodes in the layer.

This is a core step in the backpropagation algorithm used for training. If a target array is provided (typically for the output layer), it's used to calculate the initial error for each node. Otherwise, nodes calculate their error based on the error propagated from subsequent layers.

Parameters:

pruneToSparsity

(targetSparsity: number, method: "magnitude" | "snip") => void

Immediately prune connections to reach (or approach) a target sparsity fraction. Used by evolutionary pruning (generation-based) independent of training iteration schedule.

Parameters:

random

(input: number, hidden: number, output: number, options: { connections?: number | undefined; backconnections?: number | undefined; selfconnections?: number | undefined; gates?: number | undefined; }) => import("/home/runner/work/NeatapticTS/NeatapticTS/src/architecture/network").default

Creates a randomly structured network based on specified node counts and connection options.

This method allows for the generation of networks with a less rigid structure than MLPs. It initializes a network with input and output nodes and then iteratively adds hidden nodes and various types of connections (forward, backward, self) and gates using mutation methods. This approach is inspired by neuro-evolution techniques where network topology evolves.

Parameters:

Returns: The constructed network with a randomized topology.

rebuildConnections

(net: import("/home/runner/work/NeatapticTS/NeatapticTS/src/architecture/network").default) => void

Rebuilds the network's connections array from all per-node connections. This ensures that the network.connections array is consistent with the actual outgoing connections of all nodes. Useful after manual wiring or node manipulation.

Parameters:

Returns: Example usage: Network.rebuildConnections(net);

release

(conn: import("/home/runner/work/NeatapticTS/NeatapticTS/src/architecture/connection").default) => void

Return a Connection to the internal pool for later reuse. Do NOT use the instance again afterward unless re-acquired (treat as surrendered). Optimizer / trace fields are not scrubbed here (they're overwritten during acquire).

Parameters:

remove

(node: import("/home/runner/work/NeatapticTS/NeatapticTS/src/architecture/node").default) => void

Removes a node from the network. This involves:

  1. Disconnecting all incoming and outgoing connections associated with the node.
  2. Removing any self-connections.
  3. Removing the node from the nodes array.
  4. Attempting to reconnect the node's direct predecessors to its direct successors to maintain network flow, if possible and configured.
  5. Handling gates involving the removed node (ungating connections gated by this node, and potentially re-gating connections that were gated by other nodes onto the removed node's connections).

Parameters:

resetDropoutMasks

() => void

Resets all masks in the network to 1 (no dropout). Applies to both node-level and layer-level dropout. Should be called after training to ensure inference is unaffected by previous dropout.

resetInnovationCounter

(value: number) => void

Reset the monotonic auto-increment innovation counter (used for newly constructed / pooled instances). You normally only call this at the start of an experiment or when deserializing a full population.

Parameters:

resetNoveltyArchive

() => void

Reset the novelty archive (clear entries).

The novelty archive is used to keep representative behaviors for novelty search. Clearing it removes stored behaviors.

restoreRNGState

(state: any) => void

Restore a previously-snapshotted RNG state. This restores the internal seed but does not re-create the RNG function until next use.

Parameters:

sampleRandom

(count: number) => number[]

Produce count deterministic random samples using instance RNG.

secondMoment

Second raw moment estimate (Adam family) (was opt_v).

secondMomentum

Secondary momentum (Lion variant) (was opt_m2).

selectMutationMethod

(genome: import("/home/runner/work/NeatapticTS/NeatapticTS/src/architecture/network").default, rawReturnForTest: boolean) => any

Selects a mutation method for a given genome based on constraints. Ensures that the mutation respects the maximum nodes, connections, and gates.

Parameters:

Returns: The selected mutation method or null if no valid method is available.

serialize

() => any[]

Lightweight tuple serializer delegating to network.serialize.ts

set

(values: { bias?: number | undefined; squash?: any; }) => void

Sets specified properties (e.g., bias, squash function) for all nodes in the network. Useful for initializing or resetting node properties uniformly.

Parameters:

set

(values: { bias?: number | undefined; squash?: any; type?: string | undefined; }) => void

Configures properties for all nodes within the layer.

Allows batch setting of common node properties like bias, activation function (squash), or node type. If a node within the nodes array is actually a Group (e.g., in memory layers), the configuration is applied recursively to the nodes within that group.

Parameters:

setActivation

(fn: (x: number, derivate?: boolean | undefined) => number) => void

Sets a custom activation function for this node at runtime.

Parameters:

setStochasticDepth

(survival: number[]) => void

Configure stochastic depth with survival probabilities per hidden layer (length must match hidden layer count when using layered network).

snapshotRNGState

() => number | undefined

Return the current opaque RNG numeric state used by the instance. Useful for deterministic test replay and debugging.

sort

() => void

Sorts the population in descending order of fitness scores. Ensures that the fittest genomes are at the start of the population array.

spawnFromParent

(parent: import("/home/runner/work/NeatapticTS/NeatapticTS/src/architecture/network").default, mutateCount: number) => import("/home/runner/work/NeatapticTS/NeatapticTS/src/architecture/network").default

Spawn a new genome derived from a single parent while preserving Neat bookkeeping.

This helper performs a canonical "clone + slight mutation" workflow while keeping Neat's internal invariants intact. It is intended for callers that want a child genome derived from a single parent but do not want to perform the bookkeeping and registration steps manually. The function deliberately does NOT add the returned child to this.population so callers are free to inspect or further modify the child and then register it via addGenome() (or push it directly if they understand the consequences).

Behavior summary:

Important: the returned child is not registered in Neat.population — call addGenome(child, [parentId]) to insert it and keep telemetry/lineage consistent.

Parameters:

Returns: A new Network instance derived from parent. The child is unregistered.

squash

(x: number, derivate: boolean | undefined) => number

The activation function (squashing function) applied to the node's state. Maps the internal state to the node's output (activation).

Parameters:

Returns: The activation value or its derivative.

state

The internal state of the node (sum of weighted inputs + bias) before the activation function is applied.

test

(set: { input: number[]; output: number[]; }[], cost: any) => { error: number; time: number; }

Tests the network's performance on a given dataset. Calculates the average error over the dataset using a specified cost function. Uses noTraceActivate for efficiency as gradients are not needed. Handles dropout scaling if dropout was used during training.

Parameters:

Returns: An object containing the calculated average error over the dataset and the time taken for the test in milliseconds.

to

The target (post-synaptic) node receiving activation.

toJSON

() => any

Import a previously exported state bundle and rehydrate a Neat instance.

toJSON

() => object

Converts the network into a JSON object representation (latest standard). Includes formatVersion, and only serializes properties needed for full reconstruction. All references are by index. Excludes runtime-only properties (activation, state, traces).

Returns: A JSON-compatible object representing the network.

toJSON

() => { index: number | undefined; bias: number; type: string; squash: string | null; mask: number; }

Converts the node's essential properties to a JSON object for serialization. Does not include state, activation, error, or connection information, as these are typically transient or reconstructed separately.

Returns: A JSON representation of the node's configuration.

toJSON

() => { size: number; nodeIndices: (number | undefined)[]; connections: { in: number; out: number; self: number; }; }

Serializes the group into a JSON-compatible format, avoiding circular references. Only includes node indices and connection counts.

Returns: A JSON-compatible representation of the group.

toONNX

() => import("/home/runner/work/NeatapticTS/NeatapticTS/src/architecture/network/network.onnx").OnnxModel

Exports the network to ONNX format (JSON object, minimal MLP support). Only standard feedforward architectures and standard activations are supported. Gating, custom activations, and evolutionary features are ignored or replaced with Identity.

Returns: ONNX model as a JSON object.

totalDeltaBias

Accumulates changes in bias over a mini-batch during batch training. Reset after each weight update.

totalDeltaWeight

Accumulated (batched) delta weight awaiting an apply step.

type

The type of the node: 'input', 'hidden', or 'output'. Determines behavior (e.g., input nodes don't have biases modified typically, output nodes calculate error differently).

ungate

(connection: import("/home/runner/work/NeatapticTS/NeatapticTS/src/architecture/connection").default) => void

Removes the gate from a specified connection. The connection will no longer be modulated by its gater node. Removes the connection from the network's gates list.

Parameters:

ungate

(connections: import("/home/runner/work/NeatapticTS/NeatapticTS/src/architecture/connection").default | import("/home/runner/work/NeatapticTS/NeatapticTS/src/architecture/connection").default[]) => void

Removes this node's gating control over the specified connection(s). Resets the connection's gain to 1 and removes it from the connections.gated list.

Parameters:

weight

Scalar multiplier applied to the source activation (prior to gain modulation).

xtrace

Extended trace structure for modulatory / eligibility propagation algorithms. Parallel arrays for cache-friendly iteration.

Generated from source JSDoc • GitHub