@reicek/neataptic-ts 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/ISSUE_TEMPLATE/bug_report.md +33 -0
- package/.github/ISSUE_TEMPLATE/feature_request.md +27 -0
- package/.github/PULL_REQUEST_TEMPLATE.md +28 -0
- package/.github/workflows/ci.yml +41 -0
- package/.github/workflows/deploy-pages.yml +29 -0
- package/.github/workflows/manual_release_pipeline.yml +62 -0
- package/.github/workflows/publish.yml +85 -0
- package/.github/workflows/release_dispatch.yml +38 -0
- package/.travis.yml +5 -0
- package/CONTRIBUTING.md +92 -0
- package/LICENSE +24 -0
- package/ONNX_EXPORT.md +87 -0
- package/README.md +1173 -0
- package/RELEASE.md +54 -0
- package/dist-docs/package.json +1 -0
- package/dist-docs/scripts/generate-docs.d.ts +2 -0
- package/dist-docs/scripts/generate-docs.d.ts.map +1 -0
- package/dist-docs/scripts/generate-docs.js +536 -0
- package/dist-docs/scripts/generate-docs.js.map +1 -0
- package/dist-docs/scripts/render-docs-html.d.ts +2 -0
- package/dist-docs/scripts/render-docs-html.d.ts.map +1 -0
- package/dist-docs/scripts/render-docs-html.js +148 -0
- package/dist-docs/scripts/render-docs-html.js.map +1 -0
- package/docs/FOLDERS.md +14 -0
- package/docs/README.md +1173 -0
- package/docs/architecture/README.md +1391 -0
- package/docs/architecture/index.html +938 -0
- package/docs/architecture/network/README.md +1210 -0
- package/docs/architecture/network/index.html +908 -0
- package/docs/assets/ascii-maze.bundle.js +16542 -0
- package/docs/assets/ascii-maze.bundle.js.map +7 -0
- package/docs/index.html +1419 -0
- package/docs/methods/README.md +670 -0
- package/docs/methods/index.html +477 -0
- package/docs/multithreading/README.md +274 -0
- package/docs/multithreading/index.html +215 -0
- package/docs/multithreading/workers/README.md +23 -0
- package/docs/multithreading/workers/browser/README.md +39 -0
- package/docs/multithreading/workers/browser/index.html +70 -0
- package/docs/multithreading/workers/index.html +57 -0
- package/docs/multithreading/workers/node/README.md +33 -0
- package/docs/multithreading/workers/node/index.html +66 -0
- package/docs/neat/README.md +1284 -0
- package/docs/neat/index.html +906 -0
- package/docs/src/README.md +2659 -0
- package/docs/src/index.html +1579 -0
- package/jest.config.ts +32 -0
- package/package.json +99 -0
- package/plans/HyperMorphoNEAT.md +293 -0
- package/plans/ONNX_EXPORT_PLAN.md +46 -0
- package/scripts/generate-docs.ts +486 -0
- package/scripts/render-docs-html.ts +138 -0
- package/scripts/types.d.ts +2 -0
- package/src/README.md +2659 -0
- package/src/architecture/README.md +1391 -0
- package/src/architecture/activationArrayPool.ts +135 -0
- package/src/architecture/architect.ts +635 -0
- package/src/architecture/connection.ts +148 -0
- package/src/architecture/group.ts +406 -0
- package/src/architecture/layer.ts +804 -0
- package/src/architecture/network/README.md +1210 -0
- package/src/architecture/network/network.activate.ts +223 -0
- package/src/architecture/network/network.connect.ts +157 -0
- package/src/architecture/network/network.deterministic.ts +167 -0
- package/src/architecture/network/network.evolve.ts +426 -0
- package/src/architecture/network/network.gating.ts +186 -0
- package/src/architecture/network/network.genetic.ts +247 -0
- package/src/architecture/network/network.mutate.ts +624 -0
- package/src/architecture/network/network.onnx.ts +463 -0
- package/src/architecture/network/network.prune.ts +216 -0
- package/src/architecture/network/network.remove.ts +96 -0
- package/src/architecture/network/network.serialize.ts +309 -0
- package/src/architecture/network/network.slab.ts +262 -0
- package/src/architecture/network/network.standalone.ts +246 -0
- package/src/architecture/network/network.stats.ts +59 -0
- package/src/architecture/network/network.topology.ts +86 -0
- package/src/architecture/network/network.training.ts +1278 -0
- package/src/architecture/network.ts +1302 -0
- package/src/architecture/node.ts +1288 -0
- package/src/architecture/onnx.ts +3 -0
- package/src/config.ts +83 -0
- package/src/methods/README.md +670 -0
- package/src/methods/activation.ts +372 -0
- package/src/methods/connection.ts +31 -0
- package/src/methods/cost.ts +347 -0
- package/src/methods/crossover.ts +63 -0
- package/src/methods/gating.ts +43 -0
- package/src/methods/methods.ts +8 -0
- package/src/methods/mutation.ts +300 -0
- package/src/methods/rate.ts +257 -0
- package/src/methods/selection.ts +65 -0
- package/src/multithreading/README.md +274 -0
- package/src/multithreading/multi.ts +339 -0
- package/src/multithreading/workers/README.md +23 -0
- package/src/multithreading/workers/browser/README.md +39 -0
- package/src/multithreading/workers/browser/testworker.ts +99 -0
- package/src/multithreading/workers/node/README.md +33 -0
- package/src/multithreading/workers/node/testworker.ts +72 -0
- package/src/multithreading/workers/node/worker.ts +70 -0
- package/src/multithreading/workers/workers.ts +22 -0
- package/src/neat/README.md +1284 -0
- package/src/neat/neat.adaptive.ts +544 -0
- package/src/neat/neat.compat.ts +164 -0
- package/src/neat/neat.constants.ts +20 -0
- package/src/neat/neat.diversity.ts +217 -0
- package/src/neat/neat.evaluate.ts +328 -0
- package/src/neat/neat.evolve.ts +1026 -0
- package/src/neat/neat.export.ts +249 -0
- package/src/neat/neat.helpers.ts +235 -0
- package/src/neat/neat.lineage.ts +220 -0
- package/src/neat/neat.multiobjective.ts +260 -0
- package/src/neat/neat.mutation.ts +718 -0
- package/src/neat/neat.objectives.ts +157 -0
- package/src/neat/neat.pruning.ts +190 -0
- package/src/neat/neat.selection.ts +269 -0
- package/src/neat/neat.speciation.ts +460 -0
- package/src/neat/neat.species.ts +151 -0
- package/src/neat/neat.telemetry.exports.ts +469 -0
- package/src/neat/neat.telemetry.ts +933 -0
- package/src/neat/neat.types.ts +275 -0
- package/src/neat.ts +1042 -0
- package/src/neataptic.ts +10 -0
- package/test/architecture/activationArrayPool.capacity.test.ts +19 -0
- package/test/architecture/activationArrayPool.test.ts +46 -0
- package/test/architecture/connection.test.ts +290 -0
- package/test/architecture/group.test.ts +950 -0
- package/test/architecture/layer.test.ts +1535 -0
- package/test/architecture/network.pruning.test.ts +65 -0
- package/test/architecture/node.test.ts +1602 -0
- package/test/examples/asciiMaze/asciiMaze.e2e.test.ts +499 -0
- package/test/examples/asciiMaze/asciiMaze.ts +41 -0
- package/test/examples/asciiMaze/browser-entry.ts +164 -0
- package/test/examples/asciiMaze/browserLogger.ts +221 -0
- package/test/examples/asciiMaze/browserTerminalUtility.ts +48 -0
- package/test/examples/asciiMaze/colors.ts +119 -0
- package/test/examples/asciiMaze/dashboardManager.ts +968 -0
- package/test/examples/asciiMaze/evolutionEngine.ts +1248 -0
- package/test/examples/asciiMaze/fitness.ts +136 -0
- package/test/examples/asciiMaze/index.html +128 -0
- package/test/examples/asciiMaze/index.ts +26 -0
- package/test/examples/asciiMaze/interfaces.ts +235 -0
- package/test/examples/asciiMaze/mazeMovement.ts +996 -0
- package/test/examples/asciiMaze/mazeUtils.ts +278 -0
- package/test/examples/asciiMaze/mazeVision.ts +402 -0
- package/test/examples/asciiMaze/mazeVisualization.ts +585 -0
- package/test/examples/asciiMaze/mazes.ts +245 -0
- package/test/examples/asciiMaze/networkRefinement.ts +76 -0
- package/test/examples/asciiMaze/networkVisualization.ts +901 -0
- package/test/examples/asciiMaze/terminalUtility.ts +73 -0
- package/test/methods/activation.test.ts +1142 -0
- package/test/methods/connection.test.ts +146 -0
- package/test/methods/cost.test.ts +1123 -0
- package/test/methods/crossover.test.ts +202 -0
- package/test/methods/gating.test.ts +144 -0
- package/test/methods/mutation.test.ts +451 -0
- package/test/methods/optimizers.advanced.test.ts +80 -0
- package/test/methods/optimizers.behavior.test.ts +105 -0
- package/test/methods/optimizers.formula.test.ts +89 -0
- package/test/methods/rate.cosineWarmRestarts.test.ts +44 -0
- package/test/methods/rate.linearWarmupDecay.test.ts +41 -0
- package/test/methods/rate.reduceOnPlateau.test.ts +45 -0
- package/test/methods/rate.test.ts +684 -0
- package/test/methods/selection.test.ts +245 -0
- package/test/multithreading/activations.functions.test.ts +54 -0
- package/test/multithreading/multi.test.ts +290 -0
- package/test/multithreading/worker.node.process.test.ts +39 -0
- package/test/multithreading/workers.coverage.test.ts +36 -0
- package/test/multithreading/workers.dynamic.import.test.ts +8 -0
- package/test/neat/neat.adaptive.complexityBudget.test.ts +34 -0
- package/test/neat/neat.adaptive.criterion.complexity.test.ts +50 -0
- package/test/neat/neat.adaptive.mutation.strategy.test.ts +37 -0
- package/test/neat/neat.adaptive.operator.decay.test.ts +31 -0
- package/test/neat/neat.adaptive.phasedComplexity.test.ts +25 -0
- package/test/neat/neat.adaptive.pruning.test.ts +25 -0
- package/test/neat/neat.adaptive.targetSpecies.test.ts +43 -0
- package/test/neat/neat.additional.coverage.test.ts +126 -0
- package/test/neat/neat.advanced.enhancements.test.ts +85 -0
- package/test/neat/neat.advanced.test.ts +589 -0
- package/test/neat/neat.diversity.autocompat.test.ts +47 -0
- package/test/neat/neat.diversity.metrics.test.ts +21 -0
- package/test/neat/neat.diversity.stats.test.ts +44 -0
- package/test/neat/neat.enhancements.test.ts +79 -0
- package/test/neat/neat.entropy.ancestorAdaptive.test.ts +133 -0
- package/test/neat/neat.entropy.compat.csv.test.ts +108 -0
- package/test/neat/neat.evolution.pruning.test.ts +39 -0
- package/test/neat/neat.fastmode.autotune.test.ts +42 -0
- package/test/neat/neat.innovation.test.ts +134 -0
- package/test/neat/neat.lineage.antibreeding.test.ts +35 -0
- package/test/neat/neat.lineage.entropy.test.ts +56 -0
- package/test/neat/neat.lineage.inbreeding.test.ts +49 -0
- package/test/neat/neat.lineage.pressure.test.ts +29 -0
- package/test/neat/neat.multiobjective.adaptive.test.ts +57 -0
- package/test/neat/neat.multiobjective.dynamic.schedule.test.ts +46 -0
- package/test/neat/neat.multiobjective.dynamic.test.ts +31 -0
- package/test/neat/neat.multiobjective.fastsort.delegation.test.ts +51 -0
- package/test/neat/neat.multiobjective.prune.test.ts +39 -0
- package/test/neat/neat.multiobjective.test.ts +21 -0
- package/test/neat/neat.mutation.undefined.pool.test.ts +24 -0
- package/test/neat/neat.objective.events.test.ts +26 -0
- package/test/neat/neat.objective.importance.test.ts +21 -0
- package/test/neat/neat.objective.lifetimes.test.ts +33 -0
- package/test/neat/neat.offspring.allocation.test.ts +22 -0
- package/test/neat/neat.operator.bandit.test.ts +17 -0
- package/test/neat/neat.operator.phases.test.ts +38 -0
- package/test/neat/neat.pruneInactive.behavior.test.ts +54 -0
- package/test/neat/neat.reenable.adaptation.test.ts +18 -0
- package/test/neat/neat.rng.state.test.ts +22 -0
- package/test/neat/neat.spawn.add.test.ts +123 -0
- package/test/neat/neat.speciation.test.ts +96 -0
- package/test/neat/neat.species.allocation.telemetry.test.ts +26 -0
- package/test/neat/neat.species.history.csv.test.ts +24 -0
- package/test/neat/neat.telemetry.advanced.test.ts +226 -0
- package/test/neat/neat.telemetry.csv.lineage.test.ts +19 -0
- package/test/neat/neat.telemetry.parity.test.ts +42 -0
- package/test/neat/neat.telemetry.stream.test.ts +19 -0
- package/test/neat/neat.telemetry.test.ts +16 -0
- package/test/neat/neat.test.ts +422 -0
- package/test/neat/neat.utilities.test.ts +44 -0
- package/test/network/__suppress_console.ts +9 -0
- package/test/network/acyclic.topoorder.test.ts +17 -0
- package/test/network/checkpoint.metricshook.test.ts +36 -0
- package/test/network/error.handling.test.ts +581 -0
- package/test/network/evolution.test.ts +285 -0
- package/test/network/genetic.test.ts +208 -0
- package/test/network/learning.capability.test.ts +244 -0
- package/test/network/mutation.effects.test.ts +492 -0
- package/test/network/network.activate.test.ts +115 -0
- package/test/network/network.activateBatch.test.ts +30 -0
- package/test/network/network.deterministic.test.ts +64 -0
- package/test/network/network.evolve.branches.test.ts +75 -0
- package/test/network/network.evolve.multithread.branches.test.ts +83 -0
- package/test/network/network.evolve.test.ts +100 -0
- package/test/network/network.gating.removal.test.ts +93 -0
- package/test/network/network.mutate.additional.test.ts +145 -0
- package/test/network/network.mutate.edgecases.test.ts +101 -0
- package/test/network/network.mutate.test.ts +101 -0
- package/test/network/network.prune.earlyexit.test.ts +38 -0
- package/test/network/network.remove.errors.test.ts +45 -0
- package/test/network/network.slab.fallbacks.test.ts +22 -0
- package/test/network/network.stats.test.ts +45 -0
- package/test/network/network.training.advanced.test.ts +149 -0
- package/test/network/network.training.basic.test.ts +228 -0
- package/test/network/network.training.helpers.test.ts +183 -0
- package/test/network/onnx.export.test.ts +310 -0
- package/test/network/onnx.import.test.ts +129 -0
- package/test/network/pruning.topology.test.ts +282 -0
- package/test/network/regularization.determinism.test.ts +83 -0
- package/test/network/regularization.dropconnect.test.ts +17 -0
- package/test/network/regularization.dropconnect.validation.test.ts +18 -0
- package/test/network/regularization.stochasticdepth.test.ts +27 -0
- package/test/network/regularization.test.ts +843 -0
- package/test/network/regularization.weightnoise.test.ts +30 -0
- package/test/network/setupTests.ts +2 -0
- package/test/network/standalone.test.ts +332 -0
- package/test/network/structure.serialization.test.ts +660 -0
- package/test/training/training.determinism.mixed-precision.test.ts +134 -0
- package/test/training/training.earlystopping.test.ts +91 -0
- package/test/training/training.edge-cases.test.ts +91 -0
- package/test/training/training.extensions.test.ts +47 -0
- package/test/training/training.gradient.features.test.ts +110 -0
- package/test/training/training.gradient.refinements.test.ts +170 -0
- package/test/training/training.gradient.separate-bias.test.ts +41 -0
- package/test/training/training.optimizer.test.ts +48 -0
- package/test/training/training.plateau.smoothing.test.ts +58 -0
- package/test/training/training.smoothing.types.test.ts +174 -0
- package/test/training/training.train.options.coverage.test.ts +52 -0
- package/test/utils/console-helper.ts +76 -0
- package/test/utils/jest-setup.ts +60 -0
- package/test/utils/test-helpers.ts +175 -0
- package/tsconfig.docs.json +12 -0
- package/tsconfig.json +21 -0
- package/webpack.config.js +49 -0
|
@@ -0,0 +1,2659 @@
|
|
|
1
|
+
#
|
|
2
|
+
|
|
3
|
+
## config.ts
|
|
4
|
+
|
|
5
|
+
### config
|
|
6
|
+
|
|
7
|
+
### NeatapticConfig
|
|
8
|
+
|
|
9
|
+
Global NeatapticTS configuration contract & default instance.
|
|
10
|
+
|
|
11
|
+
WHY THIS EXISTS
|
|
12
|
+
--------------
|
|
13
|
+
A central `config` object offers a convenient, documented surface for end-users (and tests)
|
|
14
|
+
to tweak library behaviour without digging through scattered constants. Centralization also
|
|
15
|
+
lets us validate & evolve feature flags in a single place.
|
|
16
|
+
|
|
17
|
+
USAGE PATTERN
|
|
18
|
+
------------
|
|
19
|
+
import { config } from 'neataptic-ts';
|
|
20
|
+
config.warnings = true; // enable runtime warnings
|
|
21
|
+
config.deterministicChainMode = true // opt into deterministic deep path construction
|
|
22
|
+
|
|
23
|
+
Adjust BEFORE constructing networks / invoking evolutionary loops so that subsystems read
|
|
24
|
+
the intended values while initializing internal buffers / metadata.
|
|
25
|
+
|
|
26
|
+
DESIGN NOTES
|
|
27
|
+
------------
|
|
28
|
+
- We intentionally avoid setters / proxies to keep this a plain serializable object.
|
|
29
|
+
- Optional flags are conservative by default (disabled) to preserve legacy stochastic
|
|
30
|
+
behaviour unless a test or user explicitly opts in.
|
|
31
|
+
|
|
32
|
+
## neat.ts
|
|
33
|
+
|
|
34
|
+
### neat
|
|
35
|
+
|
|
36
|
+
### NeatOptions
|
|
37
|
+
|
|
38
|
+
### Options
|
|
39
|
+
|
|
40
|
+
Configuration options for Neat evolutionary runs.
|
|
41
|
+
|
|
42
|
+
Each property is optional and the class applies sensible defaults when a
|
|
43
|
+
field is not provided. Options control population size, mutation rates,
|
|
44
|
+
compatibility coefficients, selection strategy and other behavioral knobs.
|
|
45
|
+
|
|
46
|
+
Example:
|
|
47
|
+
const opts: NeatOptions = { popsize: 100, mutationRate: 0.5 };
|
|
48
|
+
const neat = new Neat(3, 1, fitnessFn, opts);
|
|
49
|
+
|
|
50
|
+
Note: this type is intentionally permissive to support staged migration and
|
|
51
|
+
legacy callers; prefer providing a typed options object where possible.
|
|
52
|
+
|
|
53
|
+
### default
|
|
54
|
+
|
|
55
|
+
#### _adaptivePruneLevel
|
|
56
|
+
|
|
57
|
+
Adaptive prune level for complexity control (optional).
|
|
58
|
+
|
|
59
|
+
#### _applyFitnessSharing
|
|
60
|
+
|
|
61
|
+
`() => void`
|
|
62
|
+
|
|
63
|
+
Apply fitness sharing within species. When `sharingSigma` > 0 this uses a kernel-based
|
|
64
|
+
sharing; otherwise it falls back to classic per-species averaging. Sharing reduces
|
|
65
|
+
effective fitness for similar genomes to promote diversity.
|
|
66
|
+
|
|
67
|
+
#### _bestScoreLastGen
|
|
68
|
+
|
|
69
|
+
Best score observed in the last generation (used for improvement detection).
|
|
70
|
+
|
|
71
|
+
#### _compatIntegral
|
|
72
|
+
|
|
73
|
+
Integral accumulator used by adaptive compatibility controllers.
|
|
74
|
+
|
|
75
|
+
#### _compatSpeciesEMA
|
|
76
|
+
|
|
77
|
+
Exponential moving average for compatibility threshold (adaptive speciation).
|
|
78
|
+
|
|
79
|
+
#### _computeDiversityStats
|
|
80
|
+
|
|
81
|
+
`() => void`
|
|
82
|
+
|
|
83
|
+
Compute and cache diversity statistics used by telemetry & tests.
|
|
84
|
+
|
|
85
|
+
#### _connInnovations
|
|
86
|
+
|
|
87
|
+
Map of connection innovations keyed by a string identifier.
|
|
88
|
+
|
|
89
|
+
#### _diversityStats
|
|
90
|
+
|
|
91
|
+
Cached diversity metrics (computed lazily).
|
|
92
|
+
|
|
93
|
+
#### _getObjectives
|
|
94
|
+
|
|
95
|
+
`() => import("D:/code-practice/NeatapticTS/src/neat/neat.types").ObjectiveDescriptor[]`
|
|
96
|
+
|
|
97
|
+
Internal: return cached objective descriptors, building if stale.
|
|
98
|
+
|
|
99
|
+
#### _invalidateGenomeCaches
|
|
100
|
+
|
|
101
|
+
`(genome: any) => void`
|
|
102
|
+
|
|
103
|
+
Invalidate per-genome caches (compatibility distance, forward pass, etc.).
|
|
104
|
+
|
|
105
|
+
#### _lastAncestorUniqAdjustGen
|
|
106
|
+
|
|
107
|
+
Generation when ancestor uniqueness adjustment was last applied.
|
|
108
|
+
|
|
109
|
+
#### _lastEpsilonAdjustGen
|
|
110
|
+
|
|
111
|
+
Generation when epsilon compatibility was last adjusted.
|
|
112
|
+
|
|
113
|
+
#### _lastEvalDuration
|
|
114
|
+
|
|
115
|
+
Duration of the last evaluation run (ms).
|
|
116
|
+
|
|
117
|
+
#### _lastEvolveDuration
|
|
118
|
+
|
|
119
|
+
Duration of the last evolve run (ms).
|
|
120
|
+
|
|
121
|
+
#### _lastGlobalImproveGeneration
|
|
122
|
+
|
|
123
|
+
Generation index where the last global improvement occurred.
|
|
124
|
+
|
|
125
|
+
#### _lastInbreedingCount
|
|
126
|
+
|
|
127
|
+
Last observed count of inbreeding (used for detecting excessive cloning).
|
|
128
|
+
|
|
129
|
+
#### _lastOffspringAlloc
|
|
130
|
+
|
|
131
|
+
Last allocated offspring set (used by adaptive allocators).
|
|
132
|
+
|
|
133
|
+
#### _lineageEnabled
|
|
134
|
+
|
|
135
|
+
Whether lineage metadata should be recorded on genomes.
|
|
136
|
+
|
|
137
|
+
#### _mcThreshold
|
|
138
|
+
|
|
139
|
+
Adaptive minimal criterion threshold (optional).
|
|
140
|
+
|
|
141
|
+
#### _nextGenomeId
|
|
142
|
+
|
|
143
|
+
Counter for assigning unique genome ids.
|
|
144
|
+
|
|
145
|
+
#### _nextGlobalInnovation
|
|
146
|
+
|
|
147
|
+
Counter for issuing global innovation numbers when explicit numbers are used.
|
|
148
|
+
|
|
149
|
+
#### _nodeSplitInnovations
|
|
150
|
+
|
|
151
|
+
Map of node-split innovations used to reuse innovation ids for node splits.
|
|
152
|
+
|
|
153
|
+
#### _noveltyArchive
|
|
154
|
+
|
|
155
|
+
Novelty archive used by novelty search (behavior representatives).
|
|
156
|
+
|
|
157
|
+
#### _objectiveAges
|
|
158
|
+
|
|
159
|
+
Map tracking ages for objectives by key.
|
|
160
|
+
|
|
161
|
+
#### _objectiveEvents
|
|
162
|
+
|
|
163
|
+
Queue of recent objective activation/deactivation events for telemetry.
|
|
164
|
+
|
|
165
|
+
#### _objectivesList
|
|
166
|
+
|
|
167
|
+
Cached list of registered objectives.
|
|
168
|
+
|
|
169
|
+
#### _objectiveStale
|
|
170
|
+
|
|
171
|
+
Map tracking stale counts for objectives by key.
|
|
172
|
+
|
|
173
|
+
#### _operatorStats
|
|
174
|
+
|
|
175
|
+
Operator statistics used by adaptive operator selection.
|
|
176
|
+
|
|
177
|
+
#### _paretoArchive
|
|
178
|
+
|
|
179
|
+
Archive of Pareto front metadata for multi-objective tracking.
|
|
180
|
+
|
|
181
|
+
#### _paretoObjectivesArchive
|
|
182
|
+
|
|
183
|
+
Archive storing Pareto objectives snapshots.
|
|
184
|
+
|
|
185
|
+
#### _pendingObjectiveAdds
|
|
186
|
+
|
|
187
|
+
Pending objective keys to add during safe phases.
|
|
188
|
+
|
|
189
|
+
#### _pendingObjectiveRemoves
|
|
190
|
+
|
|
191
|
+
Pending objective keys to remove during safe phases.
|
|
192
|
+
|
|
193
|
+
#### _phase
|
|
194
|
+
|
|
195
|
+
Optional phase marker for multi-stage experiments.
|
|
196
|
+
|
|
197
|
+
#### _prevInbreedingCount
|
|
198
|
+
|
|
199
|
+
Previous inbreeding count snapshot.
|
|
200
|
+
|
|
201
|
+
#### _prevSpeciesMembers
|
|
202
|
+
|
|
203
|
+
Map of species id -> set of member genome ids from previous generation.
|
|
204
|
+
|
|
205
|
+
#### _rng
|
|
206
|
+
|
|
207
|
+
Cached RNG function; created lazily and seeded from `_rngState` when used.
|
|
208
|
+
|
|
209
|
+
#### _rngState
|
|
210
|
+
|
|
211
|
+
Internal numeric state for the deterministic xorshift RNG when no user RNG
|
|
212
|
+
is provided. Stored as a 32-bit unsigned integer.
|
|
213
|
+
|
|
214
|
+
#### _sortSpeciesMembers
|
|
215
|
+
|
|
216
|
+
`(sp: { members: import("D:/code-practice/NeatapticTS/src/architecture/network").default[]; }) => void`
|
|
217
|
+
|
|
218
|
+
Sort members of a species in-place by descending score.
|
|
219
|
+
|
|
220
|
+
Parameters:
|
|
221
|
+
- `sp` - - Species object with `members` array.
|
|
222
|
+
|
|
223
|
+
#### _speciate
|
|
224
|
+
|
|
225
|
+
`() => void`
|
|
226
|
+
|
|
227
|
+
Assign genomes into species based on compatibility distance and maintain species structures.
|
|
228
|
+
This function creates new species for unassigned genomes and prunes empty species.
|
|
229
|
+
It also records species-level history used for telemetry and adaptive controllers.
|
|
230
|
+
|
|
231
|
+
#### _species
|
|
232
|
+
|
|
233
|
+
Array of current species (internal representation).
|
|
234
|
+
|
|
235
|
+
#### _speciesCreated
|
|
236
|
+
|
|
237
|
+
Map of speciesId -> creation generation for bookkeeping.
|
|
238
|
+
|
|
239
|
+
#### _speciesHistory
|
|
240
|
+
|
|
241
|
+
Time-series history of species stats (for exports/telemetry).
|
|
242
|
+
|
|
243
|
+
#### _speciesLastStats
|
|
244
|
+
|
|
245
|
+
Last recorded stats per species id.
|
|
246
|
+
|
|
247
|
+
#### _structuralEntropy
|
|
248
|
+
|
|
249
|
+
`(genome: import("D:/code-practice/NeatapticTS/src/architecture/network").default) => number`
|
|
250
|
+
|
|
251
|
+
Compatibility wrapper retained for tests that reference (neat as any)._structuralEntropy
|
|
252
|
+
|
|
253
|
+
#### _telemetry
|
|
254
|
+
|
|
255
|
+
Telemetry buffer storing diagnostic snapshots per generation.
|
|
256
|
+
|
|
257
|
+
#### _updateSpeciesStagnation
|
|
258
|
+
|
|
259
|
+
`() => void`
|
|
260
|
+
|
|
261
|
+
Update species stagnation tracking and remove species that exceeded the allowed stagnation.
|
|
262
|
+
|
|
263
|
+
#### _warnIfNoBestGenome
|
|
264
|
+
|
|
265
|
+
`() => void`
|
|
266
|
+
|
|
267
|
+
Emit a standardized warning when evolution loop finds no valid best genome (test hook).
|
|
268
|
+
|
|
269
|
+
#### addGenome
|
|
270
|
+
|
|
271
|
+
`(genome: import("D:/code-practice/NeatapticTS/src/architecture/network").default, parents: number[] | undefined) => void`
|
|
272
|
+
|
|
273
|
+
Register an externally-created genome into the `Neat` population.
|
|
274
|
+
|
|
275
|
+
Use this method when code constructs or mutates a `Network` outside of the
|
|
276
|
+
usual reproduction pipeline and needs to insert it into `neat.population`
|
|
277
|
+
while preserving lineage, id assignment, and structural invariants. The
|
|
278
|
+
method performs best-effort safety actions and falls back to pushing the
|
|
279
|
+
genome even if invariant enforcement throws, which mirrors the forgiving
|
|
280
|
+
behavior used in dynamic population expansion.
|
|
281
|
+
|
|
282
|
+
Behavior summary:
|
|
283
|
+
- Clears the genome's `score` and assigns `_id` using Neat's counter.
|
|
284
|
+
- When lineage is enabled, attaches the provided `parents` array (copied)
|
|
285
|
+
and estimates `_depth` as `max(parent._depth) + 1` when parent ids are
|
|
286
|
+
resolvable from the current population.
|
|
287
|
+
- Enforces structural invariants (`ensureMinHiddenNodes` and
|
|
288
|
+
`ensureNoDeadEnds`) and invalidates caches via
|
|
289
|
+
`_invalidateGenomeCaches(genome)`.
|
|
290
|
+
- Pushes the genome into `this.population`.
|
|
291
|
+
|
|
292
|
+
Note: Because depth estimation requires parent objects to be discoverable
|
|
293
|
+
in `this.population`, callers that generate intermediate parent genomes
|
|
294
|
+
should register them via `addGenome` before relying on automatic depth
|
|
295
|
+
estimation for their children.
|
|
296
|
+
|
|
297
|
+
Parameters:
|
|
298
|
+
- `genome` - - The external `Network` to add.
|
|
299
|
+
- `parents` - - Optional array of parent ids to record on the genome.
|
|
300
|
+
|
|
301
|
+
#### clearObjectives
|
|
302
|
+
|
|
303
|
+
`() => void`
|
|
304
|
+
|
|
305
|
+
Register a custom objective for multi-objective optimization.
|
|
306
|
+
|
|
307
|
+
Educational context: multi-objective optimization lets you optimize for
|
|
308
|
+
multiple, potentially conflicting goals (e.g., maximize fitness while
|
|
309
|
+
minimizing complexity). Each objective is identified by a unique key and
|
|
310
|
+
an accessor function mapping a genome to a numeric score. Registering an
|
|
311
|
+
objective makes it visible to the internal MO pipeline and clears any
|
|
312
|
+
cached objective list so changes take effect immediately.
|
|
313
|
+
|
|
314
|
+
Parameters:
|
|
315
|
+
- `key` - Unique objective key.
|
|
316
|
+
- `direction` - 'min' or 'max' indicating optimization direction.
|
|
317
|
+
- `accessor` - Function mapping a genome to a numeric objective value.
|
|
318
|
+
|
|
319
|
+
#### clearParetoArchive
|
|
320
|
+
|
|
321
|
+
`() => void`
|
|
322
|
+
|
|
323
|
+
Clear the Pareto archive.
|
|
324
|
+
|
|
325
|
+
Removes any stored Pareto-front snapshots retained by the algorithm.
|
|
326
|
+
|
|
327
|
+
#### clearTelemetry
|
|
328
|
+
|
|
329
|
+
`() => void`
|
|
330
|
+
|
|
331
|
+
Export telemetry as CSV with flattened columns for common nested fields.
|
|
332
|
+
|
|
333
|
+
#### createPool
|
|
334
|
+
|
|
335
|
+
`(network: import("D:/code-practice/NeatapticTS/src/architecture/network").default | null) => void`
|
|
336
|
+
|
|
337
|
+
Create initial population pool. Delegates to helpers if present.
|
|
338
|
+
|
|
339
|
+
#### ensureMinHiddenNodes
|
|
340
|
+
|
|
341
|
+
`(network: import("D:/code-practice/NeatapticTS/src/architecture/network").default, multiplierOverride: number | undefined) => void`
|
|
342
|
+
|
|
343
|
+
Ensure a network has the minimum number of hidden nodes according to
|
|
344
|
+
configured policy. Delegates to migrated helper implementation.
|
|
345
|
+
|
|
346
|
+
Parameters:
|
|
347
|
+
- `network` - Network instance to adjust.
|
|
348
|
+
- `multiplierOverride` - Optional multiplier to override configured policy.
|
|
349
|
+
|
|
350
|
+
#### ensureNoDeadEnds
|
|
351
|
+
|
|
352
|
+
`(network: import("D:/code-practice/NeatapticTS/src/architecture/network").default) => void`
|
|
353
|
+
|
|
354
|
+
Delegate ensureNoDeadEnds to mutation module (added for backward compat).
|
|
355
|
+
|
|
356
|
+
#### evolve
|
|
357
|
+
|
|
358
|
+
`() => Promise<import("D:/code-practice/NeatapticTS/src/architecture/network").default>`
|
|
359
|
+
|
|
360
|
+
Evolves the population by selecting, mutating, and breeding genomes.
|
|
361
|
+
This method is delegated to `src/neat/neat.evolve.ts` during the migration.
|
|
362
|
+
|
|
363
|
+
#### export
|
|
364
|
+
|
|
365
|
+
`() => any[]`
|
|
366
|
+
|
|
367
|
+
Exports the current population as an array of JSON objects.
|
|
368
|
+
Useful for saving the state of the population for later use.
|
|
369
|
+
|
|
370
|
+
Returns: An array of JSON representations of the population.
|
|
371
|
+
|
|
372
|
+
#### exportParetoFrontJSONL
|
|
373
|
+
|
|
374
|
+
`(maxEntries: number) => string`
|
|
375
|
+
|
|
376
|
+
Export Pareto front archive as JSON Lines for external analysis.
|
|
377
|
+
|
|
378
|
+
Each line is a JSON object representing one archived Pareto snapshot.
|
|
379
|
+
|
|
380
|
+
Parameters:
|
|
381
|
+
- `maxEntries` - Maximum number of entries to include (default: 100).
|
|
382
|
+
|
|
383
|
+
Returns: Newline-separated JSON objects.
|
|
384
|
+
|
|
385
|
+
#### exportRNGState
|
|
386
|
+
|
|
387
|
+
`() => number | undefined`
|
|
388
|
+
|
|
389
|
+
Export the current RNG state for external persistence or tests.
|
|
390
|
+
|
|
391
|
+
#### exportSpeciesHistoryCSV
|
|
392
|
+
|
|
393
|
+
`(maxEntries: number) => string`
|
|
394
|
+
|
|
395
|
+
Return an array of {id, parents} for the first `limit` genomes in population.
|
|
396
|
+
|
|
397
|
+
#### exportSpeciesHistoryJSONL
|
|
398
|
+
|
|
399
|
+
`(maxEntries: number) => string`
|
|
400
|
+
|
|
401
|
+
Export species history as JSON Lines for storage and analysis.
|
|
402
|
+
|
|
403
|
+
Each line is a JSON object containing a generation index and per-species
|
|
404
|
+
stats recorded at that generation. Useful for long-term tracking.
|
|
405
|
+
|
|
406
|
+
Parameters:
|
|
407
|
+
- `maxEntries` - Maximum history entries to include (default: 200).
|
|
408
|
+
|
|
409
|
+
Returns: Newline-separated JSON objects.
|
|
410
|
+
|
|
411
|
+
#### exportState
|
|
412
|
+
|
|
413
|
+
`() => any`
|
|
414
|
+
|
|
415
|
+
Convenience: export full evolutionary state (meta + population genomes).
|
|
416
|
+
Combines innovation registries and serialized genomes for easy persistence.
|
|
417
|
+
|
|
418
|
+
#### exportTelemetryCSV
|
|
419
|
+
|
|
420
|
+
`(maxEntries: number) => string`
|
|
421
|
+
|
|
422
|
+
Export recent telemetry entries as CSV.
|
|
423
|
+
|
|
424
|
+
The exporter attempts to flatten commonly-used nested fields (complexity,
|
|
425
|
+
perf, lineage) into columns. This is a best-effort exporter intended for
|
|
426
|
+
human inspection and simple ingestion.
|
|
427
|
+
|
|
428
|
+
Parameters:
|
|
429
|
+
- `maxEntries` - Maximum number of recent telemetry entries to include.
|
|
430
|
+
|
|
431
|
+
Returns: CSV string (may be empty when no telemetry present).
|
|
432
|
+
|
|
433
|
+
#### exportTelemetryJSONL
|
|
434
|
+
|
|
435
|
+
`() => string`
|
|
436
|
+
|
|
437
|
+
Export telemetry as JSON Lines (one JSON object per line).
|
|
438
|
+
|
|
439
|
+
Useful for piping telemetry to external loggers or analysis tools.
|
|
440
|
+
|
|
441
|
+
Returns: A newline-separated string of JSON objects.
|
|
442
|
+
|
|
443
|
+
#### getAverage
|
|
444
|
+
|
|
445
|
+
`() => number`
|
|
446
|
+
|
|
447
|
+
Calculates the average fitness score of the population.
|
|
448
|
+
Ensures that the population is evaluated before calculating the average.
|
|
449
|
+
|
|
450
|
+
Returns: The average fitness score of the population.
|
|
451
|
+
|
|
452
|
+
#### getDiversityStats
|
|
453
|
+
|
|
454
|
+
`() => any`
|
|
455
|
+
|
|
456
|
+
Return the latest cached diversity statistics.
|
|
457
|
+
|
|
458
|
+
Educational context: diversity metrics summarize how genetically and
|
|
459
|
+
behaviorally spread the population is. They can include lineage depth,
|
|
460
|
+
pairwise genetic distances, and other aggregated measures used by
|
|
461
|
+
adaptive controllers, novelty search, and telemetry. This accessor returns
|
|
462
|
+
whatever precomputed diversity object the Neat instance holds (may be
|
|
463
|
+
undefined if not computed for the current generation).
|
|
464
|
+
|
|
465
|
+
Returns: Arbitrary diversity summary object or undefined.
|
|
466
|
+
|
|
467
|
+
#### getFittest
|
|
468
|
+
|
|
469
|
+
`() => import("D:/code-practice/NeatapticTS/src/architecture/network").default`
|
|
470
|
+
|
|
471
|
+
Retrieves the fittest genome from the population.
|
|
472
|
+
Ensures that the population is evaluated and sorted before returning the result.
|
|
473
|
+
|
|
474
|
+
Returns: The fittest genome in the population.
|
|
475
|
+
|
|
476
|
+
#### getLineageSnapshot
|
|
477
|
+
|
|
478
|
+
`(limit: number) => { id: number; parents: number[]; }[]`
|
|
479
|
+
|
|
480
|
+
Get recent objective add/remove events.
|
|
481
|
+
|
|
482
|
+
#### getMinimumHiddenSize
|
|
483
|
+
|
|
484
|
+
`(multiplierOverride: number | undefined) => number`
|
|
485
|
+
|
|
486
|
+
Minimum hidden size considering explicit minHidden or multiplier policy.
|
|
487
|
+
|
|
488
|
+
#### getMultiObjectiveMetrics
|
|
489
|
+
|
|
490
|
+
`() => { rank: number; crowding: number; score: number; nodes: number; connections: number; }[]`
|
|
491
|
+
|
|
492
|
+
Returns compact multi-objective metrics for each genome in the current
|
|
493
|
+
population. The metrics include Pareto rank and crowding distance (if
|
|
494
|
+
computed), along with simple size and score measures useful in
|
|
495
|
+
instructional contexts.
|
|
496
|
+
|
|
497
|
+
Returns: Array of per-genome MO metric objects.
|
|
498
|
+
|
|
499
|
+
#### getNoveltyArchiveSize
|
|
500
|
+
|
|
501
|
+
`() => number`
|
|
502
|
+
|
|
503
|
+
Returns the number of entries currently stored in the novelty archive.
|
|
504
|
+
|
|
505
|
+
Educational context: The novelty archive stores representative behaviors
|
|
506
|
+
used by behavior-based novelty search. Monitoring its size helps teach
|
|
507
|
+
how behavioral diversity accumulates over time and can be used to
|
|
508
|
+
throttle archive growth.
|
|
509
|
+
|
|
510
|
+
Returns: Number of archived behaviors.
|
|
511
|
+
|
|
512
|
+
#### getObjectiveKeys
|
|
513
|
+
|
|
514
|
+
`() => string[]`
|
|
515
|
+
|
|
516
|
+
Public helper returning just the objective keys (tests rely on).
|
|
517
|
+
|
|
518
|
+
#### getObjectives
|
|
519
|
+
|
|
520
|
+
`() => { key: string; direction: "max" | "min"; }[]`
|
|
521
|
+
|
|
522
|
+
Clear all collected telemetry entries.
|
|
523
|
+
|
|
524
|
+
#### getOffspring
|
|
525
|
+
|
|
526
|
+
`() => import("D:/code-practice/NeatapticTS/src/architecture/network").default`
|
|
527
|
+
|
|
528
|
+
Generates an offspring by crossing over two parent networks.
|
|
529
|
+
Uses the crossover method described in the Instinct algorithm.
|
|
530
|
+
|
|
531
|
+
Returns: A new network created from two parents.
|
|
532
|
+
|
|
533
|
+
#### getOperatorStats
|
|
534
|
+
|
|
535
|
+
`() => { name: string; success: number; attempts: number; }[]`
|
|
536
|
+
|
|
537
|
+
Returns a summary of mutation/operator statistics used by operator
|
|
538
|
+
adaptation and bandit selection.
|
|
539
|
+
|
|
540
|
+
Educational context: Operator statistics track how often mutation
|
|
541
|
+
operators are attempted and how often they succeed. These counters are
|
|
542
|
+
used by adaptation mechanisms to bias operator selection towards
|
|
543
|
+
successful operators.
|
|
544
|
+
|
|
545
|
+
Returns: Array of { name, success, attempts } objects.
|
|
546
|
+
|
|
547
|
+
#### getParent
|
|
548
|
+
|
|
549
|
+
`() => import("D:/code-practice/NeatapticTS/src/architecture/network").default`
|
|
550
|
+
|
|
551
|
+
Selects a parent genome for breeding based on the selection method.
|
|
552
|
+
Supports multiple selection strategies, including POWER, FITNESS_PROPORTIONATE, and TOURNAMENT.
|
|
553
|
+
|
|
554
|
+
Returns: The selected parent genome.
|
|
555
|
+
|
|
556
|
+
#### getParetoArchive
|
|
557
|
+
|
|
558
|
+
`(maxEntries: number) => any[]`
|
|
559
|
+
|
|
560
|
+
Get recent Pareto archive entries (meta information about archived fronts).
|
|
561
|
+
|
|
562
|
+
Educational context: when performing multi-objective search we may store
|
|
563
|
+
representative Pareto-front snapshots over time. This accessor returns the
|
|
564
|
+
most recent archive entries up to the provided limit.
|
|
565
|
+
|
|
566
|
+
Parameters:
|
|
567
|
+
- `maxEntries` - Maximum number of entries to return (default: 50).
|
|
568
|
+
|
|
569
|
+
Returns: Array of archived Pareto metadata entries.
|
|
570
|
+
|
|
571
|
+
#### getParetoFronts
|
|
572
|
+
|
|
573
|
+
`(maxFronts: number) => import("D:/code-practice/NeatapticTS/src/architecture/network").default[][]`
|
|
574
|
+
|
|
575
|
+
Export species history as CSV.
|
|
576
|
+
|
|
577
|
+
Produces rows for each recorded per-species stat entry within the
|
|
578
|
+
specified window. Useful for quick inspection or spreadsheet analysis.
|
|
579
|
+
|
|
580
|
+
Parameters:
|
|
581
|
+
- `maxEntries` - Maximum history entries to include (default: 200).
|
|
582
|
+
|
|
583
|
+
Returns: CSV string (may be empty).
|
|
584
|
+
|
|
585
|
+
#### getPerformanceStats
|
|
586
|
+
|
|
587
|
+
`() => { lastEvalMs: number | undefined; lastEvolveMs: number | undefined; }`
|
|
588
|
+
|
|
589
|
+
Return recent performance statistics (durations in milliseconds) for the
|
|
590
|
+
most recent evaluation and evolve operations.
|
|
591
|
+
|
|
592
|
+
Provides wall-clock timing useful for profiling and teaching how runtime
|
|
593
|
+
varies with network complexity or population settings.
|
|
594
|
+
|
|
595
|
+
Returns: Object with { lastEvalMs, lastEvolveMs }.
|
|
596
|
+
|
|
597
|
+
#### getSpeciesHistory
|
|
598
|
+
|
|
599
|
+
`() => import("D:/code-practice/NeatapticTS/src/neat/neat.types").SpeciesHistoryEntry[]`
|
|
600
|
+
|
|
601
|
+
Returns the historical species statistics recorded each generation.
|
|
602
|
+
|
|
603
|
+
Educational context: Species history captures per-generation snapshots
|
|
604
|
+
of species-level metrics (size, best score, last improvement) and is
|
|
605
|
+
useful for plotting trends, teaching about speciation dynamics, and
|
|
606
|
+
driving adaptive controllers.
|
|
607
|
+
|
|
608
|
+
The returned array contains entries with a `generation` index and a
|
|
609
|
+
`stats` array containing per-species summaries recorded at that
|
|
610
|
+
generation.
|
|
611
|
+
|
|
612
|
+
Returns: An array of generation-stamped species stat snapshots.
|
|
613
|
+
|
|
614
|
+
#### getSpeciesStats
|
|
615
|
+
|
|
616
|
+
`() => { id: number; size: number; bestScore: number; lastImproved: number; }[]`
|
|
617
|
+
|
|
618
|
+
Return a concise summary for each current species.
|
|
619
|
+
|
|
620
|
+
Educational context: In NEAT, populations are partitioned into species based
|
|
621
|
+
on genetic compatibility. Each species groups genomes that are similar so
|
|
622
|
+
selection and reproduction can preserve diversity between groups. This
|
|
623
|
+
accessor provides a lightweight view suitable for telemetry, visualization
|
|
624
|
+
and teaching examples without exposing full genome objects.
|
|
625
|
+
|
|
626
|
+
The returned array contains objects with these fields:
|
|
627
|
+
- id: numeric species identifier
|
|
628
|
+
- size: number of members currently assigned to the species
|
|
629
|
+
- bestScore: the best observed fitness score for the species
|
|
630
|
+
- lastImproved: generation index when the species last improved its best score
|
|
631
|
+
|
|
632
|
+
Notes for learners:
|
|
633
|
+
- Species sizes and lastImproved are typical signals used to detect
|
|
634
|
+
stagnation and apply protective or penalizing measures.
|
|
635
|
+
- This function intentionally avoids returning full member lists to
|
|
636
|
+
prevent accidental mutation of internal state; use `getSpeciesHistory`
|
|
637
|
+
for richer historical data.
|
|
638
|
+
|
|
639
|
+
Returns: An array of species summary objects.
|
|
640
|
+
|
|
641
|
+
#### getTelemetry
|
|
642
|
+
|
|
643
|
+
`() => any[]`
|
|
644
|
+
|
|
645
|
+
Return the internal telemetry buffer.
|
|
646
|
+
|
|
647
|
+
Telemetry entries are produced per-generation when telemetry is enabled
|
|
648
|
+
and include diagnostic metrics (diversity, performance, lineage, etc.).
|
|
649
|
+
This accessor returns the raw buffer for external inspection or export.
|
|
650
|
+
|
|
651
|
+
Returns: Array of telemetry snapshot objects.
|
|
652
|
+
|
|
653
|
+
#### import
|
|
654
|
+
|
|
655
|
+
`(json: any[]) => void`
|
|
656
|
+
|
|
657
|
+
Imports a population from an array of JSON objects.
|
|
658
|
+
Replaces the current population with the imported one.
|
|
659
|
+
|
|
660
|
+
Parameters:
|
|
661
|
+
- `json` - - An array of JSON objects representing the population.
|
|
662
|
+
|
|
663
|
+
#### importRNGState
|
|
664
|
+
|
|
665
|
+
`(state: any) => void`
|
|
666
|
+
|
|
667
|
+
Import an RNG state (alias for restore; kept for compatibility).
|
|
668
|
+
|
|
669
|
+
Parameters:
|
|
670
|
+
- `state` - Numeric RNG state.
|
|
671
|
+
|
|
672
|
+
#### importState
|
|
673
|
+
|
|
674
|
+
`(bundle: any, fitness: (n: import("D:/code-practice/NeatapticTS/src/architecture/network").default) => number) => import("D:/code-practice/NeatapticTS/src/neat").default`
|
|
675
|
+
|
|
676
|
+
Convenience: restore full evolutionary state previously produced by exportState().
|
|
677
|
+
|
|
678
|
+
Parameters:
|
|
679
|
+
- `bundle` - Object with shape { neat, population }
|
|
680
|
+
- `fitness` - Fitness function to attach
|
|
681
|
+
|
|
682
|
+
#### mutate
|
|
683
|
+
|
|
684
|
+
`() => void`
|
|
685
|
+
|
|
686
|
+
Applies mutations to the population based on the mutation rate and amount.
|
|
687
|
+
Each genome is mutated using the selected mutation methods.
|
|
688
|
+
Slightly increases the chance of ADD_CONN mutation for more connectivity.
|
|
689
|
+
|
|
690
|
+
#### resetNoveltyArchive
|
|
691
|
+
|
|
692
|
+
`() => void`
|
|
693
|
+
|
|
694
|
+
Reset the novelty archive (clear entries).
|
|
695
|
+
|
|
696
|
+
The novelty archive is used to keep representative behaviors for novelty
|
|
697
|
+
search. Clearing it removes stored behaviors.
|
|
698
|
+
|
|
699
|
+
#### restoreRNGState
|
|
700
|
+
|
|
701
|
+
`(state: any) => void`
|
|
702
|
+
|
|
703
|
+
Restore a previously-snapshotted RNG state. This restores the internal
|
|
704
|
+
seed but does not re-create the RNG function until next use.
|
|
705
|
+
|
|
706
|
+
Parameters:
|
|
707
|
+
- `state` - Opaque numeric RNG state produced by `snapshotRNGState()`.
|
|
708
|
+
|
|
709
|
+
#### sampleRandom
|
|
710
|
+
|
|
711
|
+
`(count: number) => number[]`
|
|
712
|
+
|
|
713
|
+
Produce `count` deterministic random samples using instance RNG.
|
|
714
|
+
|
|
715
|
+
#### selectMutationMethod
|
|
716
|
+
|
|
717
|
+
`(genome: import("D:/code-practice/NeatapticTS/src/architecture/network").default, rawReturnForTest: boolean) => any`
|
|
718
|
+
|
|
719
|
+
Selects a mutation method for a given genome based on constraints.
|
|
720
|
+
Ensures that the mutation respects the maximum nodes, connections, and gates.
|
|
721
|
+
|
|
722
|
+
Parameters:
|
|
723
|
+
- `genome` - - The genome to mutate.
|
|
724
|
+
|
|
725
|
+
Returns: The selected mutation method or null if no valid method is available.
|
|
726
|
+
|
|
727
|
+
#### snapshotRNGState
|
|
728
|
+
|
|
729
|
+
`() => number | undefined`
|
|
730
|
+
|
|
731
|
+
Return the current opaque RNG numeric state used by the instance.
|
|
732
|
+
Useful for deterministic test replay and debugging.
|
|
733
|
+
|
|
734
|
+
#### sort
|
|
735
|
+
|
|
736
|
+
`() => void`
|
|
737
|
+
|
|
738
|
+
Sorts the population in descending order of fitness scores.
|
|
739
|
+
Ensures that the fittest genomes are at the start of the population array.
|
|
740
|
+
|
|
741
|
+
#### spawnFromParent
|
|
742
|
+
|
|
743
|
+
`(parent: import("D:/code-practice/NeatapticTS/src/architecture/network").default, mutateCount: number) => import("D:/code-practice/NeatapticTS/src/architecture/network").default`
|
|
744
|
+
|
|
745
|
+
Spawn a new genome derived from a single parent while preserving Neat bookkeeping.
|
|
746
|
+
|
|
747
|
+
This helper performs a canonical "clone + slight mutation" workflow while
|
|
748
|
+
keeping `Neat`'s internal invariants intact. It is intended for callers that
|
|
749
|
+
want a child genome derived from a single parent but do not want to perform the
|
|
750
|
+
bookkeeping and registration steps manually. The function deliberately does NOT
|
|
751
|
+
add the returned child to `this.population` so callers are free to inspect or
|
|
752
|
+
further modify the child and then register it via `addGenome()` (or push it
|
|
753
|
+
directly if they understand the consequences).
|
|
754
|
+
|
|
755
|
+
Behavior summary:
|
|
756
|
+
- Clone the provided `parent` (`parent.clone()` when available, else JSON round-trip).
|
|
757
|
+
- Clear fitness/score on the child and assign a fresh unique `_id`.
|
|
758
|
+
- If lineage tracking is enabled, set `(child as any)._parents = [parent._id]`
|
|
759
|
+
and `(child as any)._depth = (parent._depth ?? 0) + 1`.
|
|
760
|
+
- Enforce structural invariants by calling `ensureMinHiddenNodes(child)` and
|
|
761
|
+
`ensureNoDeadEnds(child)` so the child is valid for subsequent mutation/evaluation.
|
|
762
|
+
- Apply `mutateCount` mutations selected via `selectMutationMethod` and driven by
|
|
763
|
+
the instance RNG (`_getRNG()`); mutation exceptions are caught and ignored to
|
|
764
|
+
preserve best-effort behavior during population seeding/expansion.
|
|
765
|
+
- Invalidate per-genome caches with `_invalidateGenomeCaches(child)` before return.
|
|
766
|
+
|
|
767
|
+
Important: the returned child is not registered in `Neat.population` — call
|
|
768
|
+
`addGenome(child, [parentId])` to insert it and keep telemetry/lineage consistent.
|
|
769
|
+
|
|
770
|
+
Parameters:
|
|
771
|
+
- `parent` - - Source genome to derive from. Must be a `Network` instance.
|
|
772
|
+
- `mutateCount` - - Number of mutation operations to apply to the spawned child (default: 1).
|
|
773
|
+
|
|
774
|
+
Returns: A new `Network` instance derived from `parent`. The child is unregistered.
|
|
775
|
+
|
|
776
|
+
#### toJSON
|
|
777
|
+
|
|
778
|
+
`() => any`
|
|
779
|
+
|
|
780
|
+
Import a previously exported state bundle and rehydrate a Neat instance.
|
|
781
|
+
|
|
782
|
+
## neataptic.ts
|
|
783
|
+
|
|
784
|
+
### neataptic
|
|
785
|
+
|
|
786
|
+
Represents a node (neuron) in a neural network graph.
|
|
787
|
+
|
|
788
|
+
Nodes are the fundamental processing units. They receive inputs, apply an activation function,
|
|
789
|
+
and produce an output. Nodes can be of type 'input', 'hidden', or 'output'. Hidden and output
|
|
790
|
+
nodes have biases and activation functions, which can be mutated during neuro-evolution.
|
|
791
|
+
This class also implements mechanisms for backpropagation, including support for momentum (NAG),
|
|
792
|
+
L2 regularization, dropout, and eligibility traces for recurrent connections.
|
|
793
|
+
|
|
794
|
+
### default
|
|
795
|
+
|
|
796
|
+
#### _activateCore
|
|
797
|
+
|
|
798
|
+
`(withTrace: boolean, input: number | undefined) => number`
|
|
799
|
+
|
|
800
|
+
Internal shared implementation for activate/noTraceActivate.
|
|
801
|
+
|
|
802
|
+
Parameters:
|
|
803
|
+
- `withTrace` - Whether to update eligibility traces.
|
|
804
|
+
- `input` - Optional externally supplied activation (bypasses weighted sum if provided).
|
|
805
|
+
|
|
806
|
+
#### _adaptivePruneLevel
|
|
807
|
+
|
|
808
|
+
Adaptive prune level for complexity control (optional).
|
|
809
|
+
|
|
810
|
+
#### _applyFitnessSharing
|
|
811
|
+
|
|
812
|
+
`() => void`
|
|
813
|
+
|
|
814
|
+
Apply fitness sharing within species. When `sharingSigma` > 0 this uses a kernel-based
|
|
815
|
+
sharing; otherwise it falls back to classic per-species averaging. Sharing reduces
|
|
816
|
+
effective fitness for similar genomes to promote diversity.
|
|
817
|
+
|
|
818
|
+
#### _applyGradientClipping
|
|
819
|
+
|
|
820
|
+
`(cfg: { mode: "norm" | "percentile" | "layerwiseNorm" | "layerwisePercentile"; maxNorm?: number | undefined; percentile?: number | undefined; }) => void`
|
|
821
|
+
|
|
822
|
+
Trains the network on a given dataset subset for one pass (epoch or batch).
|
|
823
|
+
Performs activation and backpropagation for each item in the set.
|
|
824
|
+
Updates weights based on batch size configuration.
|
|
825
|
+
|
|
826
|
+
Parameters:
|
|
827
|
+
- `` - - The training dataset subset (e.g., a batch or the full set for one epoch).
|
|
828
|
+
- `` - - The number of samples to process before updating weights.
|
|
829
|
+
- `` - - The learning rate to use for this training pass.
|
|
830
|
+
- `` - - The momentum factor to use.
|
|
831
|
+
- `` - - The regularization configuration (L1, L2, or custom function).
|
|
832
|
+
- `` - - The function used to calculate the error between target and output.
|
|
833
|
+
|
|
834
|
+
Returns: The average error calculated over the provided dataset subset.
|
|
835
|
+
|
|
836
|
+
#### _bestScoreLastGen
|
|
837
|
+
|
|
838
|
+
Best score observed in the last generation (used for improvement detection).
|
|
839
|
+
|
|
840
|
+
#### _compatIntegral
|
|
841
|
+
|
|
842
|
+
Integral accumulator used by adaptive compatibility controllers.
|
|
843
|
+
|
|
844
|
+
#### _compatSpeciesEMA
|
|
845
|
+
|
|
846
|
+
Exponential moving average for compatibility threshold (adaptive speciation).
|
|
847
|
+
|
|
848
|
+
#### _computeDiversityStats
|
|
849
|
+
|
|
850
|
+
`() => void`
|
|
851
|
+
|
|
852
|
+
Compute and cache diversity statistics used by telemetry & tests.
|
|
853
|
+
|
|
854
|
+
#### _connInnovations
|
|
855
|
+
|
|
856
|
+
Map of connection innovations keyed by a string identifier.
|
|
857
|
+
|
|
858
|
+
#### _diversityStats
|
|
859
|
+
|
|
860
|
+
Cached diversity metrics (computed lazily).
|
|
861
|
+
|
|
862
|
+
#### _getObjectives
|
|
863
|
+
|
|
864
|
+
`() => import("D:/code-practice/NeatapticTS/src/neat/neat.types").ObjectiveDescriptor[]`
|
|
865
|
+
|
|
866
|
+
Internal: return cached objective descriptors, building if stale.
|
|
867
|
+
|
|
868
|
+
#### _globalNodeIndex
|
|
869
|
+
|
|
870
|
+
Global index counter for assigning unique indices to nodes.
|
|
871
|
+
|
|
872
|
+
#### _invalidateGenomeCaches
|
|
873
|
+
|
|
874
|
+
`(genome: any) => void`
|
|
875
|
+
|
|
876
|
+
Invalidate per-genome caches (compatibility distance, forward pass, etc.).
|
|
877
|
+
|
|
878
|
+
#### _lastAncestorUniqAdjustGen
|
|
879
|
+
|
|
880
|
+
Generation when ancestor uniqueness adjustment was last applied.
|
|
881
|
+
|
|
882
|
+
#### _lastEpsilonAdjustGen
|
|
883
|
+
|
|
884
|
+
Generation when epsilon compatibility was last adjusted.
|
|
885
|
+
|
|
886
|
+
#### _lastEvalDuration
|
|
887
|
+
|
|
888
|
+
Duration of the last evaluation run (ms).
|
|
889
|
+
|
|
890
|
+
#### _lastEvolveDuration
|
|
891
|
+
|
|
892
|
+
Duration of the last evolve run (ms).
|
|
893
|
+
|
|
894
|
+
#### _lastGlobalImproveGeneration
|
|
895
|
+
|
|
896
|
+
Generation index where the last global improvement occurred.
|
|
897
|
+
|
|
898
|
+
#### _lastInbreedingCount
|
|
899
|
+
|
|
900
|
+
Last observed count of inbreeding (used for detecting excessive cloning).
|
|
901
|
+
|
|
902
|
+
#### _lastOffspringAlloc
|
|
903
|
+
|
|
904
|
+
Last allocated offspring set (used by adaptive allocators).
|
|
905
|
+
|
|
906
|
+
#### _lineageEnabled
|
|
907
|
+
|
|
908
|
+
Whether lineage metadata should be recorded on genomes.
|
|
909
|
+
|
|
910
|
+
#### _mcThreshold
|
|
911
|
+
|
|
912
|
+
Adaptive minimal criterion threshold (optional).
|
|
913
|
+
|
|
914
|
+
#### _nextGenomeId
|
|
915
|
+
|
|
916
|
+
Counter for assigning unique genome ids.
|
|
917
|
+
|
|
918
|
+
#### _nextGlobalInnovation
|
|
919
|
+
|
|
920
|
+
Counter for issuing global innovation numbers when explicit numbers are used.
|
|
921
|
+
|
|
922
|
+
#### _nodeSplitInnovations
|
|
923
|
+
|
|
924
|
+
Map of node-split innovations used to reuse innovation ids for node splits.
|
|
925
|
+
|
|
926
|
+
#### _noveltyArchive
|
|
927
|
+
|
|
928
|
+
Novelty archive used by novelty search (behavior representatives).
|
|
929
|
+
|
|
930
|
+
#### _objectiveAges
|
|
931
|
+
|
|
932
|
+
Map tracking ages for objectives by key.
|
|
933
|
+
|
|
934
|
+
#### _objectiveEvents
|
|
935
|
+
|
|
936
|
+
Queue of recent objective activation/deactivation events for telemetry.
|
|
937
|
+
|
|
938
|
+
#### _objectivesList
|
|
939
|
+
|
|
940
|
+
Cached list of registered objectives.
|
|
941
|
+
|
|
942
|
+
#### _objectiveStale
|
|
943
|
+
|
|
944
|
+
Map tracking stale counts for objectives by key.
|
|
945
|
+
|
|
946
|
+
#### _operatorStats
|
|
947
|
+
|
|
948
|
+
Operator statistics used by adaptive operator selection.
|
|
949
|
+
|
|
950
|
+
#### _paretoArchive
|
|
951
|
+
|
|
952
|
+
Archive of Pareto front metadata for multi-objective tracking.
|
|
953
|
+
|
|
954
|
+
#### _paretoObjectivesArchive
|
|
955
|
+
|
|
956
|
+
Archive storing Pareto objectives snapshots.
|
|
957
|
+
|
|
958
|
+
#### _pendingObjectiveAdds
|
|
959
|
+
|
|
960
|
+
Pending objective keys to add during safe phases.
|
|
961
|
+
|
|
962
|
+
#### _pendingObjectiveRemoves
|
|
963
|
+
|
|
964
|
+
Pending objective keys to remove during safe phases.
|
|
965
|
+
|
|
966
|
+
#### _phase
|
|
967
|
+
|
|
968
|
+
Optional phase marker for multi-stage experiments.
|
|
969
|
+
|
|
970
|
+
#### _prevInbreedingCount
|
|
971
|
+
|
|
972
|
+
Previous inbreeding count snapshot.
|
|
973
|
+
|
|
974
|
+
#### _prevSpeciesMembers
|
|
975
|
+
|
|
976
|
+
Map of species id -> set of member genome ids from previous generation.
|
|
977
|
+
|
|
978
|
+
#### _rng
|
|
979
|
+
|
|
980
|
+
Cached RNG function; created lazily and seeded from `_rngState` when used.
|
|
981
|
+
|
|
982
|
+
#### _rngState
|
|
983
|
+
|
|
984
|
+
Internal numeric state for the deterministic xorshift RNG when no user RNG
|
|
985
|
+
is provided. Stored as a 32-bit unsigned integer.
|
|
986
|
+
|
|
987
|
+
#### _safeUpdateWeight
|
|
988
|
+
|
|
989
|
+
`(connection: import("D:/code-practice/NeatapticTS/src/architecture/connection").default, delta: number) => void`
|
|
990
|
+
|
|
991
|
+
Internal helper to safely update a connection weight with clipping and NaN checks.
|
|
992
|
+
|
|
993
|
+
#### _sortSpeciesMembers
|
|
994
|
+
|
|
995
|
+
`(sp: { members: import("D:/code-practice/NeatapticTS/src/architecture/network").default[]; }) => void`
|
|
996
|
+
|
|
997
|
+
Sort members of a species in-place by descending score.
|
|
998
|
+
|
|
999
|
+
Parameters:
|
|
1000
|
+
- `sp` - - Species object with `members` array.
|
|
1001
|
+
|
|
1002
|
+
#### _speciate
|
|
1003
|
+
|
|
1004
|
+
`() => void`
|
|
1005
|
+
|
|
1006
|
+
Assign genomes into species based on compatibility distance and maintain species structures.
|
|
1007
|
+
This function creates new species for unassigned genomes and prunes empty species.
|
|
1008
|
+
It also records species-level history used for telemetry and adaptive controllers.
|
|
1009
|
+
|
|
1010
|
+
#### _species
|
|
1011
|
+
|
|
1012
|
+
Array of current species (internal representation).
|
|
1013
|
+
|
|
1014
|
+
#### _speciesCreated
|
|
1015
|
+
|
|
1016
|
+
Map of speciesId -> creation generation for bookkeeping.
|
|
1017
|
+
|
|
1018
|
+
#### _speciesHistory
|
|
1019
|
+
|
|
1020
|
+
Time-series history of species stats (for exports/telemetry).
|
|
1021
|
+
|
|
1022
|
+
#### _speciesLastStats
|
|
1023
|
+
|
|
1024
|
+
Last recorded stats per species id.
|
|
1025
|
+
|
|
1026
|
+
#### _structuralEntropy
|
|
1027
|
+
|
|
1028
|
+
`(genome: import("D:/code-practice/NeatapticTS/src/architecture/network").default) => number`
|
|
1029
|
+
|
|
1030
|
+
Compatibility wrapper retained for tests that reference (neat as any)._structuralEntropy
|
|
1031
|
+
|
|
1032
|
+
#### _telemetry
|
|
1033
|
+
|
|
1034
|
+
Telemetry buffer storing diagnostic snapshots per generation.
|
|
1035
|
+
|
|
1036
|
+
#### _updateSpeciesStagnation
|
|
1037
|
+
|
|
1038
|
+
`() => void`
|
|
1039
|
+
|
|
1040
|
+
Update species stagnation tracking and remove species that exceeded the allowed stagnation.
|
|
1041
|
+
|
|
1042
|
+
#### _warnIfNoBestGenome
|
|
1043
|
+
|
|
1044
|
+
`() => void`
|
|
1045
|
+
|
|
1046
|
+
Emit a standardized warning when evolution loop finds no valid best genome (test hook).
|
|
1047
|
+
|
|
1048
|
+
#### acquire
|
|
1049
|
+
|
|
1050
|
+
`(from: import("D:/code-practice/NeatapticTS/src/architecture/node").default, to: import("D:/code-practice/NeatapticTS/src/architecture/node").default, weight: number | undefined) => import("D:/code-practice/NeatapticTS/src/architecture/connection").default`
|
|
1051
|
+
|
|
1052
|
+
Acquire a Connection from the pool or construct a new one. Ensures fresh innovation id.
|
|
1053
|
+
|
|
1054
|
+
#### activate
|
|
1055
|
+
|
|
1056
|
+
`(input: number[], training: boolean, maxActivationDepth: number) => number[]`
|
|
1057
|
+
|
|
1058
|
+
Activates the network using the given input array.
|
|
1059
|
+
Performs a forward pass through the network, calculating the activation of each node.
|
|
1060
|
+
|
|
1061
|
+
Parameters:
|
|
1062
|
+
- `` - - An array of numerical values corresponding to the network's input nodes.
|
|
1063
|
+
- `` - - Flag indicating if the activation is part of a training process.
|
|
1064
|
+
- `` - - Maximum allowed activation depth to prevent infinite loops/cycles.
|
|
1065
|
+
|
|
1066
|
+
Returns: An array of numerical values representing the activations of the network's output nodes.
|
|
1067
|
+
|
|
1068
|
+
#### activate
|
|
1069
|
+
|
|
1070
|
+
`(input: number | undefined) => number`
|
|
1071
|
+
|
|
1072
|
+
Activates the node, calculating its output value based on inputs and state.
|
|
1073
|
+
This method also calculates eligibility traces (`xtrace`) used for training recurrent connections.
|
|
1074
|
+
|
|
1075
|
+
The activation process involves:
|
|
1076
|
+
1. Calculating the node's internal state (`this.state`) based on:
|
|
1077
|
+
- Incoming connections' weighted activations.
|
|
1078
|
+
- The recurrent self-connection's weighted state from the previous timestep (`this.old`).
|
|
1079
|
+
- The node's bias.
|
|
1080
|
+
2. Applying the activation function (`this.squash`) to the state to get the activation (`this.activation`).
|
|
1081
|
+
3. Applying the dropout mask (`this.mask`).
|
|
1082
|
+
4. Calculating the derivative of the activation function.
|
|
1083
|
+
5. Updating the gain of connections gated by this node.
|
|
1084
|
+
6. Calculating and updating eligibility traces for incoming connections.
|
|
1085
|
+
|
|
1086
|
+
Parameters:
|
|
1087
|
+
- `input` - Optional input value. If provided, sets the node's activation directly (used for input nodes).
|
|
1088
|
+
|
|
1089
|
+
Returns: The calculated activation value of the node.
|
|
1090
|
+
|
|
1091
|
+
#### activate
|
|
1092
|
+
|
|
1093
|
+
`(value: number[] | undefined, training: boolean) => number[]`
|
|
1094
|
+
|
|
1095
|
+
Activates all nodes within the layer, computing their output values.
|
|
1096
|
+
|
|
1097
|
+
If an input `value` array is provided, it's used as the initial activation
|
|
1098
|
+
for the corresponding nodes in the layer. Otherwise, nodes compute their
|
|
1099
|
+
activation based on their incoming connections.
|
|
1100
|
+
|
|
1101
|
+
During training, layer-level dropout is applied, masking all nodes in the layer together.
|
|
1102
|
+
During inference, all masks are set to 1.
|
|
1103
|
+
|
|
1104
|
+
Parameters:
|
|
1105
|
+
- `value` - - An optional array of activation values to set for the layer's nodes. The length must match the number of nodes.
|
|
1106
|
+
- `training` - - A boolean indicating whether the layer is in training mode. Defaults to false.
|
|
1107
|
+
|
|
1108
|
+
Returns: An array containing the activation value of each node in the layer after activation.
|
|
1109
|
+
|
|
1110
|
+
#### activate
|
|
1111
|
+
|
|
1112
|
+
`(value: number[] | undefined) => number[]`
|
|
1113
|
+
|
|
1114
|
+
Activates all nodes in the group. If input values are provided, they are assigned
|
|
1115
|
+
sequentially to the nodes before activation. Otherwise, nodes activate based on their
|
|
1116
|
+
existing states and incoming connections.
|
|
1117
|
+
|
|
1118
|
+
Parameters:
|
|
1119
|
+
- `` - - An optional array of input values. If provided, its length must match the number of nodes in the group.
|
|
1120
|
+
|
|
1121
|
+
Returns: An array containing the activation value of each node in the group, in order.
|
|
1122
|
+
|
|
1123
|
+
#### activateBatch
|
|
1124
|
+
|
|
1125
|
+
`(inputs: number[][], training: boolean) => number[][]`
|
|
1126
|
+
|
|
1127
|
+
Activate the network over a batch of input vectors (micro-batching).
|
|
1128
|
+
|
|
1129
|
+
Currently iterates sample-by-sample while reusing the network's internal
|
|
1130
|
+
fast-path allocations. Outputs are cloned number[] arrays for API
|
|
1131
|
+
compatibility. Future optimizations can vectorize this path.
|
|
1132
|
+
|
|
1133
|
+
Parameters:
|
|
1134
|
+
- `inputs` - Array of input vectors, each length must equal this.input
|
|
1135
|
+
- `training` - Whether to run with training-time stochastic features
|
|
1136
|
+
|
|
1137
|
+
Returns: Array of output vectors, each length equals this.output
|
|
1138
|
+
|
|
1139
|
+
#### activateRaw
|
|
1140
|
+
|
|
1141
|
+
`(input: number[], training: boolean, maxActivationDepth: number) => any`
|
|
1142
|
+
|
|
1143
|
+
Raw activation that can return a typed array when pooling is enabled (zero-copy).
|
|
1144
|
+
If reuseActivationArrays=false falls back to standard activate().
|
|
1145
|
+
|
|
1146
|
+
#### activation
|
|
1147
|
+
|
|
1148
|
+
The output value of the node after applying the activation function. This is the value transmitted to connected nodes.
|
|
1149
|
+
|
|
1150
|
+
#### addGenome
|
|
1151
|
+
|
|
1152
|
+
`(genome: import("D:/code-practice/NeatapticTS/src/architecture/network").default, parents: number[] | undefined) => void`
|
|
1153
|
+
|
|
1154
|
+
Register an externally-created genome into the `Neat` population.
|
|
1155
|
+
|
|
1156
|
+
Use this method when code constructs or mutates a `Network` outside of the
|
|
1157
|
+
usual reproduction pipeline and needs to insert it into `neat.population`
|
|
1158
|
+
while preserving lineage, id assignment, and structural invariants. The
|
|
1159
|
+
method performs best-effort safety actions and falls back to pushing the
|
|
1160
|
+
genome even if invariant enforcement throws, which mirrors the forgiving
|
|
1161
|
+
behavior used in dynamic population expansion.
|
|
1162
|
+
|
|
1163
|
+
Behavior summary:
|
|
1164
|
+
- Clears the genome's `score` and assigns `_id` using Neat's counter.
|
|
1165
|
+
- When lineage is enabled, attaches the provided `parents` array (copied)
|
|
1166
|
+
and estimates `_depth` as `max(parent._depth) + 1` when parent ids are
|
|
1167
|
+
resolvable from the current population.
|
|
1168
|
+
- Enforces structural invariants (`ensureMinHiddenNodes` and
|
|
1169
|
+
`ensureNoDeadEnds`) and invalidates caches via
|
|
1170
|
+
`_invalidateGenomeCaches(genome)`.
|
|
1171
|
+
- Pushes the genome into `this.population`.
|
|
1172
|
+
|
|
1173
|
+
Note: Because depth estimation requires parent objects to be discoverable
|
|
1174
|
+
in `this.population`, callers that generate intermediate parent genomes
|
|
1175
|
+
should register them via `addGenome` before relying on automatic depth
|
|
1176
|
+
estimation for their children.
|
|
1177
|
+
|
|
1178
|
+
Parameters:
|
|
1179
|
+
- `genome` - - The external `Network` to add.
|
|
1180
|
+
- `parents` - - Optional array of parent ids to record on the genome.
|
|
1181
|
+
|
|
1182
|
+
#### adjustRateForAccumulation
|
|
1183
|
+
|
|
1184
|
+
`(rate: number, accumulationSteps: number, reduction: "average" | "sum") => number`
|
|
1185
|
+
|
|
1186
|
+
Utility: adjust rate for accumulation mode (use result when switching to 'sum' to mimic 'average').
|
|
1187
|
+
|
|
1188
|
+
#### applyBatchUpdates
|
|
1189
|
+
|
|
1190
|
+
`(momentum: number) => void`
|
|
1191
|
+
|
|
1192
|
+
Applies accumulated batch updates to incoming and self connections and this node's bias.
|
|
1193
|
+
Uses momentum in a Nesterov-compatible way: currentDelta = accumulated + momentum * previousDelta.
|
|
1194
|
+
Resets accumulators after applying. Safe to call on any node type.
|
|
1195
|
+
|
|
1196
|
+
Parameters:
|
|
1197
|
+
- `momentum` - Momentum factor (0 to disable)
|
|
1198
|
+
|
|
1199
|
+
#### applyBatchUpdatesWithOptimizer
|
|
1200
|
+
|
|
1201
|
+
`(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`
|
|
1202
|
+
|
|
1203
|
+
Extended batch update supporting multiple optimizers.
|
|
1204
|
+
|
|
1205
|
+
Applies accumulated (batch) gradients stored in `totalDeltaWeight` / `totalDeltaBias` to the
|
|
1206
|
+
underlying weights and bias using the selected optimization algorithm. Supports both classic
|
|
1207
|
+
SGD (with Nesterov-style momentum via preceding propagate logic) and a collection of adaptive
|
|
1208
|
+
optimizers. After applying an update, gradient accumulators are reset to 0.
|
|
1209
|
+
|
|
1210
|
+
Supported optimizers (type):
|
|
1211
|
+
- 'sgd' : Standard gradient descent with optional momentum.
|
|
1212
|
+
- 'rmsprop' : Exponential moving average of squared gradients (cache) to normalize step.
|
|
1213
|
+
- 'adagrad' : Accumulate squared gradients; learning rate effectively decays per weight.
|
|
1214
|
+
- 'adam' : Bias‑corrected first (m) & second (v) moment estimates.
|
|
1215
|
+
- 'adamw' : Adam with decoupled weight decay (applied after adaptive step).
|
|
1216
|
+
- 'amsgrad' : Adam variant maintaining a maximum of past v (vhat) to enforce non‑increasing step size.
|
|
1217
|
+
- 'adamax' : Adam variant using the infinity norm (u) instead of second moment.
|
|
1218
|
+
- 'nadam' : Adam + Nesterov momentum style update (lookahead on first moment).
|
|
1219
|
+
- 'radam' : Rectified Adam – warms up variance by adaptively rectifying denominator when sample size small.
|
|
1220
|
+
- 'lion' : Uses sign of combination of two momentum buffers (beta1 & beta2) for update direction only.
|
|
1221
|
+
- 'adabelief': Adam-like but second moment on (g - m) (gradient surprise) for variance reduction.
|
|
1222
|
+
- 'lookahead': Wrapper; performs k fast optimizer steps then interpolates (alpha) towards a slow (shadow) weight.
|
|
1223
|
+
|
|
1224
|
+
Options:
|
|
1225
|
+
- momentum : (SGD) momentum factor (Nesterov handled in propagate when update=true).
|
|
1226
|
+
- beta1/beta2 : Exponential decay rates for first/second moments (Adam family, Lion, AdaBelief, etc.).
|
|
1227
|
+
- eps : Numerical stability epsilon added to denominator terms.
|
|
1228
|
+
- weightDecay : Decoupled weight decay (AdamW) or additionally applied after main step when adamw selected.
|
|
1229
|
+
- lrScale : Learning rate scalar already scheduled externally (passed as currentRate).
|
|
1230
|
+
- t : Global step (1-indexed) for bias correction / rectification.
|
|
1231
|
+
- baseType : Underlying optimizer for lookahead (not itself lookahead).
|
|
1232
|
+
- la_k : Lookahead synchronization interval (number of fast steps).
|
|
1233
|
+
- la_alpha : Interpolation factor towards slow (shadow) weights/bias at sync points.
|
|
1234
|
+
|
|
1235
|
+
Internal per-connection temp fields (created lazily):
|
|
1236
|
+
- opt_m / opt_v / opt_vhat / opt_u : Moment / variance / max variance / infinity norm caches.
|
|
1237
|
+
- opt_cache : Single accumulator (RMSProp / AdaGrad).
|
|
1238
|
+
- previousDeltaWeight : For classic SGD momentum.
|
|
1239
|
+
- _la_shadowWeight / _la_shadowBias : Lookahead shadow copies.
|
|
1240
|
+
|
|
1241
|
+
Safety: We clip extreme weight / bias magnitudes and guard against NaN/Infinity.
|
|
1242
|
+
|
|
1243
|
+
Parameters:
|
|
1244
|
+
- `opts` - Optimizer configuration (see above).
|
|
1245
|
+
|
|
1246
|
+
#### attention
|
|
1247
|
+
|
|
1248
|
+
`(size: number, heads: number) => import("D:/code-practice/NeatapticTS/src/architecture/layer").default`
|
|
1249
|
+
|
|
1250
|
+
Creates a multi-head self-attention layer (stub implementation).
|
|
1251
|
+
|
|
1252
|
+
Parameters:
|
|
1253
|
+
- `size` - - Number of output nodes.
|
|
1254
|
+
- `heads` - - Number of attention heads (default 1).
|
|
1255
|
+
|
|
1256
|
+
Returns: A new Layer instance representing an attention layer.
|
|
1257
|
+
|
|
1258
|
+
#### batchNorm
|
|
1259
|
+
|
|
1260
|
+
`(size: number) => import("D:/code-practice/NeatapticTS/src/architecture/layer").default`
|
|
1261
|
+
|
|
1262
|
+
Creates a batch normalization layer.
|
|
1263
|
+
Applies batch normalization to the activations of the nodes in this layer during activation.
|
|
1264
|
+
|
|
1265
|
+
Parameters:
|
|
1266
|
+
- `size` - - The number of nodes in this layer.
|
|
1267
|
+
|
|
1268
|
+
Returns: A new Layer instance configured as a batch normalization layer.
|
|
1269
|
+
|
|
1270
|
+
#### bias
|
|
1271
|
+
|
|
1272
|
+
The bias value of the node. Added to the weighted sum of inputs before activation.
|
|
1273
|
+
Input nodes typically have a bias of 0.
|
|
1274
|
+
|
|
1275
|
+
#### clear
|
|
1276
|
+
|
|
1277
|
+
`() => void`
|
|
1278
|
+
|
|
1279
|
+
Clears the internal state of all nodes in the network.
|
|
1280
|
+
Resets node activation, state, eligibility traces, and extended traces to their initial values (usually 0).
|
|
1281
|
+
This is typically done before processing a new input sequence in recurrent networks or between training epochs if desired.
|
|
1282
|
+
|
|
1283
|
+
#### clearObjectives
|
|
1284
|
+
|
|
1285
|
+
`() => void`
|
|
1286
|
+
|
|
1287
|
+
Register a custom objective for multi-objective optimization.
|
|
1288
|
+
|
|
1289
|
+
Educational context: multi-objective optimization lets you optimize for
|
|
1290
|
+
multiple, potentially conflicting goals (e.g., maximize fitness while
|
|
1291
|
+
minimizing complexity). Each objective is identified by a unique key and
|
|
1292
|
+
an accessor function mapping a genome to a numeric score. Registering an
|
|
1293
|
+
objective makes it visible to the internal MO pipeline and clears any
|
|
1294
|
+
cached objective list so changes take effect immediately.
|
|
1295
|
+
|
|
1296
|
+
Parameters:
|
|
1297
|
+
- `key` - Unique objective key.
|
|
1298
|
+
- `direction` - 'min' or 'max' indicating optimization direction.
|
|
1299
|
+
- `accessor` - Function mapping a genome to a numeric objective value.
|
|
1300
|
+
|
|
1301
|
+
#### clearParetoArchive
|
|
1302
|
+
|
|
1303
|
+
`() => void`
|
|
1304
|
+
|
|
1305
|
+
Clear the Pareto archive.
|
|
1306
|
+
|
|
1307
|
+
Removes any stored Pareto-front snapshots retained by the algorithm.
|
|
1308
|
+
|
|
1309
|
+
#### clearTelemetry
|
|
1310
|
+
|
|
1311
|
+
`() => void`
|
|
1312
|
+
|
|
1313
|
+
Export telemetry as CSV with flattened columns for common nested fields.
|
|
1314
|
+
|
|
1315
|
+
#### clone
|
|
1316
|
+
|
|
1317
|
+
`() => import("D:/code-practice/NeatapticTS/src/architecture/network").default`
|
|
1318
|
+
|
|
1319
|
+
Creates a deep copy of the network.
|
|
1320
|
+
|
|
1321
|
+
Returns: A new Network instance that is a clone of the current network.
|
|
1322
|
+
|
|
1323
|
+
#### connect
|
|
1324
|
+
|
|
1325
|
+
`(from: import("D:/code-practice/NeatapticTS/src/architecture/node").default, to: import("D:/code-practice/NeatapticTS/src/architecture/node").default, weight: number | undefined) => import("D:/code-practice/NeatapticTS/src/architecture/connection").default[]`
|
|
1326
|
+
|
|
1327
|
+
Creates a connection between two nodes in the network.
|
|
1328
|
+
Handles both regular connections and self-connections.
|
|
1329
|
+
Adds the new connection object(s) to the appropriate network list (`connections` or `selfconns`).
|
|
1330
|
+
|
|
1331
|
+
Parameters:
|
|
1332
|
+
- `` - - The source node of the connection.
|
|
1333
|
+
- `` - - The target node of the connection.
|
|
1334
|
+
- `` - - Optional weight for the connection. If not provided, a random weight is usually assigned by the underlying `Node.connect` method.
|
|
1335
|
+
|
|
1336
|
+
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.
|
|
1337
|
+
|
|
1338
|
+
#### connect
|
|
1339
|
+
|
|
1340
|
+
`(target: import("D:/code-practice/NeatapticTS/src/architecture/node").default | { nodes: import("D:/code-practice/NeatapticTS/src/architecture/node").default[]; }, weight: number | undefined) => import("D:/code-practice/NeatapticTS/src/architecture/connection").default[]`
|
|
1341
|
+
|
|
1342
|
+
Creates a connection from this node to a target node or all nodes in a group.
|
|
1343
|
+
|
|
1344
|
+
Parameters:
|
|
1345
|
+
- `target` - The target Node or a group object containing a `nodes` array.
|
|
1346
|
+
- `weight` - The weight for the new connection(s). If undefined, a default or random weight might be assigned by the Connection constructor (currently defaults to 0, consider changing).
|
|
1347
|
+
|
|
1348
|
+
Returns: An array containing the newly created Connection object(s).
|
|
1349
|
+
|
|
1350
|
+
#### connect
|
|
1351
|
+
|
|
1352
|
+
`(target: import("D:/code-practice/NeatapticTS/src/architecture/node").default | import("D:/code-practice/NeatapticTS/src/architecture/layer").default | import("D:/code-practice/NeatapticTS/src/architecture/group").default, method: any, weight: number | undefined) => any[]`
|
|
1353
|
+
|
|
1354
|
+
Connects this layer's output to a target component (Layer, Group, or Node).
|
|
1355
|
+
|
|
1356
|
+
This method delegates the connection logic primarily to the layer's `output` group
|
|
1357
|
+
or the target layer's `input` method. It establishes the forward connections
|
|
1358
|
+
necessary for signal propagation.
|
|
1359
|
+
|
|
1360
|
+
Parameters:
|
|
1361
|
+
- `target` - - The destination Layer, Group, or Node to connect to.
|
|
1362
|
+
- `method` - - The connection method (e.g., `ALL_TO_ALL`, `ONE_TO_ONE`) defining the connection pattern. See `methods.groupConnection`.
|
|
1363
|
+
- `weight` - - An optional fixed weight to assign to all created connections.
|
|
1364
|
+
- `` - - The destination entity (Group, Layer, or Node) to connect to.
|
|
1365
|
+
|
|
1366
|
+
Returns: An array containing the newly created connection objects.
|
|
1367
|
+
|
|
1368
|
+
#### connections
|
|
1369
|
+
|
|
1370
|
+
Stores incoming, outgoing, gated, and self-connections for this node.
|
|
1371
|
+
|
|
1372
|
+
#### construct
|
|
1373
|
+
|
|
1374
|
+
`(list: (import("D:/code-practice/NeatapticTS/src/architecture/node").default | import("D:/code-practice/NeatapticTS/src/architecture/layer").default | import("D:/code-practice/NeatapticTS/src/architecture/group").default)[]) => import("D:/code-practice/NeatapticTS/src/architecture/network").default`
|
|
1375
|
+
|
|
1376
|
+
Constructs a Network instance from an array of interconnected Layers, Groups, or Nodes.
|
|
1377
|
+
|
|
1378
|
+
This method processes the input list, extracts all unique nodes, identifies connections,
|
|
1379
|
+
gates, and self-connections, and determines the network's input and output sizes based
|
|
1380
|
+
on the `type` property ('input' or 'output') set on the nodes. It uses Sets internally
|
|
1381
|
+
for efficient handling of unique elements during construction.
|
|
1382
|
+
|
|
1383
|
+
Parameters:
|
|
1384
|
+
- `` - - An array containing the building blocks (Nodes, Layers, Groups) of the network, assumed to be already interconnected.
|
|
1385
|
+
|
|
1386
|
+
Returns: A Network object representing the constructed architecture.
|
|
1387
|
+
|
|
1388
|
+
#### conv1d
|
|
1389
|
+
|
|
1390
|
+
`(size: number, kernelSize: number, stride: number, padding: number) => import("D:/code-practice/NeatapticTS/src/architecture/layer").default`
|
|
1391
|
+
|
|
1392
|
+
Creates a 1D convolutional layer (stub implementation).
|
|
1393
|
+
|
|
1394
|
+
Parameters:
|
|
1395
|
+
- `size` - - Number of output nodes (filters).
|
|
1396
|
+
- `kernelSize` - - Size of the convolution kernel.
|
|
1397
|
+
- `stride` - - Stride of the convolution (default 1).
|
|
1398
|
+
- `padding` - - Padding (default 0).
|
|
1399
|
+
|
|
1400
|
+
Returns: A new Layer instance representing a 1D convolutional layer.
|
|
1401
|
+
|
|
1402
|
+
#### createMLP
|
|
1403
|
+
|
|
1404
|
+
`(inputCount: number, hiddenCounts: number[], outputCount: number) => import("D:/code-practice/NeatapticTS/src/architecture/network").default`
|
|
1405
|
+
|
|
1406
|
+
Creates a fully connected, strictly layered MLP network.
|
|
1407
|
+
|
|
1408
|
+
Parameters:
|
|
1409
|
+
- `` - - Number of input nodes
|
|
1410
|
+
- `` - - Array of hidden layer sizes (e.g. [2,3] for two hidden layers)
|
|
1411
|
+
- `` - - Number of output nodes
|
|
1412
|
+
|
|
1413
|
+
Returns: A new, fully connected, layered MLP
|
|
1414
|
+
|
|
1415
|
+
#### createPool
|
|
1416
|
+
|
|
1417
|
+
`(network: import("D:/code-practice/NeatapticTS/src/architecture/network").default | null) => void`
|
|
1418
|
+
|
|
1419
|
+
Create initial population pool. Delegates to helpers if present.
|
|
1420
|
+
|
|
1421
|
+
#### crossOver
|
|
1422
|
+
|
|
1423
|
+
`(network1: import("D:/code-practice/NeatapticTS/src/architecture/network").default, network2: import("D:/code-practice/NeatapticTS/src/architecture/network").default, equal: boolean) => import("D:/code-practice/NeatapticTS/src/architecture/network").default`
|
|
1424
|
+
|
|
1425
|
+
Creates a new offspring network by performing crossover between two parent networks.
|
|
1426
|
+
This method implements the crossover mechanism inspired by the NEAT algorithm and described
|
|
1427
|
+
in the Instinct paper, combining genes (nodes and connections) from both parents.
|
|
1428
|
+
Fitness scores can influence the inheritance process. Matching genes are inherited randomly,
|
|
1429
|
+
while disjoint/excess genes are typically inherited from the fitter parent (or randomly if fitness is equal or `equal` flag is set).
|
|
1430
|
+
|
|
1431
|
+
Parameters:
|
|
1432
|
+
- `` - - The first parent network.
|
|
1433
|
+
- `` - - The second parent network.
|
|
1434
|
+
- `` - - If true, disjoint and excess genes are inherited randomly regardless of fitness.
|
|
1435
|
+
If false (default), they are inherited from the fitter parent.
|
|
1436
|
+
|
|
1437
|
+
Returns: A new Network instance representing the offspring.
|
|
1438
|
+
|
|
1439
|
+
#### dense
|
|
1440
|
+
|
|
1441
|
+
`(size: number) => import("D:/code-practice/NeatapticTS/src/architecture/layer").default`
|
|
1442
|
+
|
|
1443
|
+
Creates a standard fully connected (dense) layer.
|
|
1444
|
+
|
|
1445
|
+
All nodes in the source layer/group will connect to all nodes in this layer
|
|
1446
|
+
when using the default `ALL_TO_ALL` connection method via `layer.input()`.
|
|
1447
|
+
|
|
1448
|
+
Parameters:
|
|
1449
|
+
- `size` - - The number of nodes (neurons) in this layer.
|
|
1450
|
+
|
|
1451
|
+
Returns: A new Layer instance configured as a dense layer.
|
|
1452
|
+
|
|
1453
|
+
#### derivative
|
|
1454
|
+
|
|
1455
|
+
The derivative of the activation function evaluated at the node's current state. Used in backpropagation.
|
|
1456
|
+
|
|
1457
|
+
#### deserialize
|
|
1458
|
+
|
|
1459
|
+
`(data: any[], inputSize: number | undefined, outputSize: number | undefined) => import("D:/code-practice/NeatapticTS/src/architecture/network").default`
|
|
1460
|
+
|
|
1461
|
+
Creates a Network instance from serialized data produced by `serialize()`.
|
|
1462
|
+
Reconstructs the network structure and state based on the provided arrays.
|
|
1463
|
+
|
|
1464
|
+
Parameters:
|
|
1465
|
+
- `` - - The serialized network data array, typically obtained from `network.serialize()`.
|
|
1466
|
+
Expected format: `[activations, states, squashNames, connectionData, inputSize, outputSize]`.
|
|
1467
|
+
- `` - - Optional input size override.
|
|
1468
|
+
- `` - - Optional output size override.
|
|
1469
|
+
|
|
1470
|
+
Returns: A new Network instance reconstructed from the serialized data.
|
|
1471
|
+
|
|
1472
|
+
#### disconnect
|
|
1473
|
+
|
|
1474
|
+
`(from: import("D:/code-practice/NeatapticTS/src/architecture/node").default, to: import("D:/code-practice/NeatapticTS/src/architecture/node").default) => void`
|
|
1475
|
+
|
|
1476
|
+
Disconnects two nodes, removing the connection between them.
|
|
1477
|
+
Handles both regular connections and self-connections.
|
|
1478
|
+
If the connection being removed was gated, it is also ungated.
|
|
1479
|
+
|
|
1480
|
+
Parameters:
|
|
1481
|
+
- `` - - The source node of the connection to remove.
|
|
1482
|
+
- `` - - The target node of the connection to remove.
|
|
1483
|
+
|
|
1484
|
+
#### disconnect
|
|
1485
|
+
|
|
1486
|
+
`(target: import("D:/code-practice/NeatapticTS/src/architecture/node").default, twosided: boolean) => void`
|
|
1487
|
+
|
|
1488
|
+
Removes the connection from this node to the target node.
|
|
1489
|
+
|
|
1490
|
+
Parameters:
|
|
1491
|
+
- `target` - The target node to disconnect from.
|
|
1492
|
+
- `twosided` - If true, also removes the connection from the target node back to this node (if it exists). Defaults to false.
|
|
1493
|
+
|
|
1494
|
+
#### disconnect
|
|
1495
|
+
|
|
1496
|
+
`(target: import("D:/code-practice/NeatapticTS/src/architecture/node").default | import("D:/code-practice/NeatapticTS/src/architecture/group").default, twosided: boolean | undefined) => void`
|
|
1497
|
+
|
|
1498
|
+
Removes connections between this layer's nodes and a target Group or Node.
|
|
1499
|
+
|
|
1500
|
+
Parameters:
|
|
1501
|
+
- `target` - - The Group or Node to disconnect from.
|
|
1502
|
+
- `twosided` - - If true, removes connections in both directions (from this layer to target, and from target to this layer). Defaults to false.
|
|
1503
|
+
|
|
1504
|
+
#### disconnect
|
|
1505
|
+
|
|
1506
|
+
`(target: import("D:/code-practice/NeatapticTS/src/architecture/node").default | import("D:/code-practice/NeatapticTS/src/architecture/group").default, twosided: boolean) => void`
|
|
1507
|
+
|
|
1508
|
+
Removes connections between nodes in this group and a target Group or Node.
|
|
1509
|
+
|
|
1510
|
+
Parameters:
|
|
1511
|
+
- `` - - The Group or Node to disconnect from.
|
|
1512
|
+
- `` - - If true, also removes connections originating from the `target` and ending in this group. Defaults to false (only removes connections from this group to the target).
|
|
1513
|
+
|
|
1514
|
+
#### dropout
|
|
1515
|
+
|
|
1516
|
+
Dropout rate for this layer (0 to 1). If > 0, all nodes in the layer are masked together during training.
|
|
1517
|
+
Layer-level dropout takes precedence over node-level dropout for nodes in this layer.
|
|
1518
|
+
|
|
1519
|
+
#### enableWeightNoise
|
|
1520
|
+
|
|
1521
|
+
`(stdDev: number | { perHiddenLayer: number[]; }) => void`
|
|
1522
|
+
|
|
1523
|
+
Enable weight noise. Provide a single std dev number or { perHiddenLayer: number[] }.
|
|
1524
|
+
|
|
1525
|
+
#### enforceMinimumHiddenLayerSizes
|
|
1526
|
+
|
|
1527
|
+
`(network: import("D:/code-practice/NeatapticTS/src/architecture/network").default) => import("D:/code-practice/NeatapticTS/src/architecture/network").default`
|
|
1528
|
+
|
|
1529
|
+
Enforces the minimum hidden layer size rule on a network.
|
|
1530
|
+
|
|
1531
|
+
This ensures that all hidden layers have at least min(input, output) + 1 nodes,
|
|
1532
|
+
which is a common heuristic to ensure networks have adequate representation capacity.
|
|
1533
|
+
|
|
1534
|
+
Parameters:
|
|
1535
|
+
- `` - - The network to enforce minimum hidden layer sizes on
|
|
1536
|
+
|
|
1537
|
+
Returns: The same network with properly sized hidden layers
|
|
1538
|
+
|
|
1539
|
+
#### ensureMinHiddenNodes
|
|
1540
|
+
|
|
1541
|
+
`(network: import("D:/code-practice/NeatapticTS/src/architecture/network").default, multiplierOverride: number | undefined) => void`
|
|
1542
|
+
|
|
1543
|
+
Ensure a network has the minimum number of hidden nodes according to
|
|
1544
|
+
configured policy. Delegates to migrated helper implementation.
|
|
1545
|
+
|
|
1546
|
+
Parameters:
|
|
1547
|
+
- `network` - Network instance to adjust.
|
|
1548
|
+
- `multiplierOverride` - Optional multiplier to override configured policy.
|
|
1549
|
+
|
|
1550
|
+
#### ensureNoDeadEnds
|
|
1551
|
+
|
|
1552
|
+
`(network: import("D:/code-practice/NeatapticTS/src/architecture/network").default) => void`
|
|
1553
|
+
|
|
1554
|
+
Delegate ensureNoDeadEnds to mutation module (added for backward compat).
|
|
1555
|
+
|
|
1556
|
+
#### error
|
|
1557
|
+
|
|
1558
|
+
Stores error values calculated during backpropagation.
|
|
1559
|
+
|
|
1560
|
+
#### evolve
|
|
1561
|
+
|
|
1562
|
+
`() => Promise<import("D:/code-practice/NeatapticTS/src/architecture/network").default>`
|
|
1563
|
+
|
|
1564
|
+
Evolves the population by selecting, mutating, and breeding genomes.
|
|
1565
|
+
This method is delegated to `src/neat/neat.evolve.ts` during the migration.
|
|
1566
|
+
|
|
1567
|
+
#### export
|
|
1568
|
+
|
|
1569
|
+
`() => any[]`
|
|
1570
|
+
|
|
1571
|
+
Exports the current population as an array of JSON objects.
|
|
1572
|
+
Useful for saving the state of the population for later use.
|
|
1573
|
+
|
|
1574
|
+
Returns: An array of JSON representations of the population.
|
|
1575
|
+
|
|
1576
|
+
#### exportParetoFrontJSONL
|
|
1577
|
+
|
|
1578
|
+
`(maxEntries: number) => string`
|
|
1579
|
+
|
|
1580
|
+
Export Pareto front archive as JSON Lines for external analysis.
|
|
1581
|
+
|
|
1582
|
+
Each line is a JSON object representing one archived Pareto snapshot.
|
|
1583
|
+
|
|
1584
|
+
Parameters:
|
|
1585
|
+
- `maxEntries` - Maximum number of entries to include (default: 100).
|
|
1586
|
+
|
|
1587
|
+
Returns: Newline-separated JSON objects.
|
|
1588
|
+
|
|
1589
|
+
#### exportRNGState
|
|
1590
|
+
|
|
1591
|
+
`() => number | undefined`
|
|
1592
|
+
|
|
1593
|
+
Export the current RNG state for external persistence or tests.
|
|
1594
|
+
|
|
1595
|
+
#### exportSpeciesHistoryCSV
|
|
1596
|
+
|
|
1597
|
+
`(maxEntries: number) => string`
|
|
1598
|
+
|
|
1599
|
+
Return an array of {id, parents} for the first `limit` genomes in population.
|
|
1600
|
+
|
|
1601
|
+
#### exportSpeciesHistoryJSONL
|
|
1602
|
+
|
|
1603
|
+
`(maxEntries: number) => string`
|
|
1604
|
+
|
|
1605
|
+
Export species history as JSON Lines for storage and analysis.
|
|
1606
|
+
|
|
1607
|
+
Each line is a JSON object containing a generation index and per-species
|
|
1608
|
+
stats recorded at that generation. Useful for long-term tracking.
|
|
1609
|
+
|
|
1610
|
+
Parameters:
|
|
1611
|
+
- `maxEntries` - Maximum history entries to include (default: 200).
|
|
1612
|
+
|
|
1613
|
+
Returns: Newline-separated JSON objects.
|
|
1614
|
+
|
|
1615
|
+
#### exportState
|
|
1616
|
+
|
|
1617
|
+
`() => any`
|
|
1618
|
+
|
|
1619
|
+
Convenience: export full evolutionary state (meta + population genomes).
|
|
1620
|
+
Combines innovation registries and serialized genomes for easy persistence.
|
|
1621
|
+
|
|
1622
|
+
#### exportTelemetryCSV
|
|
1623
|
+
|
|
1624
|
+
`(maxEntries: number) => string`
|
|
1625
|
+
|
|
1626
|
+
Export recent telemetry entries as CSV.
|
|
1627
|
+
|
|
1628
|
+
The exporter attempts to flatten commonly-used nested fields (complexity,
|
|
1629
|
+
perf, lineage) into columns. This is a best-effort exporter intended for
|
|
1630
|
+
human inspection and simple ingestion.
|
|
1631
|
+
|
|
1632
|
+
Parameters:
|
|
1633
|
+
- `maxEntries` - Maximum number of recent telemetry entries to include.
|
|
1634
|
+
|
|
1635
|
+
Returns: CSV string (may be empty when no telemetry present).
|
|
1636
|
+
|
|
1637
|
+
#### exportTelemetryJSONL
|
|
1638
|
+
|
|
1639
|
+
`() => string`
|
|
1640
|
+
|
|
1641
|
+
Export telemetry as JSON Lines (one JSON object per line).
|
|
1642
|
+
|
|
1643
|
+
Useful for piping telemetry to external loggers or analysis tools.
|
|
1644
|
+
|
|
1645
|
+
Returns: A newline-separated string of JSON objects.
|
|
1646
|
+
|
|
1647
|
+
#### fromJSON
|
|
1648
|
+
|
|
1649
|
+
`(json: any) => import("D:/code-practice/NeatapticTS/src/architecture/network").default`
|
|
1650
|
+
|
|
1651
|
+
Reconstructs a network from a JSON object (latest standard).
|
|
1652
|
+
Handles formatVersion, robust error handling, and index-based references.
|
|
1653
|
+
|
|
1654
|
+
Parameters:
|
|
1655
|
+
- `` - - The JSON object representing the network.
|
|
1656
|
+
|
|
1657
|
+
Returns: The reconstructed network.
|
|
1658
|
+
|
|
1659
|
+
#### fromJSON
|
|
1660
|
+
|
|
1661
|
+
`(json: { bias: number; type: string; squash: string; mask: number; }) => import("D:/code-practice/NeatapticTS/src/architecture/node").default`
|
|
1662
|
+
|
|
1663
|
+
Creates a Node instance from a JSON object.
|
|
1664
|
+
|
|
1665
|
+
Parameters:
|
|
1666
|
+
- `json` - The JSON object containing node configuration.
|
|
1667
|
+
|
|
1668
|
+
Returns: A new Node instance configured according to the JSON object.
|
|
1669
|
+
|
|
1670
|
+
#### gate
|
|
1671
|
+
|
|
1672
|
+
`(node: import("D:/code-practice/NeatapticTS/src/architecture/node").default, connection: import("D:/code-practice/NeatapticTS/src/architecture/connection").default) => void`
|
|
1673
|
+
|
|
1674
|
+
Gates a connection with a specified node.
|
|
1675
|
+
The activation of the `node` (gater) will modulate the weight of the `connection`.
|
|
1676
|
+
Adds the connection to the network's `gates` list.
|
|
1677
|
+
|
|
1678
|
+
Parameters:
|
|
1679
|
+
- `` - - The node that will act as the gater. Must be part of this network.
|
|
1680
|
+
- `` - - The connection to be gated.
|
|
1681
|
+
|
|
1682
|
+
#### gate
|
|
1683
|
+
|
|
1684
|
+
`(connections: import("D:/code-practice/NeatapticTS/src/architecture/connection").default | import("D:/code-practice/NeatapticTS/src/architecture/connection").default[]) => void`
|
|
1685
|
+
|
|
1686
|
+
Makes this node gate the provided connection(s).
|
|
1687
|
+
The connection's gain will be controlled by this node's activation value.
|
|
1688
|
+
|
|
1689
|
+
Parameters:
|
|
1690
|
+
- `connections` - A single Connection object or an array of Connection objects to be gated.
|
|
1691
|
+
|
|
1692
|
+
#### gate
|
|
1693
|
+
|
|
1694
|
+
`(connections: any[], method: any) => void`
|
|
1695
|
+
|
|
1696
|
+
Applies gating to a set of connections originating from this layer's output group.
|
|
1697
|
+
|
|
1698
|
+
Gating allows the activity of nodes in this layer (specifically, the output group)
|
|
1699
|
+
to modulate the flow of information through the specified `connections`.
|
|
1700
|
+
|
|
1701
|
+
Parameters:
|
|
1702
|
+
- `connections` - - An array of connection objects to be gated.
|
|
1703
|
+
- `method` - - The gating method (e.g., `INPUT`, `OUTPUT`, `SELF`) specifying how the gate influences the connection. See `methods.gating`.
|
|
1704
|
+
|
|
1705
|
+
#### gate
|
|
1706
|
+
|
|
1707
|
+
`(connections: any, method: any) => void`
|
|
1708
|
+
|
|
1709
|
+
Configures nodes within this group to act as gates for the specified connection(s).
|
|
1710
|
+
Gating allows the output of a node in this group to modulate the flow of signal through the gated connection.
|
|
1711
|
+
|
|
1712
|
+
Parameters:
|
|
1713
|
+
- `` - - A single connection object or an array of connection objects to be gated. Consider using a more specific type like `Connection | Connection[]`.
|
|
1714
|
+
- `` - - The gating mechanism to use (e.g., `methods.gating.INPUT`, `methods.gating.OUTPUT`, `methods.gating.SELF`). Specifies which part of the connection is influenced by the gater node.
|
|
1715
|
+
|
|
1716
|
+
#### gates
|
|
1717
|
+
|
|
1718
|
+
**Deprecated:** Use connections.gated; retained for legacy tests
|
|
1719
|
+
|
|
1720
|
+
#### geneId
|
|
1721
|
+
|
|
1722
|
+
Stable per-node gene identifier for NEAT innovation reuse
|
|
1723
|
+
|
|
1724
|
+
#### getAverage
|
|
1725
|
+
|
|
1726
|
+
`() => number`
|
|
1727
|
+
|
|
1728
|
+
Calculates the average fitness score of the population.
|
|
1729
|
+
Ensures that the population is evaluated before calculating the average.
|
|
1730
|
+
|
|
1731
|
+
Returns: The average fitness score of the population.
|
|
1732
|
+
|
|
1733
|
+
#### getDiversityStats
|
|
1734
|
+
|
|
1735
|
+
`() => any`
|
|
1736
|
+
|
|
1737
|
+
Return the latest cached diversity statistics.
|
|
1738
|
+
|
|
1739
|
+
Educational context: diversity metrics summarize how genetically and
|
|
1740
|
+
behaviorally spread the population is. They can include lineage depth,
|
|
1741
|
+
pairwise genetic distances, and other aggregated measures used by
|
|
1742
|
+
adaptive controllers, novelty search, and telemetry. This accessor returns
|
|
1743
|
+
whatever precomputed diversity object the Neat instance holds (may be
|
|
1744
|
+
undefined if not computed for the current generation).
|
|
1745
|
+
|
|
1746
|
+
Returns: Arbitrary diversity summary object or undefined.
|
|
1747
|
+
|
|
1748
|
+
#### getFittest
|
|
1749
|
+
|
|
1750
|
+
`() => import("D:/code-practice/NeatapticTS/src/architecture/network").default`
|
|
1751
|
+
|
|
1752
|
+
Retrieves the fittest genome from the population.
|
|
1753
|
+
Ensures that the population is evaluated and sorted before returning the result.
|
|
1754
|
+
|
|
1755
|
+
Returns: The fittest genome in the population.
|
|
1756
|
+
|
|
1757
|
+
#### getLastGradClipGroupCount
|
|
1758
|
+
|
|
1759
|
+
`() => number`
|
|
1760
|
+
|
|
1761
|
+
Returns last gradient clipping group count (0 if no clipping yet).
|
|
1762
|
+
|
|
1763
|
+
#### getLineageSnapshot
|
|
1764
|
+
|
|
1765
|
+
`(limit: number) => { id: number; parents: number[]; }[]`
|
|
1766
|
+
|
|
1767
|
+
Get recent objective add/remove events.
|
|
1768
|
+
|
|
1769
|
+
#### getLossScale
|
|
1770
|
+
|
|
1771
|
+
`() => number`
|
|
1772
|
+
|
|
1773
|
+
Returns current mixed precision loss scale (1 if disabled).
|
|
1774
|
+
|
|
1775
|
+
#### getMinimumHiddenSize
|
|
1776
|
+
|
|
1777
|
+
`(multiplierOverride: number | undefined) => number`
|
|
1778
|
+
|
|
1779
|
+
Minimum hidden size considering explicit minHidden or multiplier policy.
|
|
1780
|
+
|
|
1781
|
+
#### getMultiObjectiveMetrics
|
|
1782
|
+
|
|
1783
|
+
`() => { rank: number; crowding: number; score: number; nodes: number; connections: number; }[]`
|
|
1784
|
+
|
|
1785
|
+
Returns compact multi-objective metrics for each genome in the current
|
|
1786
|
+
population. The metrics include Pareto rank and crowding distance (if
|
|
1787
|
+
computed), along with simple size and score measures useful in
|
|
1788
|
+
instructional contexts.
|
|
1789
|
+
|
|
1790
|
+
Returns: Array of per-genome MO metric objects.
|
|
1791
|
+
|
|
1792
|
+
#### getNoveltyArchiveSize
|
|
1793
|
+
|
|
1794
|
+
`() => number`
|
|
1795
|
+
|
|
1796
|
+
Returns the number of entries currently stored in the novelty archive.
|
|
1797
|
+
|
|
1798
|
+
Educational context: The novelty archive stores representative behaviors
|
|
1799
|
+
used by behavior-based novelty search. Monitoring its size helps teach
|
|
1800
|
+
how behavioral diversity accumulates over time and can be used to
|
|
1801
|
+
throttle archive growth.
|
|
1802
|
+
|
|
1803
|
+
Returns: Number of archived behaviors.
|
|
1804
|
+
|
|
1805
|
+
#### getObjectiveKeys
|
|
1806
|
+
|
|
1807
|
+
`() => string[]`
|
|
1808
|
+
|
|
1809
|
+
Public helper returning just the objective keys (tests rely on).
|
|
1810
|
+
|
|
1811
|
+
#### getObjectives
|
|
1812
|
+
|
|
1813
|
+
`() => { key: string; direction: "max" | "min"; }[]`
|
|
1814
|
+
|
|
1815
|
+
Clear all collected telemetry entries.
|
|
1816
|
+
|
|
1817
|
+
#### getOffspring
|
|
1818
|
+
|
|
1819
|
+
`() => import("D:/code-practice/NeatapticTS/src/architecture/network").default`
|
|
1820
|
+
|
|
1821
|
+
Generates an offspring by crossing over two parent networks.
|
|
1822
|
+
Uses the crossover method described in the Instinct algorithm.
|
|
1823
|
+
|
|
1824
|
+
Returns: A new network created from two parents.
|
|
1825
|
+
|
|
1826
|
+
#### getOperatorStats
|
|
1827
|
+
|
|
1828
|
+
`() => { name: string; success: number; attempts: number; }[]`
|
|
1829
|
+
|
|
1830
|
+
Returns a summary of mutation/operator statistics used by operator
|
|
1831
|
+
adaptation and bandit selection.
|
|
1832
|
+
|
|
1833
|
+
Educational context: Operator statistics track how often mutation
|
|
1834
|
+
operators are attempted and how often they succeed. These counters are
|
|
1835
|
+
used by adaptation mechanisms to bias operator selection towards
|
|
1836
|
+
successful operators.
|
|
1837
|
+
|
|
1838
|
+
Returns: Array of { name, success, attempts } objects.
|
|
1839
|
+
|
|
1840
|
+
#### getParent
|
|
1841
|
+
|
|
1842
|
+
`() => import("D:/code-practice/NeatapticTS/src/architecture/network").default`
|
|
1843
|
+
|
|
1844
|
+
Selects a parent genome for breeding based on the selection method.
|
|
1845
|
+
Supports multiple selection strategies, including POWER, FITNESS_PROPORTIONATE, and TOURNAMENT.
|
|
1846
|
+
|
|
1847
|
+
Returns: The selected parent genome.
|
|
1848
|
+
|
|
1849
|
+
#### getParetoArchive
|
|
1850
|
+
|
|
1851
|
+
`(maxEntries: number) => any[]`
|
|
1852
|
+
|
|
1853
|
+
Get recent Pareto archive entries (meta information about archived fronts).
|
|
1854
|
+
|
|
1855
|
+
Educational context: when performing multi-objective search we may store
|
|
1856
|
+
representative Pareto-front snapshots over time. This accessor returns the
|
|
1857
|
+
most recent archive entries up to the provided limit.
|
|
1858
|
+
|
|
1859
|
+
Parameters:
|
|
1860
|
+
- `maxEntries` - Maximum number of entries to return (default: 50).
|
|
1861
|
+
|
|
1862
|
+
Returns: Array of archived Pareto metadata entries.
|
|
1863
|
+
|
|
1864
|
+
#### getParetoFronts
|
|
1865
|
+
|
|
1866
|
+
`(maxFronts: number) => import("D:/code-practice/NeatapticTS/src/architecture/network").default[][]`
|
|
1867
|
+
|
|
1868
|
+
Export species history as CSV.
|
|
1869
|
+
|
|
1870
|
+
Produces rows for each recorded per-species stat entry within the
|
|
1871
|
+
specified window. Useful for quick inspection or spreadsheet analysis.
|
|
1872
|
+
|
|
1873
|
+
Parameters:
|
|
1874
|
+
- `maxEntries` - Maximum history entries to include (default: 200).
|
|
1875
|
+
|
|
1876
|
+
Returns: CSV string (may be empty).
|
|
1877
|
+
|
|
1878
|
+
#### getPerformanceStats
|
|
1879
|
+
|
|
1880
|
+
`() => { lastEvalMs: number | undefined; lastEvolveMs: number | undefined; }`
|
|
1881
|
+
|
|
1882
|
+
Return recent performance statistics (durations in milliseconds) for the
|
|
1883
|
+
most recent evaluation and evolve operations.
|
|
1884
|
+
|
|
1885
|
+
Provides wall-clock timing useful for profiling and teaching how runtime
|
|
1886
|
+
varies with network complexity or population settings.
|
|
1887
|
+
|
|
1888
|
+
Returns: Object with { lastEvalMs, lastEvolveMs }.
|
|
1889
|
+
|
|
1890
|
+
#### getRawGradientNorm
|
|
1891
|
+
|
|
1892
|
+
`() => number`
|
|
1893
|
+
|
|
1894
|
+
Returns last recorded raw (pre-update) gradient L2 norm.
|
|
1895
|
+
|
|
1896
|
+
#### getSpeciesHistory
|
|
1897
|
+
|
|
1898
|
+
`() => import("D:/code-practice/NeatapticTS/src/neat/neat.types").SpeciesHistoryEntry[]`
|
|
1899
|
+
|
|
1900
|
+
Returns the historical species statistics recorded each generation.
|
|
1901
|
+
|
|
1902
|
+
Educational context: Species history captures per-generation snapshots
|
|
1903
|
+
of species-level metrics (size, best score, last improvement) and is
|
|
1904
|
+
useful for plotting trends, teaching about speciation dynamics, and
|
|
1905
|
+
driving adaptive controllers.
|
|
1906
|
+
|
|
1907
|
+
The returned array contains entries with a `generation` index and a
|
|
1908
|
+
`stats` array containing per-species summaries recorded at that
|
|
1909
|
+
generation.
|
|
1910
|
+
|
|
1911
|
+
Returns: An array of generation-stamped species stat snapshots.
|
|
1912
|
+
|
|
1913
|
+
#### getSpeciesStats
|
|
1914
|
+
|
|
1915
|
+
`() => { id: number; size: number; bestScore: number; lastImproved: number; }[]`
|
|
1916
|
+
|
|
1917
|
+
Return a concise summary for each current species.
|
|
1918
|
+
|
|
1919
|
+
Educational context: In NEAT, populations are partitioned into species based
|
|
1920
|
+
on genetic compatibility. Each species groups genomes that are similar so
|
|
1921
|
+
selection and reproduction can preserve diversity between groups. This
|
|
1922
|
+
accessor provides a lightweight view suitable for telemetry, visualization
|
|
1923
|
+
and teaching examples without exposing full genome objects.
|
|
1924
|
+
|
|
1925
|
+
The returned array contains objects with these fields:
|
|
1926
|
+
- id: numeric species identifier
|
|
1927
|
+
- size: number of members currently assigned to the species
|
|
1928
|
+
- bestScore: the best observed fitness score for the species
|
|
1929
|
+
- lastImproved: generation index when the species last improved its best score
|
|
1930
|
+
|
|
1931
|
+
Notes for learners:
|
|
1932
|
+
- Species sizes and lastImproved are typical signals used to detect
|
|
1933
|
+
stagnation and apply protective or penalizing measures.
|
|
1934
|
+
- This function intentionally avoids returning full member lists to
|
|
1935
|
+
prevent accidental mutation of internal state; use `getSpeciesHistory`
|
|
1936
|
+
for richer historical data.
|
|
1937
|
+
|
|
1938
|
+
Returns: An array of species summary objects.
|
|
1939
|
+
|
|
1940
|
+
#### getTelemetry
|
|
1941
|
+
|
|
1942
|
+
`() => any[]`
|
|
1943
|
+
|
|
1944
|
+
Return the internal telemetry buffer.
|
|
1945
|
+
|
|
1946
|
+
Telemetry entries are produced per-generation when telemetry is enabled
|
|
1947
|
+
and include diagnostic metrics (diversity, performance, lineage, etc.).
|
|
1948
|
+
This accessor returns the raw buffer for external inspection or export.
|
|
1949
|
+
|
|
1950
|
+
Returns: Array of telemetry snapshot objects.
|
|
1951
|
+
|
|
1952
|
+
#### getTrainingStats
|
|
1953
|
+
|
|
1954
|
+
`() => { gradNorm: number; gradNormRaw: number; lossScale: number; optimizerStep: number; mp: { good: number; bad: number; overflowCount: number; scaleUps: number; scaleDowns: number; lastOverflowStep: number; }; }`
|
|
1955
|
+
|
|
1956
|
+
Consolidated training stats snapshot.
|
|
1957
|
+
|
|
1958
|
+
#### gru
|
|
1959
|
+
|
|
1960
|
+
`(size: number) => import("D:/code-practice/NeatapticTS/src/architecture/layer").default`
|
|
1961
|
+
|
|
1962
|
+
Creates a Gated Recurrent Unit (GRU) layer.
|
|
1963
|
+
|
|
1964
|
+
GRUs are another type of recurrent neural network cell, often considered
|
|
1965
|
+
simpler than LSTMs but achieving similar performance on many tasks.
|
|
1966
|
+
They use an update gate and a reset gate to manage information flow.
|
|
1967
|
+
|
|
1968
|
+
Parameters:
|
|
1969
|
+
- `size` - - The number of GRU units (and nodes in each gate/cell group).
|
|
1970
|
+
|
|
1971
|
+
Returns: A new Layer instance configured as a GRU layer.
|
|
1972
|
+
|
|
1973
|
+
#### gru
|
|
1974
|
+
|
|
1975
|
+
`(layers: number[]) => import("D:/code-practice/NeatapticTS/src/architecture/network").default`
|
|
1976
|
+
|
|
1977
|
+
Creates a Gated Recurrent Unit (GRU) network.
|
|
1978
|
+
GRUs are another type of recurrent neural network, similar to LSTMs but often simpler.
|
|
1979
|
+
This constructor uses `Layer.gru` to create the core GRU blocks.
|
|
1980
|
+
|
|
1981
|
+
Parameters:
|
|
1982
|
+
- `` - - A sequence of numbers representing the size (number of units) of each layer: input layer size, hidden GRU layer sizes..., output layer size. Must include at least input, one hidden, and output layer sizes.
|
|
1983
|
+
|
|
1984
|
+
Returns: The constructed GRU network.
|
|
1985
|
+
|
|
1986
|
+
#### hopfield
|
|
1987
|
+
|
|
1988
|
+
`(size: number) => import("D:/code-practice/NeatapticTS/src/architecture/network").default`
|
|
1989
|
+
|
|
1990
|
+
Creates a Hopfield network.
|
|
1991
|
+
Hopfield networks are a form of recurrent neural network often used for associative memory tasks.
|
|
1992
|
+
This implementation creates a simple, fully connected structure.
|
|
1993
|
+
|
|
1994
|
+
Parameters:
|
|
1995
|
+
- `` - - The number of nodes in the network (input and output layers will have this size).
|
|
1996
|
+
|
|
1997
|
+
Returns: The constructed Hopfield network.
|
|
1998
|
+
|
|
1999
|
+
#### import
|
|
2000
|
+
|
|
2001
|
+
`(json: any[]) => void`
|
|
2002
|
+
|
|
2003
|
+
Imports a population from an array of JSON objects.
|
|
2004
|
+
Replaces the current population with the imported one.
|
|
2005
|
+
|
|
2006
|
+
Parameters:
|
|
2007
|
+
- `json` - - An array of JSON objects representing the population.
|
|
2008
|
+
|
|
2009
|
+
#### importRNGState
|
|
2010
|
+
|
|
2011
|
+
`(state: any) => void`
|
|
2012
|
+
|
|
2013
|
+
Import an RNG state (alias for restore; kept for compatibility).
|
|
2014
|
+
|
|
2015
|
+
Parameters:
|
|
2016
|
+
- `state` - Numeric RNG state.
|
|
2017
|
+
|
|
2018
|
+
#### importState
|
|
2019
|
+
|
|
2020
|
+
`(bundle: any, fitness: (n: import("D:/code-practice/NeatapticTS/src/architecture/network").default) => number) => import("D:/code-practice/NeatapticTS/src/neat").default`
|
|
2021
|
+
|
|
2022
|
+
Convenience: restore full evolutionary state previously produced by exportState().
|
|
2023
|
+
|
|
2024
|
+
Parameters:
|
|
2025
|
+
- `bundle` - Object with shape { neat, population }
|
|
2026
|
+
- `fitness` - Fitness function to attach
|
|
2027
|
+
|
|
2028
|
+
#### index
|
|
2029
|
+
|
|
2030
|
+
Optional index, potentially used to identify the node's position within a layer or network structure. Not used internally by the Node class itself.
|
|
2031
|
+
|
|
2032
|
+
#### innovationID
|
|
2033
|
+
|
|
2034
|
+
`(a: number, b: number) => number`
|
|
2035
|
+
|
|
2036
|
+
Generates a unique innovation ID for the connection.
|
|
2037
|
+
|
|
2038
|
+
The innovation ID is calculated using the Cantor pairing function, which maps two integers
|
|
2039
|
+
(representing the source and target nodes) to a unique integer.
|
|
2040
|
+
|
|
2041
|
+
Parameters:
|
|
2042
|
+
- `` - - The ID of the source node.
|
|
2043
|
+
- `` - - The ID of the target node.
|
|
2044
|
+
|
|
2045
|
+
Returns: The innovation ID based on the Cantor pairing function.
|
|
2046
|
+
|
|
2047
|
+
#### input
|
|
2048
|
+
|
|
2049
|
+
`(from: import("D:/code-practice/NeatapticTS/src/architecture/layer").default | import("D:/code-practice/NeatapticTS/src/architecture/group").default, method: any, weight: number | undefined) => any[]`
|
|
2050
|
+
|
|
2051
|
+
Handles the connection logic when this layer is the *target* of a connection.
|
|
2052
|
+
|
|
2053
|
+
It connects the output of the `from` layer or group to this layer's primary
|
|
2054
|
+
input mechanism (which is often the `output` group itself, but depends on the layer type).
|
|
2055
|
+
This method is usually called by the `connect` method of the source layer/group.
|
|
2056
|
+
|
|
2057
|
+
Parameters:
|
|
2058
|
+
- `from` - - The source Layer or Group connecting *to* this layer.
|
|
2059
|
+
- `method` - - The connection method (e.g., `ALL_TO_ALL`). Defaults to `ALL_TO_ALL`.
|
|
2060
|
+
- `weight` - - An optional fixed weight for the connections.
|
|
2061
|
+
|
|
2062
|
+
Returns: An array containing the newly created connection objects.
|
|
2063
|
+
|
|
2064
|
+
#### isActivating
|
|
2065
|
+
|
|
2066
|
+
Internal flag to detect cycles during activation
|
|
2067
|
+
|
|
2068
|
+
#### isConnectedTo
|
|
2069
|
+
|
|
2070
|
+
`(target: import("D:/code-practice/NeatapticTS/src/architecture/node").default) => boolean`
|
|
2071
|
+
|
|
2072
|
+
Checks if this node is connected to another node.
|
|
2073
|
+
|
|
2074
|
+
Parameters:
|
|
2075
|
+
- `target` - The target node to check the connection with.
|
|
2076
|
+
|
|
2077
|
+
Returns: True if connected, otherwise false.
|
|
2078
|
+
|
|
2079
|
+
#### isGroup
|
|
2080
|
+
|
|
2081
|
+
`(obj: any) => boolean`
|
|
2082
|
+
|
|
2083
|
+
Type guard to check if an object is likely a `Group`.
|
|
2084
|
+
|
|
2085
|
+
This is a duck-typing check based on the presence of expected properties
|
|
2086
|
+
(`set` method and `nodes` array). Used internally where `layer.nodes`
|
|
2087
|
+
might contain `Group` instances (e.g., in `Memory` layers).
|
|
2088
|
+
|
|
2089
|
+
Parameters:
|
|
2090
|
+
- `obj` - - The object to inspect.
|
|
2091
|
+
|
|
2092
|
+
Returns: `true` if the object has `set` and `nodes` properties matching a Group, `false` otherwise.
|
|
2093
|
+
|
|
2094
|
+
#### isProjectedBy
|
|
2095
|
+
|
|
2096
|
+
`(node: import("D:/code-practice/NeatapticTS/src/architecture/node").default) => boolean`
|
|
2097
|
+
|
|
2098
|
+
Checks if the given node has a direct outgoing connection to this node.
|
|
2099
|
+
Considers both regular incoming connections and the self-connection.
|
|
2100
|
+
|
|
2101
|
+
Parameters:
|
|
2102
|
+
- `node` - The potential source node.
|
|
2103
|
+
|
|
2104
|
+
Returns: True if the given node projects to this node, false otherwise.
|
|
2105
|
+
|
|
2106
|
+
#### isProjectingTo
|
|
2107
|
+
|
|
2108
|
+
`(node: import("D:/code-practice/NeatapticTS/src/architecture/node").default) => boolean`
|
|
2109
|
+
|
|
2110
|
+
Checks if this node has a direct outgoing connection to the given node.
|
|
2111
|
+
Considers both regular outgoing connections and the self-connection.
|
|
2112
|
+
|
|
2113
|
+
Parameters:
|
|
2114
|
+
- `node` - The potential target node.
|
|
2115
|
+
|
|
2116
|
+
Returns: True if this node projects to the target node, false otherwise.
|
|
2117
|
+
|
|
2118
|
+
#### layerNorm
|
|
2119
|
+
|
|
2120
|
+
`(size: number) => import("D:/code-practice/NeatapticTS/src/architecture/layer").default`
|
|
2121
|
+
|
|
2122
|
+
Creates a layer normalization layer.
|
|
2123
|
+
Applies layer normalization to the activations of the nodes in this layer during activation.
|
|
2124
|
+
|
|
2125
|
+
Parameters:
|
|
2126
|
+
- `size` - - The number of nodes in this layer.
|
|
2127
|
+
|
|
2128
|
+
Returns: A new Layer instance configured as a layer normalization layer.
|
|
2129
|
+
|
|
2130
|
+
#### lstm
|
|
2131
|
+
|
|
2132
|
+
`(size: number) => import("D:/code-practice/NeatapticTS/src/architecture/layer").default`
|
|
2133
|
+
|
|
2134
|
+
Creates a Long Short-Term Memory (LSTM) layer.
|
|
2135
|
+
|
|
2136
|
+
LSTMs are a type of recurrent neural network (RNN) cell capable of learning
|
|
2137
|
+
long-range dependencies. This implementation uses standard LSTM architecture
|
|
2138
|
+
with input, forget, and output gates, and a memory cell.
|
|
2139
|
+
|
|
2140
|
+
Parameters:
|
|
2141
|
+
- `size` - - The number of LSTM units (and nodes in each gate/cell group).
|
|
2142
|
+
|
|
2143
|
+
Returns: A new Layer instance configured as an LSTM layer.
|
|
2144
|
+
|
|
2145
|
+
#### lstm
|
|
2146
|
+
|
|
2147
|
+
`(layerArgs: (number | { inputToOutput?: boolean | undefined; })[]) => import("D:/code-practice/NeatapticTS/src/architecture/network").default`
|
|
2148
|
+
|
|
2149
|
+
Creates a Long Short-Term Memory (LSTM) network.
|
|
2150
|
+
LSTMs are a type of recurrent neural network (RNN) capable of learning long-range dependencies.
|
|
2151
|
+
This constructor uses `Layer.lstm` to create the core LSTM blocks.
|
|
2152
|
+
|
|
2153
|
+
Parameters:
|
|
2154
|
+
- `` - - A sequence of arguments defining the network structure:
|
|
2155
|
+
- Numbers represent the size (number of units) of each layer: input layer size, hidden LSTM layer sizes..., output layer size.
|
|
2156
|
+
- An optional configuration object can be provided as the last argument.
|
|
2157
|
+
- `` - - Configuration options (if passed as the last argument).
|
|
2158
|
+
|
|
2159
|
+
Returns: The constructed LSTM network.
|
|
2160
|
+
|
|
2161
|
+
#### mask
|
|
2162
|
+
|
|
2163
|
+
A mask factor (typically 0 or 1) used for implementing dropout. If 0, the node's output is effectively silenced.
|
|
2164
|
+
|
|
2165
|
+
#### memory
|
|
2166
|
+
|
|
2167
|
+
`(size: number, memory: number) => import("D:/code-practice/NeatapticTS/src/architecture/layer").default`
|
|
2168
|
+
|
|
2169
|
+
Creates a Memory layer, designed to hold state over a fixed number of time steps.
|
|
2170
|
+
|
|
2171
|
+
This layer consists of multiple groups (memory blocks), each holding the state
|
|
2172
|
+
from a previous time step. The input connects to the most recent block, and
|
|
2173
|
+
information propagates backward through the blocks. The layer's output
|
|
2174
|
+
concatenates the states of all memory blocks.
|
|
2175
|
+
|
|
2176
|
+
Parameters:
|
|
2177
|
+
- `size` - - The number of nodes in each memory block (must match the input size).
|
|
2178
|
+
- `memory` - - The number of time steps to remember (number of memory blocks).
|
|
2179
|
+
|
|
2180
|
+
Returns: A new Layer instance configured as a Memory layer.
|
|
2181
|
+
|
|
2182
|
+
#### mutate
|
|
2183
|
+
|
|
2184
|
+
`() => void`
|
|
2185
|
+
|
|
2186
|
+
Applies mutations to the population based on the mutation rate and amount.
|
|
2187
|
+
Each genome is mutated using the selected mutation methods.
|
|
2188
|
+
Slightly increases the chance of ADD_CONN mutation for more connectivity.
|
|
2189
|
+
|
|
2190
|
+
#### mutate
|
|
2191
|
+
|
|
2192
|
+
`(method: any) => void`
|
|
2193
|
+
|
|
2194
|
+
Mutates the network's structure or parameters according to the specified method.
|
|
2195
|
+
This is a core operation for neuro-evolutionary algorithms (like NEAT).
|
|
2196
|
+
The method argument should be one of the mutation types defined in `methods.mutation`.
|
|
2197
|
+
|
|
2198
|
+
Parameters:
|
|
2199
|
+
- `` - - The mutation method to apply (e.g., `mutation.ADD_NODE`, `mutation.MOD_WEIGHT`).
|
|
2200
|
+
Some methods might have associated parameters (e.g., `MOD_WEIGHT` uses `min`, `max`).
|
|
2201
|
+
- `method` - A mutation method object, typically from `methods.mutation`. It should define the type of mutation and its parameters (e.g., allowed functions, modification range).
|
|
2202
|
+
|
|
2203
|
+
#### narx
|
|
2204
|
+
|
|
2205
|
+
`(inputSize: number, hiddenLayers: number | number[], outputSize: number, previousInput: number, previousOutput: number) => import("D:/code-practice/NeatapticTS/src/architecture/network").default`
|
|
2206
|
+
|
|
2207
|
+
Creates a Nonlinear AutoRegressive network with eXogenous inputs (NARX).
|
|
2208
|
+
NARX networks are recurrent networks often used for time series prediction.
|
|
2209
|
+
They predict the next value of a time series based on previous values of the series
|
|
2210
|
+
and previous values of external (exogenous) input series.
|
|
2211
|
+
|
|
2212
|
+
Parameters:
|
|
2213
|
+
- `` - - The number of input nodes for the exogenous inputs at each time step.
|
|
2214
|
+
- `` - - The size of the hidden layer(s). Can be a single number for one hidden layer, or an array of numbers for multiple hidden layers. Use 0 or [] for no hidden layers.
|
|
2215
|
+
- `` - - The number of output nodes (predicting the time series).
|
|
2216
|
+
- `` - - The number of past time steps of the exogenous input to feed back into the network.
|
|
2217
|
+
- `` - - The number of past time steps of the network's own output to feed back into the network (autoregressive part).
|
|
2218
|
+
|
|
2219
|
+
Returns: The constructed NARX network.
|
|
2220
|
+
|
|
2221
|
+
#### nodes
|
|
2222
|
+
|
|
2223
|
+
An array containing all the nodes (neurons or groups) that constitute this layer.
|
|
2224
|
+
The order of nodes might be relevant depending on the layer type and its connections.
|
|
2225
|
+
|
|
2226
|
+
**Deprecated:** Placeholder kept for legacy structural algorithms. No longer populated.
|
|
2227
|
+
|
|
2228
|
+
#### noTraceActivate
|
|
2229
|
+
|
|
2230
|
+
`(input: number[]) => number[]`
|
|
2231
|
+
|
|
2232
|
+
Activates the network without calculating eligibility traces.
|
|
2233
|
+
This is a performance optimization for scenarios where backpropagation is not needed,
|
|
2234
|
+
such as during testing, evaluation, or deployment (inference).
|
|
2235
|
+
|
|
2236
|
+
Parameters:
|
|
2237
|
+
- `` - - An array of numerical values corresponding to the network's input nodes.
|
|
2238
|
+
The length must match the network's `input` size.
|
|
2239
|
+
|
|
2240
|
+
Returns: An array of numerical values representing the activations of the network's output nodes.
|
|
2241
|
+
|
|
2242
|
+
#### noTraceActivate
|
|
2243
|
+
|
|
2244
|
+
`(input: number | undefined) => number`
|
|
2245
|
+
|
|
2246
|
+
Activates the node without calculating eligibility traces (`xtrace`).
|
|
2247
|
+
This is a performance optimization used during inference (when the network
|
|
2248
|
+
is just making predictions, not learning) as trace calculations are only needed for training.
|
|
2249
|
+
|
|
2250
|
+
Parameters:
|
|
2251
|
+
- `input` - Optional input value. If provided, sets the node's activation directly (used for input nodes).
|
|
2252
|
+
|
|
2253
|
+
Returns: The calculated activation value of the node.
|
|
2254
|
+
|
|
2255
|
+
#### old
|
|
2256
|
+
|
|
2257
|
+
The node's state from the previous activation cycle. Used for recurrent self-connections.
|
|
2258
|
+
|
|
2259
|
+
#### output
|
|
2260
|
+
|
|
2261
|
+
Represents the primary output group of nodes for this layer.
|
|
2262
|
+
This group is typically used when connecting this layer *to* another layer or group.
|
|
2263
|
+
It might be null if the layer is not yet fully constructed or is an input layer.
|
|
2264
|
+
|
|
2265
|
+
#### perceptron
|
|
2266
|
+
|
|
2267
|
+
`(layers: number[]) => import("D:/code-practice/NeatapticTS/src/architecture/network").default`
|
|
2268
|
+
|
|
2269
|
+
Creates a standard Multi-Layer Perceptron (MLP) network.
|
|
2270
|
+
An MLP consists of an input layer, one or more hidden layers, and an output layer,
|
|
2271
|
+
fully connected layer by layer.
|
|
2272
|
+
|
|
2273
|
+
Parameters:
|
|
2274
|
+
- `` - - A sequence of numbers representing the size (number of nodes) of each layer, starting with the input layer, followed by hidden layers, and ending with the output layer. Must include at least input, one hidden, and output layer sizes.
|
|
2275
|
+
|
|
2276
|
+
Returns: The constructed MLP network.
|
|
2277
|
+
|
|
2278
|
+
#### previousDeltaBias
|
|
2279
|
+
|
|
2280
|
+
The change in bias applied in the previous training iteration. Used for calculating momentum.
|
|
2281
|
+
|
|
2282
|
+
#### propagate
|
|
2283
|
+
|
|
2284
|
+
`(rate: number, momentum: number, update: boolean, target: number[], regularization: number, costDerivative: ((target: number, output: number) => number) | undefined) => void`
|
|
2285
|
+
|
|
2286
|
+
Propagates the error backward through the network (backpropagation).
|
|
2287
|
+
Calculates the error gradient for each node and connection.
|
|
2288
|
+
If `update` is true, it adjusts the weights and biases based on the calculated gradients,
|
|
2289
|
+
learning rate, momentum, and optional L2 regularization.
|
|
2290
|
+
|
|
2291
|
+
The process starts from the output nodes and moves backward layer by layer (or topologically for recurrent nets).
|
|
2292
|
+
|
|
2293
|
+
Parameters:
|
|
2294
|
+
- `` - - The learning rate (controls the step size of weight adjustments).
|
|
2295
|
+
- `` - - The momentum factor (helps overcome local minima and speeds up convergence). Typically between 0 and 1.
|
|
2296
|
+
- `` - - If true, apply the calculated weight and bias updates. If false, only calculate gradients (e.g., for batch accumulation).
|
|
2297
|
+
- `` - - An array of target values corresponding to the network's output nodes.
|
|
2298
|
+
The length must match the network's `output` size.
|
|
2299
|
+
- `` - - The L2 regularization factor (lambda). Helps prevent overfitting by penalizing large weights.
|
|
2300
|
+
- `` - - Optional derivative of the cost function for output nodes.
|
|
2301
|
+
|
|
2302
|
+
#### propagate
|
|
2303
|
+
|
|
2304
|
+
`(rate: number, momentum: number, update: boolean, regularization: number | { type: "L1" | "L2"; lambda: number; } | ((weight: number) => number), target: number | undefined) => void`
|
|
2305
|
+
|
|
2306
|
+
Back-propagates the error signal through the node and calculates weight/bias updates.
|
|
2307
|
+
|
|
2308
|
+
This method implements the backpropagation algorithm, including:
|
|
2309
|
+
1. Calculating the node's error responsibility based on errors from subsequent nodes (`projected` error)
|
|
2310
|
+
and errors from connections it gates (`gated` error).
|
|
2311
|
+
2. Calculating the gradient for each incoming connection's weight using eligibility traces (`xtrace`).
|
|
2312
|
+
3. Calculating the change (delta) for weights and bias, incorporating:
|
|
2313
|
+
- Learning rate.
|
|
2314
|
+
- L1/L2/custom regularization.
|
|
2315
|
+
- Momentum (using Nesterov Accelerated Gradient - NAG).
|
|
2316
|
+
4. Optionally applying the calculated updates immediately or accumulating them for batch training.
|
|
2317
|
+
|
|
2318
|
+
Parameters:
|
|
2319
|
+
- `rate` - The learning rate (controls the step size of updates).
|
|
2320
|
+
- `momentum` - The momentum factor (helps accelerate learning and overcome local minima). Uses NAG.
|
|
2321
|
+
- `update` - If true, apply the calculated weight/bias updates immediately. If false, accumulate them in `totalDelta*` properties for batch updates.
|
|
2322
|
+
- `regularization` - The regularization setting. Can be:
|
|
2323
|
+
- number (L2 lambda)
|
|
2324
|
+
- { type: 'L1'|'L2', lambda: number }
|
|
2325
|
+
- (weight: number) => number (custom function)
|
|
2326
|
+
- `target` - The target output value for this node. Only used if the node is of type 'output'.
|
|
2327
|
+
|
|
2328
|
+
#### propagate
|
|
2329
|
+
|
|
2330
|
+
`(rate: number, momentum: number, target: number[] | undefined) => void`
|
|
2331
|
+
|
|
2332
|
+
Propagates the error backward through all nodes in the layer.
|
|
2333
|
+
|
|
2334
|
+
This is a core step in the backpropagation algorithm used for training.
|
|
2335
|
+
If a `target` array is provided (typically for the output layer), it's used
|
|
2336
|
+
to calculate the initial error for each node. Otherwise, nodes calculate
|
|
2337
|
+
their error based on the error propagated from subsequent layers.
|
|
2338
|
+
|
|
2339
|
+
Parameters:
|
|
2340
|
+
- `rate` - - The learning rate, controlling the step size of weight adjustments.
|
|
2341
|
+
- `momentum` - - The momentum factor, used to smooth weight updates and escape local minima.
|
|
2342
|
+
- `target` - - An optional array of target values (expected outputs) for the layer's nodes. The length must match the number of nodes.
|
|
2343
|
+
- `` - - The learning rate to apply during weight updates.
|
|
2344
|
+
|
|
2345
|
+
#### pruneToSparsity
|
|
2346
|
+
|
|
2347
|
+
`(targetSparsity: number, method: "magnitude" | "snip") => void`
|
|
2348
|
+
|
|
2349
|
+
Immediately prune connections to reach (or approach) a target sparsity fraction.
|
|
2350
|
+
Used by evolutionary pruning (generation-based) independent of training iteration schedule.
|
|
2351
|
+
|
|
2352
|
+
Parameters:
|
|
2353
|
+
- `targetSparsity` - fraction in (0,1). 0.8 means keep 20% of original (if first call sets baseline)
|
|
2354
|
+
- `method` - 'magnitude' | 'snip'
|
|
2355
|
+
|
|
2356
|
+
#### random
|
|
2357
|
+
|
|
2358
|
+
`(input: number, hidden: number, output: number, options: { connections?: number | undefined; backconnections?: number | undefined; selfconnections?: number | undefined; gates?: number | undefined; }) => import("D:/code-practice/NeatapticTS/src/architecture/network").default`
|
|
2359
|
+
|
|
2360
|
+
Creates a randomly structured network based on specified node counts and connection options.
|
|
2361
|
+
|
|
2362
|
+
This method allows for the generation of networks with a less rigid structure than MLPs.
|
|
2363
|
+
It initializes a network with input and output nodes and then iteratively adds hidden nodes
|
|
2364
|
+
and various types of connections (forward, backward, self) and gates using mutation methods.
|
|
2365
|
+
This approach is inspired by neuro-evolution techniques where network topology evolves.
|
|
2366
|
+
|
|
2367
|
+
Parameters:
|
|
2368
|
+
- `` - - The number of input nodes.
|
|
2369
|
+
- `` - - The number of hidden nodes to add.
|
|
2370
|
+
- `` - - The number of output nodes.
|
|
2371
|
+
- `` - - Optional configuration for the network structure.
|
|
2372
|
+
|
|
2373
|
+
Returns: The constructed network with a randomized topology.
|
|
2374
|
+
|
|
2375
|
+
#### rebuildConnections
|
|
2376
|
+
|
|
2377
|
+
`(net: import("D:/code-practice/NeatapticTS/src/architecture/network").default) => void`
|
|
2378
|
+
|
|
2379
|
+
Rebuilds the network's connections array from all per-node connections.
|
|
2380
|
+
This ensures that the network.connections array is consistent with the actual
|
|
2381
|
+
outgoing connections of all nodes. Useful after manual wiring or node manipulation.
|
|
2382
|
+
|
|
2383
|
+
Parameters:
|
|
2384
|
+
- `` - - The network instance to rebuild connections for.
|
|
2385
|
+
|
|
2386
|
+
Returns: Example usage:
|
|
2387
|
+
Network.rebuildConnections(net);
|
|
2388
|
+
|
|
2389
|
+
#### release
|
|
2390
|
+
|
|
2391
|
+
`(conn: import("D:/code-practice/NeatapticTS/src/architecture/connection").default) => void`
|
|
2392
|
+
|
|
2393
|
+
Return a Connection to the pool for reuse.
|
|
2394
|
+
|
|
2395
|
+
#### remove
|
|
2396
|
+
|
|
2397
|
+
`(node: import("D:/code-practice/NeatapticTS/src/architecture/node").default) => void`
|
|
2398
|
+
|
|
2399
|
+
Removes a node from the network.
|
|
2400
|
+
This involves:
|
|
2401
|
+
1. Disconnecting all incoming and outgoing connections associated with the node.
|
|
2402
|
+
2. Removing any self-connections.
|
|
2403
|
+
3. Removing the node from the `nodes` array.
|
|
2404
|
+
4. Attempting to reconnect the node's direct predecessors to its direct successors
|
|
2405
|
+
to maintain network flow, if possible and configured.
|
|
2406
|
+
5. Handling gates involving the removed node (ungating connections gated *by* this node,
|
|
2407
|
+
and potentially re-gating connections that were gated *by other nodes* onto the removed node's connections).
|
|
2408
|
+
|
|
2409
|
+
Parameters:
|
|
2410
|
+
- `` - - The node instance to remove. Must exist within the network's `nodes` list.
|
|
2411
|
+
|
|
2412
|
+
#### resetDropoutMasks
|
|
2413
|
+
|
|
2414
|
+
`() => void`
|
|
2415
|
+
|
|
2416
|
+
Resets all masks in the network to 1 (no dropout). Applies to both node-level and layer-level dropout.
|
|
2417
|
+
Should be called after training to ensure inference is unaffected by previous dropout.
|
|
2418
|
+
|
|
2419
|
+
#### resetNoveltyArchive
|
|
2420
|
+
|
|
2421
|
+
`() => void`
|
|
2422
|
+
|
|
2423
|
+
Reset the novelty archive (clear entries).
|
|
2424
|
+
|
|
2425
|
+
The novelty archive is used to keep representative behaviors for novelty
|
|
2426
|
+
search. Clearing it removes stored behaviors.
|
|
2427
|
+
|
|
2428
|
+
#### restoreRNGState
|
|
2429
|
+
|
|
2430
|
+
`(state: any) => void`
|
|
2431
|
+
|
|
2432
|
+
Restore a previously-snapshotted RNG state. This restores the internal
|
|
2433
|
+
seed but does not re-create the RNG function until next use.
|
|
2434
|
+
|
|
2435
|
+
Parameters:
|
|
2436
|
+
- `state` - Opaque numeric RNG state produced by `snapshotRNGState()`.
|
|
2437
|
+
|
|
2438
|
+
#### sampleRandom
|
|
2439
|
+
|
|
2440
|
+
`(count: number) => number[]`
|
|
2441
|
+
|
|
2442
|
+
Produce `count` deterministic random samples using instance RNG.
|
|
2443
|
+
|
|
2444
|
+
#### selectMutationMethod
|
|
2445
|
+
|
|
2446
|
+
`(genome: import("D:/code-practice/NeatapticTS/src/architecture/network").default, rawReturnForTest: boolean) => any`
|
|
2447
|
+
|
|
2448
|
+
Selects a mutation method for a given genome based on constraints.
|
|
2449
|
+
Ensures that the mutation respects the maximum nodes, connections, and gates.
|
|
2450
|
+
|
|
2451
|
+
Parameters:
|
|
2452
|
+
- `genome` - - The genome to mutate.
|
|
2453
|
+
|
|
2454
|
+
Returns: The selected mutation method or null if no valid method is available.
|
|
2455
|
+
|
|
2456
|
+
#### serialize
|
|
2457
|
+
|
|
2458
|
+
`() => any[]`
|
|
2459
|
+
|
|
2460
|
+
Lightweight tuple serializer delegating to network.serialize.ts
|
|
2461
|
+
|
|
2462
|
+
#### set
|
|
2463
|
+
|
|
2464
|
+
`(values: { bias?: number | undefined; squash?: any; }) => void`
|
|
2465
|
+
|
|
2466
|
+
Sets specified properties (e.g., bias, squash function) for all nodes in the network.
|
|
2467
|
+
Useful for initializing or resetting node properties uniformly.
|
|
2468
|
+
|
|
2469
|
+
Parameters:
|
|
2470
|
+
- `` - - An object containing the properties and values to set.
|
|
2471
|
+
|
|
2472
|
+
#### set
|
|
2473
|
+
|
|
2474
|
+
`(values: { bias?: number | undefined; squash?: any; type?: string | undefined; }) => void`
|
|
2475
|
+
|
|
2476
|
+
Configures properties for all nodes within the layer.
|
|
2477
|
+
|
|
2478
|
+
Allows batch setting of common node properties like bias, activation function (`squash`),
|
|
2479
|
+
or node type. If a node within the `nodes` array is actually a `Group` (e.g., in memory layers),
|
|
2480
|
+
the configuration is applied recursively to the nodes within that group.
|
|
2481
|
+
|
|
2482
|
+
Parameters:
|
|
2483
|
+
- `values` - - An object containing the properties and their values to set.
|
|
2484
|
+
Example: `{ bias: 0.5, squash: methods.Activation.ReLU }`
|
|
2485
|
+
- `` - - An object containing the properties and their new values. Only provided properties are updated.
|
|
2486
|
+
`bias`: Sets the bias term for all nodes.
|
|
2487
|
+
`squash`: Sets the activation function (squashing function) for all nodes.
|
|
2488
|
+
`type`: Sets the node type (e.g., 'input', 'hidden', 'output') for all nodes.
|
|
2489
|
+
|
|
2490
|
+
#### setActivation
|
|
2491
|
+
|
|
2492
|
+
`(fn: (x: number, derivate?: boolean | undefined) => number) => void`
|
|
2493
|
+
|
|
2494
|
+
Sets a custom activation function for this node at runtime.
|
|
2495
|
+
|
|
2496
|
+
Parameters:
|
|
2497
|
+
- `fn` - The activation function (should handle derivative if needed).
|
|
2498
|
+
|
|
2499
|
+
#### setStochasticDepth
|
|
2500
|
+
|
|
2501
|
+
`(survival: number[]) => void`
|
|
2502
|
+
|
|
2503
|
+
Configure stochastic depth with survival probabilities per hidden layer (length must match hidden layer count when using layered network).
|
|
2504
|
+
|
|
2505
|
+
#### snapshotRNGState
|
|
2506
|
+
|
|
2507
|
+
`() => number | undefined`
|
|
2508
|
+
|
|
2509
|
+
Return the current opaque RNG numeric state used by the instance.
|
|
2510
|
+
Useful for deterministic test replay and debugging.
|
|
2511
|
+
|
|
2512
|
+
#### sort
|
|
2513
|
+
|
|
2514
|
+
`() => void`
|
|
2515
|
+
|
|
2516
|
+
Sorts the population in descending order of fitness scores.
|
|
2517
|
+
Ensures that the fittest genomes are at the start of the population array.
|
|
2518
|
+
|
|
2519
|
+
#### spawnFromParent
|
|
2520
|
+
|
|
2521
|
+
`(parent: import("D:/code-practice/NeatapticTS/src/architecture/network").default, mutateCount: number) => import("D:/code-practice/NeatapticTS/src/architecture/network").default`
|
|
2522
|
+
|
|
2523
|
+
Spawn a new genome derived from a single parent while preserving Neat bookkeeping.
|
|
2524
|
+
|
|
2525
|
+
This helper performs a canonical "clone + slight mutation" workflow while
|
|
2526
|
+
keeping `Neat`'s internal invariants intact. It is intended for callers that
|
|
2527
|
+
want a child genome derived from a single parent but do not want to perform the
|
|
2528
|
+
bookkeeping and registration steps manually. The function deliberately does NOT
|
|
2529
|
+
add the returned child to `this.population` so callers are free to inspect or
|
|
2530
|
+
further modify the child and then register it via `addGenome()` (or push it
|
|
2531
|
+
directly if they understand the consequences).
|
|
2532
|
+
|
|
2533
|
+
Behavior summary:
|
|
2534
|
+
- Clone the provided `parent` (`parent.clone()` when available, else JSON round-trip).
|
|
2535
|
+
- Clear fitness/score on the child and assign a fresh unique `_id`.
|
|
2536
|
+
- If lineage tracking is enabled, set `(child as any)._parents = [parent._id]`
|
|
2537
|
+
and `(child as any)._depth = (parent._depth ?? 0) + 1`.
|
|
2538
|
+
- Enforce structural invariants by calling `ensureMinHiddenNodes(child)` and
|
|
2539
|
+
`ensureNoDeadEnds(child)` so the child is valid for subsequent mutation/evaluation.
|
|
2540
|
+
- Apply `mutateCount` mutations selected via `selectMutationMethod` and driven by
|
|
2541
|
+
the instance RNG (`_getRNG()`); mutation exceptions are caught and ignored to
|
|
2542
|
+
preserve best-effort behavior during population seeding/expansion.
|
|
2543
|
+
- Invalidate per-genome caches with `_invalidateGenomeCaches(child)` before return.
|
|
2544
|
+
|
|
2545
|
+
Important: the returned child is not registered in `Neat.population` — call
|
|
2546
|
+
`addGenome(child, [parentId])` to insert it and keep telemetry/lineage consistent.
|
|
2547
|
+
|
|
2548
|
+
Parameters:
|
|
2549
|
+
- `parent` - - Source genome to derive from. Must be a `Network` instance.
|
|
2550
|
+
- `mutateCount` - - Number of mutation operations to apply to the spawned child (default: 1).
|
|
2551
|
+
|
|
2552
|
+
Returns: A new `Network` instance derived from `parent`. The child is unregistered.
|
|
2553
|
+
|
|
2554
|
+
#### squash
|
|
2555
|
+
|
|
2556
|
+
`(x: number, derivate: boolean | undefined) => number`
|
|
2557
|
+
|
|
2558
|
+
The activation function (squashing function) applied to the node's state.
|
|
2559
|
+
Maps the internal state to the node's output (activation).
|
|
2560
|
+
|
|
2561
|
+
Parameters:
|
|
2562
|
+
- `x` - The node's internal state (sum of weighted inputs + bias).
|
|
2563
|
+
- `derivate` - If true, returns the derivative of the function instead of the function value.
|
|
2564
|
+
|
|
2565
|
+
Returns: The activation value or its derivative.
|
|
2566
|
+
|
|
2567
|
+
#### state
|
|
2568
|
+
|
|
2569
|
+
The internal state of the node (sum of weighted inputs + bias) before the activation function is applied.
|
|
2570
|
+
|
|
2571
|
+
#### test
|
|
2572
|
+
|
|
2573
|
+
`(set: { input: number[]; output: number[]; }[], cost: any) => { error: number; time: number; }`
|
|
2574
|
+
|
|
2575
|
+
Tests the network's performance on a given dataset.
|
|
2576
|
+
Calculates the average error over the dataset using a specified cost function.
|
|
2577
|
+
Uses `noTraceActivate` for efficiency as gradients are not needed.
|
|
2578
|
+
Handles dropout scaling if dropout was used during training.
|
|
2579
|
+
|
|
2580
|
+
Parameters:
|
|
2581
|
+
- `` - - The test dataset, an array of objects with `input` and `output` arrays.
|
|
2582
|
+
- `` - - The cost function to evaluate the error. Defaults to Mean Squared Error.
|
|
2583
|
+
|
|
2584
|
+
Returns: An object containing the calculated average error over the dataset and the time taken for the test in milliseconds.
|
|
2585
|
+
|
|
2586
|
+
#### toJSON
|
|
2587
|
+
|
|
2588
|
+
`() => any`
|
|
2589
|
+
|
|
2590
|
+
Import a previously exported state bundle and rehydrate a Neat instance.
|
|
2591
|
+
|
|
2592
|
+
#### toJSON
|
|
2593
|
+
|
|
2594
|
+
`() => object`
|
|
2595
|
+
|
|
2596
|
+
Converts the network into a JSON object representation (latest standard).
|
|
2597
|
+
Includes formatVersion, and only serializes properties needed for full reconstruction.
|
|
2598
|
+
All references are by index. Excludes runtime-only properties (activation, state, traces).
|
|
2599
|
+
|
|
2600
|
+
Returns: A JSON-compatible object representing the network.
|
|
2601
|
+
|
|
2602
|
+
#### toJSON
|
|
2603
|
+
|
|
2604
|
+
`() => { index: number | undefined; bias: number; type: string; squash: string | null; mask: number; }`
|
|
2605
|
+
|
|
2606
|
+
Converts the node's essential properties to a JSON object for serialization.
|
|
2607
|
+
Does not include state, activation, error, or connection information, as these
|
|
2608
|
+
are typically transient or reconstructed separately.
|
|
2609
|
+
|
|
2610
|
+
Returns: A JSON representation of the node's configuration.
|
|
2611
|
+
|
|
2612
|
+
#### toJSON
|
|
2613
|
+
|
|
2614
|
+
`() => { size: number; nodeIndices: (number | undefined)[]; connections: { in: number; out: number; self: number; }; }`
|
|
2615
|
+
|
|
2616
|
+
Serializes the group into a JSON-compatible format, avoiding circular references.
|
|
2617
|
+
Only includes node indices and connection counts.
|
|
2618
|
+
|
|
2619
|
+
Returns: A JSON-compatible representation of the group.
|
|
2620
|
+
|
|
2621
|
+
#### toONNX
|
|
2622
|
+
|
|
2623
|
+
`() => import("D:/code-practice/NeatapticTS/src/architecture/network/network.onnx").OnnxModel`
|
|
2624
|
+
|
|
2625
|
+
Exports the network to ONNX format (JSON object, minimal MLP support).
|
|
2626
|
+
Only standard feedforward architectures and standard activations are supported.
|
|
2627
|
+
Gating, custom activations, and evolutionary features are ignored or replaced with Identity.
|
|
2628
|
+
|
|
2629
|
+
Returns: ONNX model as a JSON object.
|
|
2630
|
+
|
|
2631
|
+
#### totalDeltaBias
|
|
2632
|
+
|
|
2633
|
+
Accumulates changes in bias over a mini-batch during batch training. Reset after each weight update.
|
|
2634
|
+
|
|
2635
|
+
#### type
|
|
2636
|
+
|
|
2637
|
+
The type of the node: 'input', 'hidden', or 'output'.
|
|
2638
|
+
Determines behavior (e.g., input nodes don't have biases modified typically, output nodes calculate error differently).
|
|
2639
|
+
|
|
2640
|
+
#### ungate
|
|
2641
|
+
|
|
2642
|
+
`(connection: import("D:/code-practice/NeatapticTS/src/architecture/connection").default) => void`
|
|
2643
|
+
|
|
2644
|
+
Removes the gate from a specified connection.
|
|
2645
|
+
The connection will no longer be modulated by its gater node.
|
|
2646
|
+
Removes the connection from the network's `gates` list.
|
|
2647
|
+
|
|
2648
|
+
Parameters:
|
|
2649
|
+
- `` - - The connection object to ungate.
|
|
2650
|
+
|
|
2651
|
+
#### ungate
|
|
2652
|
+
|
|
2653
|
+
`(connections: import("D:/code-practice/NeatapticTS/src/architecture/connection").default | import("D:/code-practice/NeatapticTS/src/architecture/connection").default[]) => void`
|
|
2654
|
+
|
|
2655
|
+
Removes this node's gating control over the specified connection(s).
|
|
2656
|
+
Resets the connection's gain to 1 and removes it from the `connections.gated` list.
|
|
2657
|
+
|
|
2658
|
+
Parameters:
|
|
2659
|
+
- `connections` - A single Connection object or an array of Connection objects to ungate.
|