@reicek/neataptic-ts 0.1.25 → 0.1.26
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/copilot-instructions.md +11 -0
- package/.github/skills/trace-analyzer-extension/SKILL.md +3 -3
- package/.github/skills/trace-analyzer-extension/assets/extension-checklist.md +1 -1
- package/.github/skills/trace-analyzer-extension/references/analyzer-extension-workflow.md +1 -1
- package/.github/skills/trace-audit-reporting/SKILL.md +3 -3
- package/.github/skills/trace-audit-reporting/references/trace-analysis-workflow.md +1 -1
- package/package.json +19 -13
- package/plans/Flappy_Bird_Folder_Documentation_Pass.md +4 -4
- package/plans/README.md +24 -0
- package/plans/Roadmap.md +62 -40
- package/plans/analyze-trace-solid-split.plans.md +66 -0
- package/plans/architecture-solid-split.plans.md +9 -15
- package/plans/asciiMaze-typescript-repair.plans.md +1 -1
- package/plans/generate-docs-solid-split.plans.md +87 -0
- package/plans/methods-docs.plans.md +25 -1
- package/plans/methods-solid-split.plans.md +14 -14
- package/plans/neat-docs.plans.md +9 -1
- package/plans/neat-test-surface-repair.plans.md +1 -1
- package/plans/render-docs-html-solid-split.plans.md +68 -0
- package/plans/src-no-explicit-any-cleanup.plans.md +1 -1
- package/plans/utils-docs.plans.md +6 -1
- package/scripts/analyze-trace/analyze-trace.analysis.ts +479 -0
- package/scripts/analyze-trace/analyze-trace.constants.ts +35 -0
- package/scripts/analyze-trace/analyze-trace.io.ts +69 -0
- package/scripts/analyze-trace/analyze-trace.report.ts +100 -0
- package/scripts/analyze-trace/analyze-trace.shared.ts +116 -0
- package/scripts/analyze-trace/analyze-trace.ts +45 -0
- package/scripts/analyze-trace/analyze-trace.types.ts +72 -0
- package/scripts/assets/theme.css +80 -23
- package/scripts/copy-examples.ts +239 -0
- package/scripts/export-onnx.ts +223 -0
- package/scripts/generate-bench-tables.ts +378 -37
- package/scripts/generate-docs/generate-docs.constants.ts +107 -0
- package/scripts/generate-docs/generate-docs.order.ts +355 -0
- package/scripts/generate-docs/generate-docs.state.ts +31 -0
- package/scripts/generate-docs/generate-docs.targets.ts +165 -0
- package/scripts/generate-docs/generate-docs.ts +63 -0
- package/scripts/generate-docs/generate-docs.types.ts +112 -0
- package/scripts/generate-docs/output/generate-docs.output.folder-index.utils.ts +167 -0
- package/scripts/generate-docs/output/generate-docs.output.ordering.utils.ts +353 -0
- package/scripts/generate-docs/output/generate-docs.output.readme.utils.ts +420 -0
- package/scripts/generate-docs/output/generate-docs.output.ts +123 -0
- package/scripts/generate-docs/output/generate-docs.output.warnings.utils.ts +219 -0
- package/scripts/generate-docs/symbols/generate-docs.symbols.collection.utils.ts +365 -0
- package/scripts/generate-docs/symbols/generate-docs.symbols.jsdoc.utils.ts +373 -0
- package/scripts/generate-docs/symbols/generate-docs.symbols.normalize.utils.ts +155 -0
- package/scripts/generate-docs/symbols/generate-docs.symbols.render.utils.ts +149 -0
- package/scripts/generate-docs/symbols/generate-docs.symbols.signature.utils.ts +289 -0
- package/scripts/generate-docs/symbols/generate-docs.symbols.ts +11 -0
- package/scripts/mermaid-cli.mjs +102 -22
- package/scripts/mermaid-cli.ts +736 -0
- package/scripts/render-docs-html/render-docs-html.assets.ts +54 -0
- package/scripts/render-docs-html/render-docs-html.mermaid.ts +245 -0
- package/scripts/{render-docs-html.sidebar.ts → render-docs-html/render-docs-html.navigation.ts} +141 -144
- package/scripts/render-docs-html/render-docs-html.pages.ts +333 -0
- package/scripts/render-docs-html/render-docs-html.shared.ts +333 -0
- package/scripts/render-docs-html/render-docs-html.types.ts +42 -0
- package/scripts/render-docs-html.ts +23 -587
- package/scripts/run-docs.ts +238 -0
- package/scripts/write-dist-docs-pkg.ts +40 -0
- package/src/README.md +75 -75
- package/src/architecture/connection/README.md +5 -5
- package/src/architecture/layer/README.md +508 -508
- package/src/architecture/network/README.md +1458 -1458
- package/src/architecture/network/activate/README.md +694 -694
- package/src/architecture/network/bootstrap/README.md +77 -77
- package/src/architecture/network/connect/README.md +74 -74
- package/src/architecture/network/deterministic/README.md +135 -135
- package/src/architecture/network/evolve/README.md +364 -364
- package/src/architecture/network/gating/README.md +130 -130
- package/src/architecture/network/genetic/README.md +399 -399
- package/src/architecture/network/mutate/README.md +897 -897
- package/src/architecture/network/onnx/README.md +720 -720
- package/src/architecture/network/onnx/export/README.md +728 -728
- package/src/architecture/network/onnx/export/layers/README.md +450 -450
- package/src/architecture/network/onnx/import/README.md +618 -618
- package/src/architecture/network/onnx/schema/README.md +32 -32
- package/src/architecture/network/prune/README.md +245 -245
- package/src/architecture/network/remove/README.md +135 -135
- package/src/architecture/network/runtime/README.md +106 -106
- package/src/architecture/network/serialize/README.md +542 -542
- package/src/architecture/network/slab/README.md +608 -608
- package/src/architecture/network/standalone/README.md +212 -212
- package/src/architecture/network/stats/README.md +84 -84
- package/src/architecture/network/topology/README.md +465 -465
- package/src/architecture/network/training/README.md +200 -200
- package/src/architecture/node/README.md +5 -5
- package/src/architecture/nodePool/README.md +14 -14
- package/src/methods/README.md +99 -99
- package/src/methods/activation/README.md +189 -189
- package/src/methods/cost/README.md +131 -131
- package/src/methods/rate/README.md +86 -86
- package/src/multithreading/README.md +77 -77
- package/src/multithreading/workers/browser/README.md +8 -8
- package/src/multithreading/workers/node/README.md +8 -8
- package/src/neat/README.md +148 -148
- package/src/neat/adaptive/README.md +120 -120
- package/src/neat/adaptive/acceptance/README.md +40 -40
- package/src/neat/adaptive/complexity/README.md +137 -137
- package/src/neat/adaptive/core/README.md +197 -197
- package/src/neat/adaptive/lineage/README.md +90 -90
- package/src/neat/adaptive/mutation/README.md +284 -284
- package/src/neat/compat/README.md +43 -43
- package/src/neat/compat/core/README.md +90 -90
- package/src/neat/diversity/README.md +35 -35
- package/src/neat/diversity/core/README.md +88 -88
- package/src/neat/evaluate/README.md +85 -85
- package/src/neat/evaluate/auto-distance/README.md +75 -75
- package/src/neat/evaluate/entropy-compat/README.md +37 -37
- package/src/neat/evaluate/entropy-sharing/README.md +43 -43
- package/src/neat/evaluate/fitness/README.md +23 -23
- package/src/neat/evaluate/novelty/README.md +120 -120
- package/src/neat/evaluate/objectives/README.md +17 -17
- package/src/neat/evaluate/shared/README.md +94 -94
- package/src/neat/evolve/README.md +96 -96
- package/src/neat/evolve/adaptive/README.md +60 -60
- package/src/neat/evolve/objectives/README.md +63 -63
- package/src/neat/evolve/offspring/README.md +56 -56
- package/src/neat/evolve/population/README.md +171 -171
- package/src/neat/evolve/runtime/README.md +79 -79
- package/src/neat/evolve/speciation/README.md +74 -74
- package/src/neat/evolve/warnings/README.md +10 -10
- package/src/neat/export/README.md +114 -114
- package/src/neat/helpers/README.md +50 -50
- package/src/neat/init/README.md +9 -9
- package/src/neat/lineage/core/README.md +101 -101
- package/src/neat/multiobjective/category/README.md +74 -74
- package/src/neat/multiobjective/crowding/README.md +272 -272
- package/src/neat/multiobjective/dominance/README.md +171 -171
- package/src/neat/multiobjective/fronts/README.md +68 -68
- package/src/neat/multiobjective/metrics/README.md +43 -43
- package/src/neat/multiobjective/objectives/README.md +31 -31
- package/src/neat/multiobjective/shared/README.md +27 -27
- package/src/neat/mutation/README.md +97 -97
- package/src/neat/mutation/add-conn/README.md +115 -115
- package/src/neat/mutation/add-node/README.md +126 -126
- package/src/neat/mutation/flow/README.md +149 -149
- package/src/neat/mutation/repair/README.md +185 -185
- package/src/neat/mutation/select/README.md +117 -117
- package/src/neat/mutation/shared/README.md +32 -32
- package/src/neat/objectives/README.md +25 -25
- package/src/neat/objectives/core/README.md +67 -67
- package/src/neat/pruning/README.md +40 -40
- package/src/neat/pruning/core/README.md +171 -171
- package/src/neat/pruning/facade/README.md +32 -32
- package/src/neat/rng/README.md +104 -104
- package/src/neat/rng/core/README.md +137 -137
- package/src/neat/rng/facade/README.md +50 -50
- package/src/neat/selection/README.md +111 -111
- package/src/neat/selection/core/README.md +227 -227
- package/src/neat/selection/facade/README.md +61 -61
- package/src/neat/shared/README.md +163 -163
- package/src/neat/speciation/README.md +31 -31
- package/src/neat/speciation/threshold/README.md +35 -35
- package/src/neat/species/README.md +25 -25
- package/src/neat/species/core/README.md +20 -20
- package/src/neat/species/core/shared/README.md +18 -18
- package/src/neat/species/history/context/README.md +22 -22
- package/src/neat/telemetry/accessors/README.md +58 -58
- package/src/neat/telemetry/exports/README.md +233 -233
- package/src/neat/telemetry/facade/README.md +252 -252
- package/src/neat/telemetry/facade/archive/README.md +57 -57
- package/src/neat/telemetry/facade/buffer/README.md +43 -43
- package/src/neat/telemetry/facade/lineage/README.md +12 -12
- package/src/neat/telemetry/facade/objectives/README.md +44 -44
- package/src/neat/telemetry/facade/runtime/README.md +26 -26
- package/src/neat/telemetry/facade/species/README.md +27 -27
- package/src/neat/telemetry/metrics/README.md +696 -696
- package/src/neat/telemetry/recorder/README.md +57 -57
- package/src/neat/telemetry/types/README.md +32 -32
- package/src/neat/topology-intent/README.md +75 -75
- package/src/utils/README.md +193 -193
- package/test/examples/asciiMaze/browser-entry/README.md +92 -92
- package/test/examples/asciiMaze/dashboardManager/README.md +109 -109
- package/test/examples/asciiMaze/dashboardManager/telemetry/README.md +28 -28
- package/test/examples/asciiMaze/evolutionEngine/README.md +1527 -1527
- package/test/examples/asciiMaze/mazeMovement/README.md +105 -105
- package/test/examples/asciiMaze/mazeMovement/finalization/README.md +16 -16
- package/test/examples/asciiMaze/mazeMovement/policy/README.md +57 -57
- package/test/examples/asciiMaze/mazeMovement/runtime/README.md +52 -52
- package/test/examples/asciiMaze/mazeMovement/shaping/README.md +46 -46
- package/test/examples/flappy_bird/browser-entry/README.md +508 -508
- package/test/examples/flappy_bird/browser-entry/host/README.md +101 -101
- package/test/examples/flappy_bird/browser-entry/host/resize/README.md +144 -144
- package/test/examples/flappy_bird/browser-entry/network-view/README.md +194 -194
- package/test/examples/flappy_bird/browser-entry/playback/README.md +278 -278
- package/test/examples/flappy_bird/browser-entry/playback/background/README.md +129 -129
- package/test/examples/flappy_bird/browser-entry/playback/background/ground-grid/README.md +502 -502
- package/test/examples/flappy_bird/browser-entry/playback/frame-render/README.md +139 -139
- package/test/examples/flappy_bird/browser-entry/playback/snapshot/README.md +10 -10
- package/test/examples/flappy_bird/browser-entry/playback/trail/README.md +43 -43
- package/test/examples/flappy_bird/browser-entry/playback/worker-channel/README.md +30 -30
- package/test/examples/flappy_bird/browser-entry/runtime/README.md +59 -59
- package/test/examples/flappy_bird/browser-entry/visualization/README.md +276 -276
- package/test/examples/flappy_bird/browser-entry/worker-channel/README.md +16 -16
- package/test/examples/flappy_bird/constants/README.md +1070 -1070
- package/test/examples/flappy_bird/environment/README.md +22 -22
- package/test/examples/flappy_bird/evaluation/README.md +32 -32
- package/test/examples/flappy_bird/evaluation/rollout/README.md +141 -141
- package/test/examples/flappy_bird/flappy-evolution-worker/README.md +425 -425
- package/test/examples/flappy_bird/simulation-shared/README.md +170 -170
- package/test/examples/flappy_bird/simulation-shared/observation/README.md +109 -109
- package/test/examples/flappy_bird/trainer/README.md +325 -325
- package/test/examples/flappy_bird/trainer/evaluation/README.md +74 -74
- package/scripts/analyze-trace.ts +0 -590
- package/scripts/copy-examples.mjs +0 -114
- package/scripts/export-onnx.mjs +0 -86
- package/scripts/generate-bench-tables.mjs +0 -182
- package/scripts/generate-docs.ts +0 -2900
- package/scripts/write-dist-docs-pkg.mjs +0 -16
|
@@ -37,6 +37,36 @@ flowchart TD
|
|
|
37
37
|
|
|
38
38
|
## neat/evolve/speciation/evolve.speciation.utils.ts
|
|
39
39
|
|
|
40
|
+
### applyGlobalStagnationInjectionIfNeeded
|
|
41
|
+
|
|
42
|
+
```ts
|
|
43
|
+
applyGlobalStagnationInjectionIfNeeded(
|
|
44
|
+
internal: NeatControllerForEvolution,
|
|
45
|
+
helpers: { buildFreshGenomeForStagnation: () => Promise<GenomeWithMetadata>; replaceFraction: number; },
|
|
46
|
+
): Promise<void>
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Apply global stagnation injection if configured.
|
|
50
|
+
|
|
51
|
+
This is the evolve loop's constrained recovery valve for long periods without
|
|
52
|
+
global improvement. Instead of discarding the whole population or rebuilding
|
|
53
|
+
the generation logic from scratch, the helper replaces only the worst-ranked
|
|
54
|
+
fraction beyond elitism with fresh genomes, then resets the stagnation window
|
|
55
|
+
so the controller can test whether the new search seeds reopen progress.
|
|
56
|
+
|
|
57
|
+
The design is intentionally conservative:
|
|
58
|
+
|
|
59
|
+
- elites are preserved,
|
|
60
|
+
- the replacement fraction is bounded by the caller,
|
|
61
|
+
- injected genomes still pass through the normal later evolution pipeline.
|
|
62
|
+
|
|
63
|
+
Parameters:
|
|
64
|
+
- `internal` - - NEAT controller instance.
|
|
65
|
+
- `helpers` - - Helper callbacks for stagnation injection.
|
|
66
|
+
- `helpers` - - Genome builder for injection.
|
|
67
|
+
|
|
68
|
+
Returns: A promise that resolves after bounded replacements are complete.
|
|
69
|
+
|
|
40
70
|
### applySpeciationAndSharingIfEnabled
|
|
41
71
|
|
|
42
72
|
```ts
|
|
@@ -90,80 +120,43 @@ Parameters:
|
|
|
90
120
|
|
|
91
121
|
Returns: A new genome prepared for bounded stagnation rescue.
|
|
92
122
|
|
|
93
|
-
###
|
|
94
|
-
|
|
95
|
-
```ts
|
|
96
|
-
recordSpeciesHistorySnapshot(
|
|
97
|
-
internal: NeatControllerForEvolution,
|
|
98
|
-
maxHistory: number,
|
|
99
|
-
): void
|
|
100
|
-
```
|
|
101
|
-
|
|
102
|
-
Record a species history snapshot when needed.
|
|
103
|
-
|
|
104
|
-
This helper preserves a minimal per-generation history row for downstream
|
|
105
|
-
readers that expect species-history evidence even when the heavier extended
|
|
106
|
-
history path is disabled. It deliberately records only lightweight summary
|
|
107
|
-
fields, keeps one row per generation, and trims to a bounded rolling window
|
|
108
|
-
so evolve can maintain export-friendly evidence without turning this bridge
|
|
109
|
-
into the full history-enrichment layer.
|
|
110
|
-
|
|
111
|
-
Parameters:
|
|
112
|
-
- `internal` - - NEAT controller instance.
|
|
113
|
-
- `maxHistory` - - Maximum history length.
|
|
114
|
-
|
|
115
|
-
Returns: Nothing.
|
|
116
|
-
|
|
117
|
-
### updateSpeciesStagnationIfEnabled
|
|
123
|
+
### buildSpeciesHistoryStats
|
|
118
124
|
|
|
119
125
|
```ts
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
):
|
|
126
|
+
buildSpeciesHistoryStats(
|
|
127
|
+
speciesList: SpeciesWithMetadata[],
|
|
128
|
+
): { id: number; size: number; avgSharedFitness?: number | undefined; bestScore?: number | undefined; lastImproved?: number | undefined; }[]
|
|
123
129
|
```
|
|
124
130
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
The stagnation update remains optional because some evolve configurations use
|
|
128
|
-
the broader selection and replacement machinery without long-lived species
|
|
129
|
-
maintenance. When speciation is active, this helper advances the species-side
|
|
130
|
-
stagnation counters so later allocation and pruning decisions can distinguish
|
|
131
|
-
between active lineages and species that have stopped improving.
|
|
131
|
+
Build the minimal species-history row shape used by evolve-side snapshots.
|
|
132
132
|
|
|
133
133
|
Parameters:
|
|
134
|
-
- `
|
|
134
|
+
- `speciesList` - - Live species registry for the current generation.
|
|
135
135
|
|
|
136
|
-
Returns:
|
|
136
|
+
Returns: Summary rows aligned with the shared species history contract.
|
|
137
137
|
|
|
138
|
-
###
|
|
138
|
+
### ensureHiddenNodeVariance
|
|
139
139
|
|
|
140
140
|
```ts
|
|
141
|
-
|
|
141
|
+
ensureHiddenNodeVariance(
|
|
142
142
|
internal: NeatControllerForEvolution,
|
|
143
|
-
|
|
143
|
+
genome: GenomeWithMetadata,
|
|
144
144
|
): Promise<void>
|
|
145
145
|
```
|
|
146
146
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
This is the evolve loop's constrained recovery valve for long periods without
|
|
150
|
-
global improvement. Instead of discarding the whole population or rebuilding
|
|
151
|
-
the generation logic from scratch, the helper replaces only the worst-ranked
|
|
152
|
-
fraction beyond elitism with fresh genomes, then resets the stagnation window
|
|
153
|
-
so the controller can test whether the new search seeds reopen progress.
|
|
154
|
-
|
|
155
|
-
The design is intentionally conservative:
|
|
147
|
+
Ensure a minimal hidden-node variance in injected genomes.
|
|
156
148
|
|
|
157
|
-
-
|
|
158
|
-
|
|
159
|
-
|
|
149
|
+
Fresh stagnation-recovery genomes can otherwise collapse into the smallest
|
|
150
|
+
legal topology and fail to contribute structural novelty. This helper adds
|
|
151
|
+
one conservative hidden-node bridge when the injected genome has no hidden
|
|
152
|
+
layer at all, preserving the idea that rescue should re-open search space
|
|
153
|
+
rather than only reshuffle minimal direct input-output paths.
|
|
160
154
|
|
|
161
155
|
Parameters:
|
|
162
156
|
- `internal` - - NEAT controller instance.
|
|
163
|
-
- `
|
|
164
|
-
- `helpers` - - Genome builder for injection.
|
|
157
|
+
- `genome` - - Genome to adjust.
|
|
165
158
|
|
|
166
|
-
Returns: A promise that resolves after
|
|
159
|
+
Returns: A promise that resolves after best-effort variance injection.
|
|
167
160
|
|
|
168
161
|
### ensureSpeciesHistorySnapshot
|
|
169
162
|
|
|
@@ -188,40 +181,47 @@ Parameters:
|
|
|
188
181
|
|
|
189
182
|
Returns: Nothing.
|
|
190
183
|
|
|
191
|
-
###
|
|
184
|
+
### recordSpeciesHistorySnapshot
|
|
192
185
|
|
|
193
186
|
```ts
|
|
194
|
-
|
|
187
|
+
recordSpeciesHistorySnapshot(
|
|
195
188
|
internal: NeatControllerForEvolution,
|
|
196
|
-
|
|
197
|
-
):
|
|
189
|
+
maxHistory: number,
|
|
190
|
+
): void
|
|
198
191
|
```
|
|
199
192
|
|
|
200
|
-
|
|
193
|
+
Record a species history snapshot when needed.
|
|
201
194
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
195
|
+
This helper preserves a minimal per-generation history row for downstream
|
|
196
|
+
readers that expect species-history evidence even when the heavier extended
|
|
197
|
+
history path is disabled. It deliberately records only lightweight summary
|
|
198
|
+
fields, keeps one row per generation, and trims to a bounded rolling window
|
|
199
|
+
so evolve can maintain export-friendly evidence without turning this bridge
|
|
200
|
+
into the full history-enrichment layer.
|
|
207
201
|
|
|
208
202
|
Parameters:
|
|
209
203
|
- `internal` - - NEAT controller instance.
|
|
210
|
-
- `
|
|
204
|
+
- `maxHistory` - - Maximum history length.
|
|
211
205
|
|
|
212
|
-
Returns:
|
|
206
|
+
Returns: Nothing.
|
|
213
207
|
|
|
214
|
-
###
|
|
208
|
+
### updateSpeciesStagnationIfEnabled
|
|
215
209
|
|
|
216
210
|
```ts
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
):
|
|
211
|
+
updateSpeciesStagnationIfEnabled(
|
|
212
|
+
internal: NeatControllerForEvolution,
|
|
213
|
+
): void
|
|
220
214
|
```
|
|
221
215
|
|
|
222
|
-
|
|
216
|
+
Update species stagnation status when speciation enabled.
|
|
217
|
+
|
|
218
|
+
The stagnation update remains optional because some evolve configurations use
|
|
219
|
+
the broader selection and replacement machinery without long-lived species
|
|
220
|
+
maintenance. When speciation is active, this helper advances the species-side
|
|
221
|
+
stagnation counters so later allocation and pruning decisions can distinguish
|
|
222
|
+
between active lineages and species that have stopped improving.
|
|
223
223
|
|
|
224
224
|
Parameters:
|
|
225
|
-
- `
|
|
225
|
+
- `internal` - - NEAT controller instance.
|
|
226
226
|
|
|
227
|
-
Returns:
|
|
227
|
+
Returns: Nothing.
|
|
@@ -19,6 +19,16 @@ Read this chapter when you want to understand:
|
|
|
19
19
|
|
|
20
20
|
## neat/evolve/warnings/evolve.warnings.utils.ts
|
|
21
21
|
|
|
22
|
+
### EVOLVE_NO_BEST_GENOME_WARNING
|
|
23
|
+
|
|
24
|
+
Warning emitted when evolution finishes without a best genome.
|
|
25
|
+
|
|
26
|
+
This message signals that the generation loop completed without producing a
|
|
27
|
+
champion snapshot that the controller considers safe to return. That usually
|
|
28
|
+
points to an upstream evaluation or population-state problem rather than to a
|
|
29
|
+
normal low-fitness generation, so the wording intentionally distinguishes
|
|
30
|
+
"no valid best genome" from merely "no improvement."
|
|
31
|
+
|
|
22
32
|
### warnIfNoBestGenome
|
|
23
33
|
|
|
24
34
|
```ts
|
|
@@ -31,13 +41,3 @@ The helper is deliberately conservative: it tries to warn, but it does not
|
|
|
31
41
|
let missing or restricted console support destabilize the evolve loop further.
|
|
32
42
|
That keeps warning emission informative for normal runtimes while preserving a
|
|
33
43
|
best-effort contract for test harnesses and embedded environments.
|
|
34
|
-
|
|
35
|
-
### EVOLVE_NO_BEST_GENOME_WARNING
|
|
36
|
-
|
|
37
|
-
Warning emitted when evolution finishes without a best genome.
|
|
38
|
-
|
|
39
|
-
This message signals that the generation loop completed without producing a
|
|
40
|
-
champion snapshot that the controller considers safe to return. That usually
|
|
41
|
-
points to an upstream evaluation or population-state problem rather than to a
|
|
42
|
-
normal low-fitness generation, so the wording intentionally distinguishes
|
|
43
|
-
"no valid best genome" from merely "no improvement."
|
|
@@ -70,38 +70,6 @@ fs.writeFileSync('population.json', JSON.stringify(popSnapshot, null, 2));
|
|
|
70
70
|
|
|
71
71
|
Returns: Array of genome JSON objects.
|
|
72
72
|
|
|
73
|
-
### importPopulation
|
|
74
|
-
|
|
75
|
-
```ts
|
|
76
|
-
importPopulation(
|
|
77
|
-
populationJSON: GenomeJSON[],
|
|
78
|
-
): Promise<void>
|
|
79
|
-
```
|
|
80
|
-
|
|
81
|
-
Import (replace) the current population from an array of serialized genomes.
|
|
82
|
-
This does not touch NEAT meta state (generation, innovations, etc.) - only the
|
|
83
|
-
population array and implied `popsize` are updated.
|
|
84
|
-
That makes it the right tool when you want to swap candidate solutions into an
|
|
85
|
-
existing controller context instead of restoring a full historical checkpoint.
|
|
86
|
-
|
|
87
|
-
Example:
|
|
88
|
-
|
|
89
|
-
```ts
|
|
90
|
-
const populationData: GenomeJSON[] = JSON.parse(fs.readFileSync('population.json', 'utf8'));
|
|
91
|
-
neat.importPopulation(populationData); // population replaced
|
|
92
|
-
neat.evolve(); // continue evolving with new starting genomes
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
Edge cases handled:
|
|
96
|
-
- Empty array => becomes an empty population (popsize=0).
|
|
97
|
-
- Malformed entries will throw if `Network.fromJSON` rejects them.
|
|
98
|
-
|
|
99
|
-
Parameters:
|
|
100
|
-
- `populationJSON` - Array of serialized genome objects.
|
|
101
|
-
|
|
102
|
-
Returns: Promise that resolves once all genomes have been rehydrated and the
|
|
103
|
-
controller population has been replaced.
|
|
104
|
-
|
|
105
73
|
### exportState
|
|
106
74
|
|
|
107
75
|
```ts
|
|
@@ -128,68 +96,6 @@ const neat2 = Neat.importState(raw, fitnessFn); // identical evolutionary contex
|
|
|
128
96
|
|
|
129
97
|
Returns: A {@link NeatStateJSON} bundle containing meta + population.
|
|
130
98
|
|
|
131
|
-
### importStateImpl
|
|
132
|
-
|
|
133
|
-
```ts
|
|
134
|
-
importStateImpl(
|
|
135
|
-
stateBundle: NeatStateJSON,
|
|
136
|
-
fitnessFunction: (network: GenomeWithSerialization) => number | Promise<number>,
|
|
137
|
-
): Promise<NeatControllerForExport>
|
|
138
|
-
```
|
|
139
|
-
|
|
140
|
-
Static-style helper that rehydrates a full evolutionary state previously
|
|
141
|
-
produced by {@link exportState}. Invoke this with the NEAT class (not an
|
|
142
|
-
instance) bound as `this`, e.g. `Neat.importStateImpl(bundle, fitnessFn)`.
|
|
143
|
-
It constructs a new NEAT instance using the meta data, then imports the
|
|
144
|
-
population (if present).
|
|
145
|
-
|
|
146
|
-
This is the most complete restore path in the chapter. If a saved bundle is
|
|
147
|
-
valid, the caller gets back a fresh controller that knows both where the run
|
|
148
|
-
was in evolutionary time and which genomes were alive at that moment.
|
|
149
|
-
|
|
150
|
-
Safety and validation:
|
|
151
|
-
- Throws if the bundle is not an object.
|
|
152
|
-
- Silently skips population import if `population` is missing or not an array.
|
|
153
|
-
|
|
154
|
-
Example:
|
|
155
|
-
|
|
156
|
-
```ts
|
|
157
|
-
const bundle: NeatStateJSON = JSON.parse(fs.readFileSync('state.json', 'utf8'));
|
|
158
|
-
const neat = Neat.importStateImpl(bundle, fitnessFn);
|
|
159
|
-
neat.evolve();
|
|
160
|
-
```
|
|
161
|
-
|
|
162
|
-
Parameters:
|
|
163
|
-
- `stateBundle` - Full state bundle from {@link exportState} .
|
|
164
|
-
- `fitnessFunction` - Fitness evaluation callback used for new instance.
|
|
165
|
-
|
|
166
|
-
Returns: Rehydrated NEAT instance ready to continue evolving.
|
|
167
|
-
|
|
168
|
-
### toJSONImpl
|
|
169
|
-
|
|
170
|
-
```ts
|
|
171
|
-
toJSONImpl(): NeatMetaJSON
|
|
172
|
-
```
|
|
173
|
-
|
|
174
|
-
Serialize NEAT meta (excluding the mutable population) for persistence of
|
|
175
|
-
innovation history and experiment configuration. This is sufficient to
|
|
176
|
-
recreate a blank NEAT run at the same evolutionary generation with the same
|
|
177
|
-
innovation counters, enabling deterministic continuation when combined later
|
|
178
|
-
with a saved population.
|
|
179
|
-
|
|
180
|
-
Use this path when the controller context matters but the population payload
|
|
181
|
-
should be stored, transferred, or versioned separately.
|
|
182
|
-
|
|
183
|
-
Example:
|
|
184
|
-
|
|
185
|
-
```ts
|
|
186
|
-
const meta = neat.toJSONImpl();
|
|
187
|
-
fs.writeFileSync('neat-meta.json', JSON.stringify(meta));
|
|
188
|
-
// ... later ...
|
|
189
|
-
const metaLoaded = JSON.parse(fs.readFileSync('neat-meta.json', 'utf8')) as NeatMetaJSON;
|
|
190
|
-
const neat2 = Neat.fromJSONImpl(metaLoaded, fitnessFn); // empty population
|
|
191
|
-
```
|
|
192
|
-
|
|
193
99
|
### fromJSONImpl
|
|
194
100
|
|
|
195
101
|
```ts
|
|
@@ -234,21 +140,81 @@ export helpers preserve whatever `Network#toJSON()` emits, which lets the
|
|
|
234
140
|
broader architecture evolve without forcing this chapter to hard-code every
|
|
235
141
|
possible serialized field.
|
|
236
142
|
|
|
237
|
-
###
|
|
143
|
+
### GenomeWithSerialization
|
|
238
144
|
|
|
239
|
-
|
|
240
|
-
population genomes. This allows you to persist and resume experiment context
|
|
241
|
-
without committing to a particular population snapshot.
|
|
145
|
+
Genome with toJSON serialization method.
|
|
242
146
|
|
|
243
|
-
|
|
147
|
+
This is the smallest runtime contract needed by the export helpers when they
|
|
148
|
+
only care about turning one genome into a JSON payload.
|
|
244
149
|
|
|
245
|
-
|
|
246
|
-
serialized genomes (population). This is what you get from `exportState()` and
|
|
247
|
-
feed into `importStateImpl()` to resume exactly where you left off.
|
|
150
|
+
### importPopulation
|
|
248
151
|
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
152
|
+
```ts
|
|
153
|
+
importPopulation(
|
|
154
|
+
populationJSON: GenomeJSON[],
|
|
155
|
+
): Promise<void>
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
Import (replace) the current population from an array of serialized genomes.
|
|
159
|
+
This does not touch NEAT meta state (generation, innovations, etc.) - only the
|
|
160
|
+
population array and implied `popsize` are updated.
|
|
161
|
+
That makes it the right tool when you want to swap candidate solutions into an
|
|
162
|
+
existing controller context instead of restoring a full historical checkpoint.
|
|
163
|
+
|
|
164
|
+
Example:
|
|
165
|
+
|
|
166
|
+
```ts
|
|
167
|
+
const populationData: GenomeJSON[] = JSON.parse(fs.readFileSync('population.json', 'utf8'));
|
|
168
|
+
neat.importPopulation(populationData); // population replaced
|
|
169
|
+
neat.evolve(); // continue evolving with new starting genomes
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
Edge cases handled:
|
|
173
|
+
- Empty array => becomes an empty population (popsize=0).
|
|
174
|
+
- Malformed entries will throw if `Network.fromJSON` rejects them.
|
|
175
|
+
|
|
176
|
+
Parameters:
|
|
177
|
+
- `populationJSON` - Array of serialized genome objects.
|
|
178
|
+
|
|
179
|
+
Returns: Promise that resolves once all genomes have been rehydrated and the
|
|
180
|
+
controller population has been replaced.
|
|
181
|
+
|
|
182
|
+
### importStateImpl
|
|
183
|
+
|
|
184
|
+
```ts
|
|
185
|
+
importStateImpl(
|
|
186
|
+
stateBundle: NeatStateJSON,
|
|
187
|
+
fitnessFunction: (network: GenomeWithSerialization) => number | Promise<number>,
|
|
188
|
+
): Promise<NeatControllerForExport>
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
Static-style helper that rehydrates a full evolutionary state previously
|
|
192
|
+
produced by {@link exportState}. Invoke this with the NEAT class (not an
|
|
193
|
+
instance) bound as `this`, e.g. `Neat.importStateImpl(bundle, fitnessFn)`.
|
|
194
|
+
It constructs a new NEAT instance using the meta data, then imports the
|
|
195
|
+
population (if present).
|
|
196
|
+
|
|
197
|
+
This is the most complete restore path in the chapter. If a saved bundle is
|
|
198
|
+
valid, the caller gets back a fresh controller that knows both where the run
|
|
199
|
+
was in evolutionary time and which genomes were alive at that moment.
|
|
200
|
+
|
|
201
|
+
Safety and validation:
|
|
202
|
+
- Throws if the bundle is not an object.
|
|
203
|
+
- Silently skips population import if `population` is missing or not an array.
|
|
204
|
+
|
|
205
|
+
Example:
|
|
206
|
+
|
|
207
|
+
```ts
|
|
208
|
+
const bundle: NeatStateJSON = JSON.parse(fs.readFileSync('state.json', 'utf8'));
|
|
209
|
+
const neat = Neat.importStateImpl(bundle, fitnessFn);
|
|
210
|
+
neat.evolve();
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
Parameters:
|
|
214
|
+
- `stateBundle` - Full state bundle from {@link exportState} .
|
|
215
|
+
- `fitnessFunction` - Fitness evaluation callback used for new instance.
|
|
216
|
+
|
|
217
|
+
Returns: Rehydrated NEAT instance ready to continue evolving.
|
|
252
218
|
|
|
253
219
|
### InnovationMapEntry
|
|
254
220
|
|
|
@@ -257,12 +223,13 @@ Connection innovation map entry.
|
|
|
257
223
|
Innovation maps are serialized as `[key, value]` tuples so they can round-trip
|
|
258
224
|
cleanly through JSON and later be restored into `Map` instances.
|
|
259
225
|
|
|
260
|
-
###
|
|
226
|
+
### NeatConstructor
|
|
261
227
|
|
|
262
|
-
|
|
228
|
+
NEAT class constructor interface.
|
|
263
229
|
|
|
264
|
-
|
|
265
|
-
|
|
230
|
+
Static-style restore helpers depend on this constructor shape so they can
|
|
231
|
+
rebuild a controller instance from persisted meta data and then optionally
|
|
232
|
+
rehydrate the population.
|
|
266
233
|
|
|
267
234
|
### NeatControllerForExport
|
|
268
235
|
|
|
@@ -273,6 +240,22 @@ of the concrete `Neat` class. That keeps export and restore logic reusable in
|
|
|
273
240
|
tests and static-style helper flows without coupling the file to the full
|
|
274
241
|
controller implementation.
|
|
275
242
|
|
|
243
|
+
### NeatMetaJSON
|
|
244
|
+
|
|
245
|
+
Serialized meta information describing a NEAT run, excluding the concrete
|
|
246
|
+
population genomes. This allows you to persist and resume experiment context
|
|
247
|
+
without committing to a particular population snapshot.
|
|
248
|
+
|
|
249
|
+
### NeatStateJSON
|
|
250
|
+
|
|
251
|
+
Top-level bundle containing both NEAT meta information and the full array of
|
|
252
|
+
serialized genomes (population). This is what you get from `exportState()` and
|
|
253
|
+
feed into `importStateImpl()` to resume exactly where you left off.
|
|
254
|
+
|
|
255
|
+
If `NeatMetaJSON` is the controller checkpoint and `GenomeJSON[]` is the pool
|
|
256
|
+
of candidate solutions, `NeatStateJSON` is the combined pause-and-resume
|
|
257
|
+
artifact that preserves both layers together.
|
|
258
|
+
|
|
276
259
|
### NetworkClass
|
|
277
260
|
|
|
278
261
|
Network class with static fromJSON method.
|
|
@@ -280,10 +263,27 @@ Network class with static fromJSON method.
|
|
|
280
263
|
Import helpers use this contract when rebuilding genomes from serialized JSON
|
|
281
264
|
without needing to know the concrete network implementation details.
|
|
282
265
|
|
|
283
|
-
###
|
|
266
|
+
### toJSONImpl
|
|
284
267
|
|
|
285
|
-
|
|
268
|
+
```ts
|
|
269
|
+
toJSONImpl(): NeatMetaJSON
|
|
270
|
+
```
|
|
286
271
|
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
272
|
+
Serialize NEAT meta (excluding the mutable population) for persistence of
|
|
273
|
+
innovation history and experiment configuration. This is sufficient to
|
|
274
|
+
recreate a blank NEAT run at the same evolutionary generation with the same
|
|
275
|
+
innovation counters, enabling deterministic continuation when combined later
|
|
276
|
+
with a saved population.
|
|
277
|
+
|
|
278
|
+
Use this path when the controller context matters but the population payload
|
|
279
|
+
should be stored, transferred, or versioned separately.
|
|
280
|
+
|
|
281
|
+
Example:
|
|
282
|
+
|
|
283
|
+
```ts
|
|
284
|
+
const meta = neat.toJSONImpl();
|
|
285
|
+
fs.writeFileSync('neat-meta.json', JSON.stringify(meta));
|
|
286
|
+
// ... later ...
|
|
287
|
+
const metaLoaded = JSON.parse(fs.readFileSync('neat-meta.json', 'utf8')) as NeatMetaJSON;
|
|
288
|
+
const neat2 = Neat.fromJSONImpl(metaLoaded, fitnessFn); // empty population
|
|
289
|
+
```
|
|
@@ -51,56 +51,6 @@ cross the boundary into the live population in a normalized state?
|
|
|
51
51
|
|
|
52
52
|
## neat/helpers/neat.helpers.ts
|
|
53
53
|
|
|
54
|
-
### spawnFromParent
|
|
55
|
-
|
|
56
|
-
```ts
|
|
57
|
-
spawnFromParent(
|
|
58
|
-
parentGenome: GenomeWithMetadata,
|
|
59
|
-
mutateCount: number,
|
|
60
|
-
): Promise<GenomeWithMetadata>
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
Spawn (clone & mutate) a child genome from an existing parent genome.
|
|
64
|
-
|
|
65
|
-
Read this helper as the provisional provenance path. It produces a candidate
|
|
66
|
-
offspring whose lineage is already meaningful, but whose membership in the
|
|
67
|
-
active population is still undecided. That split is important when a caller
|
|
68
|
-
wants to preview, filter, score, or compare several children before allowing
|
|
69
|
-
one of them to join the population through {@link addGenome}.
|
|
70
|
-
|
|
71
|
-
Evolutionary rationale:
|
|
72
|
-
- Cloning preserves the full topology and weights of the parent.
|
|
73
|
-
- A configurable number of mutation passes are applied sequentially; each
|
|
74
|
-
pass may alter structure (add/remove nodes or connections) or weights.
|
|
75
|
-
- Lineage annotations (`_parents`, `_depth`) enable later analytics such as
|
|
76
|
-
diversity statistics, genealogy visualization, and pruning heuristics.
|
|
77
|
-
- Cache invalidation happens before the child is returned so later admission
|
|
78
|
-
or evaluation logic never observes stale derived state from the clone.
|
|
79
|
-
|
|
80
|
-
Robustness philosophy: individual mutation failures are silently ignored so a
|
|
81
|
-
single stochastic edge case does not derail evolutionary progress.
|
|
82
|
-
|
|
83
|
-
Parameters:
|
|
84
|
-
- `this` - Bound NEAT instance (inferred when used as a method).
|
|
85
|
-
- `parentGenome` - Parent genome/network to clone. Must implement either
|
|
86
|
-
`clone()` OR a pair of `toJSON()` / static `fromJSON()` for deep copying.
|
|
87
|
-
- `mutateCount` - Number of sequential mutation operations to attempt; each
|
|
88
|
-
iteration chooses a mutation method using the instance's selection
|
|
89
|
-
logic. Defaults to 1 for conservative structural drift.
|
|
90
|
-
|
|
91
|
-
Returns: A new genome whose score and derived caches are reset, whose lineage
|
|
92
|
-
metadata references the parent, and whose final admission into the
|
|
93
|
-
live population is left to the caller.
|
|
94
|
-
|
|
95
|
-
Example:
|
|
96
|
-
|
|
97
|
-
```ts
|
|
98
|
-
// Assume `neat` is an instance implementing NeatLike and `parent` is a genome in neat.population
|
|
99
|
-
const child = neat.spawnFromParent(parent, 3); // apply 3 mutation passes
|
|
100
|
-
// Optionally inspect / filter the child before adding
|
|
101
|
-
neat.addGenome(child, [parent._id]);
|
|
102
|
-
```
|
|
103
|
-
|
|
104
54
|
### addGenome
|
|
105
55
|
|
|
106
56
|
```ts
|
|
@@ -230,3 +180,53 @@ In practice this seam protects two invariants:
|
|
|
230
180
|
- every entering genome receives the same controller-owned metadata shape,
|
|
231
181
|
- every entry path applies the same best-effort cleanup before later chapters
|
|
232
182
|
read the genome.
|
|
183
|
+
|
|
184
|
+
### spawnFromParent
|
|
185
|
+
|
|
186
|
+
```ts
|
|
187
|
+
spawnFromParent(
|
|
188
|
+
parentGenome: GenomeWithMetadata,
|
|
189
|
+
mutateCount: number,
|
|
190
|
+
): Promise<GenomeWithMetadata>
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
Spawn (clone & mutate) a child genome from an existing parent genome.
|
|
194
|
+
|
|
195
|
+
Read this helper as the provisional provenance path. It produces a candidate
|
|
196
|
+
offspring whose lineage is already meaningful, but whose membership in the
|
|
197
|
+
active population is still undecided. That split is important when a caller
|
|
198
|
+
wants to preview, filter, score, or compare several children before allowing
|
|
199
|
+
one of them to join the population through {@link addGenome}.
|
|
200
|
+
|
|
201
|
+
Evolutionary rationale:
|
|
202
|
+
- Cloning preserves the full topology and weights of the parent.
|
|
203
|
+
- A configurable number of mutation passes are applied sequentially; each
|
|
204
|
+
pass may alter structure (add/remove nodes or connections) or weights.
|
|
205
|
+
- Lineage annotations (`_parents`, `_depth`) enable later analytics such as
|
|
206
|
+
diversity statistics, genealogy visualization, and pruning heuristics.
|
|
207
|
+
- Cache invalidation happens before the child is returned so later admission
|
|
208
|
+
or evaluation logic never observes stale derived state from the clone.
|
|
209
|
+
|
|
210
|
+
Robustness philosophy: individual mutation failures are silently ignored so a
|
|
211
|
+
single stochastic edge case does not derail evolutionary progress.
|
|
212
|
+
|
|
213
|
+
Parameters:
|
|
214
|
+
- `this` - Bound NEAT instance (inferred when used as a method).
|
|
215
|
+
- `parentGenome` - Parent genome/network to clone. Must implement either
|
|
216
|
+
`clone()` OR a pair of `toJSON()` / static `fromJSON()` for deep copying.
|
|
217
|
+
- `mutateCount` - Number of sequential mutation operations to attempt; each
|
|
218
|
+
iteration chooses a mutation method using the instance's selection
|
|
219
|
+
logic. Defaults to 1 for conservative structural drift.
|
|
220
|
+
|
|
221
|
+
Returns: A new genome whose score and derived caches are reset, whose lineage
|
|
222
|
+
metadata references the parent, and whose final admission into the
|
|
223
|
+
live population is left to the caller.
|
|
224
|
+
|
|
225
|
+
Example:
|
|
226
|
+
|
|
227
|
+
```ts
|
|
228
|
+
// Assume `neat` is an instance implementing NeatLike and `parent` is a genome in neat.population
|
|
229
|
+
const child = neat.spawnFromParent(parent, 3); // apply 3 mutation passes
|
|
230
|
+
// Optionally inspect / filter the child before adding
|
|
231
|
+
neat.addGenome(child, [parent._id]);
|
|
232
|
+
```
|
package/src/neat/init/README.md
CHANGED
|
@@ -118,6 +118,15 @@ After the call returns, the instance has concrete startup policy, prepared
|
|
|
118
118
|
controller state, and either an attempted generation-zero pool or a safely
|
|
119
119
|
preserved empty population ready for later work.
|
|
120
120
|
|
|
121
|
+
### InitializeNeatConstructorRequest
|
|
122
|
+
|
|
123
|
+
Mutable constructor request packet consumed during bootstrap.
|
|
124
|
+
|
|
125
|
+
`optionBag` is the live options object that the public facade keeps after the
|
|
126
|
+
constructor returns, `rawOptions` preserves the caller's original intent for
|
|
127
|
+
checks that should not be default-inflated, and `defaults` supplies the
|
|
128
|
+
public baseline constants exported by the surrounding NEAT surface.
|
|
129
|
+
|
|
121
130
|
### NeatConstructorDefaults
|
|
122
131
|
|
|
123
132
|
### NeatInitializationHost
|
|
@@ -129,12 +138,3 @@ helper needs write access to a few controller-owned fields and one pool
|
|
|
129
138
|
creation hook, but it does not own evaluation, evolution, or persistence.
|
|
130
139
|
Keeping the contract narrow prevents the init chapter from quietly becoming a
|
|
131
140
|
second facade.
|
|
132
|
-
|
|
133
|
-
### InitializeNeatConstructorRequest
|
|
134
|
-
|
|
135
|
-
Mutable constructor request packet consumed during bootstrap.
|
|
136
|
-
|
|
137
|
-
`optionBag` is the live options object that the public facade keeps after the
|
|
138
|
-
constructor returns, `rawOptions` preserves the caller's original intent for
|
|
139
|
-
checks that should not be default-inflated, and `defaults` supplies the
|
|
140
|
-
public baseline constants exported by the surrounding NEAT surface.
|