@reicek/neataptic-ts 0.1.24 → 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/.github/workflows/ci.yml +3 -3
- package/.github/workflows/deploy-pages.yml +6 -6
- package/.github/workflows/manual_release_pipeline.yml +3 -3
- package/.github/workflows/publish.yml +18 -19
- package/.github/workflows/release_dispatch.yml +3 -3
- package/package.json +26 -20
- 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
package/src/neat/rng/README.md
CHANGED
|
@@ -87,73 +87,28 @@ const replayedSample = getOrCreateRng(neat)();
|
|
|
87
87
|
|
|
88
88
|
## neat/rng/rng.ts
|
|
89
89
|
|
|
90
|
-
###
|
|
91
|
-
|
|
92
|
-
Odd scramble factor used while deriving a default seed from time and host
|
|
93
|
-
context.
|
|
94
|
-
|
|
95
|
-
This constant helps mix the fallback seed path before the xorshift stream is
|
|
96
|
-
ever created. It matters only when callers did not already provide an RNG,
|
|
97
|
-
explicit seed, or restored numeric state.
|
|
98
|
-
|
|
99
|
-
### RNG_DEFAULT_SEED_FALLBACK
|
|
100
|
-
|
|
101
|
-
Fallback seed used when the derived or restored seed would otherwise be zero.
|
|
102
|
-
|
|
103
|
-
Xorshift32 cannot advance from a zero state, so this constant is the guarded
|
|
104
|
-
non-zero escape hatch that keeps initialization and restore flows valid.
|
|
105
|
-
It is the last-resort seed, not the normal source of entropy.
|
|
106
|
-
|
|
107
|
-
### RNG_SHIFT_LEFT_PRIMARY
|
|
108
|
-
|
|
109
|
-
Left-shift used by the first xorshift32 mixing step.
|
|
110
|
-
|
|
111
|
-
### RNG_SHIFT_RIGHT_PRIMARY
|
|
112
|
-
|
|
113
|
-
Right-shift used by the middle xorshift32 mixing step.
|
|
114
|
-
|
|
115
|
-
### RNG_SHIFT_LEFT_SECONDARY
|
|
116
|
-
|
|
117
|
-
Left-shift used by the final xorshift32 mixing step.
|
|
118
|
-
|
|
119
|
-
### RNG_NORMALIZATION_DIVISOR
|
|
120
|
-
|
|
121
|
-
Divisor used to normalize the 32-bit integer state into the `[0, 1)` range.
|
|
122
|
-
|
|
123
|
-
This is the final step that turns a deterministic integer state transition
|
|
124
|
-
into the floating-point random samples consumed by the controller. Keeping it
|
|
125
|
-
named makes the integer-state phase and the outward-facing sample phase read
|
|
126
|
-
like two explicit steps instead of one opaque formula.
|
|
127
|
-
|
|
128
|
-
### RNG_POPULATION_OFFSET
|
|
129
|
-
|
|
130
|
-
Minimum population offset added before time scrambling during default seeding.
|
|
131
|
-
|
|
132
|
-
The offset keeps empty or tiny populations from collapsing the derived seed
|
|
133
|
-
toward zero too easily during initialization. It exists to stabilize the
|
|
134
|
-
fallback path, not to encode a meaningful NEAT population heuristic.
|
|
90
|
+
### exportRngState
|
|
135
91
|
|
|
136
|
-
|
|
92
|
+
```ts
|
|
93
|
+
exportRngState(
|
|
94
|
+
host: RngHost,
|
|
95
|
+
): number | undefined
|
|
96
|
+
```
|
|
137
97
|
|
|
138
|
-
|
|
98
|
+
Export the current RNG state for persistence.
|
|
139
99
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
seeding, and the optional hooks that let callers override the default path.
|
|
100
|
+
Use this when deterministic replay must cross a broader boundary such as
|
|
101
|
+
JSON export, checkpointing, or test snapshots. The returned number is the
|
|
102
|
+
compact controller-facing representation of the current random stream.
|
|
144
103
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
104
|
+
Unlike `snapshotRngState()`, this helper is named for the portability use
|
|
105
|
+
case: the returned token is meant to leave the immediate call site and later
|
|
106
|
+
come back through `restoreRngState()` or `importRngState()`.
|
|
148
107
|
|
|
149
|
-
|
|
108
|
+
Parameters:
|
|
109
|
+
- `host` - - Object holding RNG state.
|
|
150
110
|
|
|
151
|
-
|
|
152
|
-
const host: RngHost = {
|
|
153
|
-
population: new Array(10),
|
|
154
|
-
options: { seed: 42 },
|
|
155
|
-
};
|
|
156
|
-
```
|
|
111
|
+
Returns: The numeric RNG state or undefined when not set.
|
|
157
112
|
|
|
158
113
|
### getOrCreateRng
|
|
159
114
|
|
|
@@ -195,29 +150,23 @@ const firstDraw = rng();
|
|
|
195
150
|
const checkpoint = snapshotRngState(neat);
|
|
196
151
|
```
|
|
197
152
|
|
|
198
|
-
###
|
|
153
|
+
### importRngState
|
|
199
154
|
|
|
200
155
|
```ts
|
|
201
|
-
|
|
156
|
+
importRngState(
|
|
202
157
|
host: RngHost,
|
|
203
|
-
|
|
158
|
+
state: string | number | undefined,
|
|
159
|
+
): void
|
|
204
160
|
```
|
|
205
161
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
Use this when you want an in-memory checkpoint before a risky controller
|
|
209
|
-
action such as a mutation batch, debugging session, or deterministic test.
|
|
210
|
-
Unlike exporting a whole controller state, this is the smallest replay token:
|
|
211
|
-
it captures only the numeric RNG position.
|
|
162
|
+
Alias for restoring RNG state kept for compatibility with prior surface.
|
|
212
163
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
boundary such as JSON serialization, checkpoint files, or fixture snapshots.
|
|
164
|
+
This exists so older callers can keep using the import-style name while the
|
|
165
|
+
underlying behavior remains the same replay boundary as `restoreRngState()`.
|
|
216
166
|
|
|
217
167
|
Parameters:
|
|
218
168
|
- `host` - - Object holding RNG state.
|
|
219
|
-
|
|
220
|
-
Returns: The numeric RNG state or undefined when uninitialized.
|
|
169
|
+
- `state` - - Numeric RNG state to restore.
|
|
221
170
|
|
|
222
171
|
### restoreRngState
|
|
223
172
|
|
|
@@ -247,46 +196,73 @@ const savedState = exportRngState(neat);
|
|
|
247
196
|
restoreRngState(neat, savedState);
|
|
248
197
|
```
|
|
249
198
|
|
|
250
|
-
###
|
|
199
|
+
### RNG_DEFAULT_SEED_FALLBACK
|
|
251
200
|
|
|
252
|
-
|
|
253
|
-
importRngState(
|
|
254
|
-
host: RngHost,
|
|
255
|
-
state: string | number | undefined,
|
|
256
|
-
): void
|
|
257
|
-
```
|
|
201
|
+
Fallback seed used when the derived or restored seed would otherwise be zero.
|
|
258
202
|
|
|
259
|
-
|
|
203
|
+
Xorshift32 cannot advance from a zero state, so this constant is the guarded
|
|
204
|
+
non-zero escape hatch that keeps initialization and restore flows valid.
|
|
205
|
+
It is the last-resort seed, not the normal source of entropy.
|
|
260
206
|
|
|
261
|
-
|
|
262
|
-
underlying behavior remains the same replay boundary as `restoreRngState()`.
|
|
207
|
+
### RNG_NORMALIZATION_DIVISOR
|
|
263
208
|
|
|
264
|
-
|
|
265
|
-
- `host` - - Object holding RNG state.
|
|
266
|
-
- `state` - - Numeric RNG state to restore.
|
|
209
|
+
Divisor used to normalize the 32-bit integer state into the `[0, 1)` range.
|
|
267
210
|
|
|
268
|
-
|
|
211
|
+
This is the final step that turns a deterministic integer state transition
|
|
212
|
+
into the floating-point random samples consumed by the controller. Keeping it
|
|
213
|
+
named makes the integer-state phase and the outward-facing sample phase read
|
|
214
|
+
like two explicit steps instead of one opaque formula.
|
|
269
215
|
|
|
270
|
-
|
|
271
|
-
exportRngState(
|
|
272
|
-
host: RngHost,
|
|
273
|
-
): number | undefined
|
|
274
|
-
```
|
|
216
|
+
### RNG_POPULATION_OFFSET
|
|
275
217
|
|
|
276
|
-
|
|
218
|
+
Minimum population offset added before time scrambling during default seeding.
|
|
277
219
|
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
220
|
+
The offset keeps empty or tiny populations from collapsing the derived seed
|
|
221
|
+
toward zero too easily during initialization. It exists to stabilize the
|
|
222
|
+
fallback path, not to encode a meaningful NEAT population heuristic.
|
|
281
223
|
|
|
282
|
-
|
|
283
|
-
case: the returned token is meant to leave the immediate call site and later
|
|
284
|
-
come back through `restoreRngState()` or `importRngState()`.
|
|
224
|
+
### RNG_SHIFT_LEFT_PRIMARY
|
|
285
225
|
|
|
286
|
-
|
|
287
|
-
- `host` - - Object holding RNG state.
|
|
226
|
+
Left-shift used by the first xorshift32 mixing step.
|
|
288
227
|
|
|
289
|
-
|
|
228
|
+
### RNG_SHIFT_LEFT_SECONDARY
|
|
229
|
+
|
|
230
|
+
Left-shift used by the final xorshift32 mixing step.
|
|
231
|
+
|
|
232
|
+
### RNG_SHIFT_RIGHT_PRIMARY
|
|
233
|
+
|
|
234
|
+
Right-shift used by the middle xorshift32 mixing step.
|
|
235
|
+
|
|
236
|
+
### RNG_TIME_SCRAMBLE_CONSTANT
|
|
237
|
+
|
|
238
|
+
Odd scramble factor used while deriving a default seed from time and host
|
|
239
|
+
context.
|
|
240
|
+
|
|
241
|
+
This constant helps mix the fallback seed path before the xorshift stream is
|
|
242
|
+
ever created. It matters only when callers did not already provide an RNG,
|
|
243
|
+
explicit seed, or restored numeric state.
|
|
244
|
+
|
|
245
|
+
### RngHost
|
|
246
|
+
|
|
247
|
+
Minimal host surface required by the RNG replay utilities.
|
|
248
|
+
|
|
249
|
+
This contract is deliberately smaller than the full controller. The replay
|
|
250
|
+
helpers only need four kinds of state: the live RNG closure, the numeric
|
|
251
|
+
checkpoint behind that closure, a little population context for fallback
|
|
252
|
+
seeding, and the optional hooks that let callers override the default path.
|
|
253
|
+
|
|
254
|
+
That small seam is what makes deterministic replay portable. Tests,
|
|
255
|
+
diagnostics, import-export helpers, and the controller itself can all reuse
|
|
256
|
+
the same RNG utilities without pretending they share one large runtime type.
|
|
257
|
+
|
|
258
|
+
Example:
|
|
259
|
+
|
|
260
|
+
```ts
|
|
261
|
+
const host: RngHost = {
|
|
262
|
+
population: new Array(10),
|
|
263
|
+
options: { seed: 42 },
|
|
264
|
+
};
|
|
265
|
+
```
|
|
290
266
|
|
|
291
267
|
### sampleRandomSequence
|
|
292
268
|
|
|
@@ -321,3 +297,27 @@ const before = snapshotRngState(neat);
|
|
|
321
297
|
const samples = sampleRandomSequence(neat, 3);
|
|
322
298
|
restoreRngState(neat, before);
|
|
323
299
|
```
|
|
300
|
+
|
|
301
|
+
### snapshotRngState
|
|
302
|
+
|
|
303
|
+
```ts
|
|
304
|
+
snapshotRngState(
|
|
305
|
+
host: RngHost,
|
|
306
|
+
): number | undefined
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
Snapshot the current RNG state for deterministic replay.
|
|
310
|
+
|
|
311
|
+
Use this when you want an in-memory checkpoint before a risky controller
|
|
312
|
+
action such as a mutation batch, debugging session, or deterministic test.
|
|
313
|
+
Unlike exporting a whole controller state, this is the smallest replay token:
|
|
314
|
+
it captures only the numeric RNG position.
|
|
315
|
+
|
|
316
|
+
Prefer this helper when the state is staying in memory inside the current
|
|
317
|
+
process. Use `exportRngState()` when the same token is about to cross a wider
|
|
318
|
+
boundary such as JSON serialization, checkpoint files, or fixture snapshots.
|
|
319
|
+
|
|
320
|
+
Parameters:
|
|
321
|
+
- `host` - - Object holding RNG state.
|
|
322
|
+
|
|
323
|
+
Returns: The numeric RNG state or undefined when uninitialized.
|
|
@@ -76,27 +76,28 @@ The story is intentionally split into three shelves:
|
|
|
76
76
|
Read the chapter in that order when you want the whole lifecycle: host
|
|
77
77
|
state, stream creation, snapshot or export, then later restore.
|
|
78
78
|
|
|
79
|
-
###
|
|
79
|
+
### exportRngState
|
|
80
80
|
|
|
81
|
-
|
|
81
|
+
```ts
|
|
82
|
+
exportRngState(
|
|
83
|
+
host: RngHost,
|
|
84
|
+
): number | undefined
|
|
85
|
+
```
|
|
82
86
|
|
|
83
|
-
|
|
84
|
-
helpers only need four kinds of state: the live RNG closure, the numeric
|
|
85
|
-
checkpoint behind that closure, a little population context for fallback
|
|
86
|
-
seeding, and the optional hooks that let callers override the default path.
|
|
87
|
+
Export the current RNG state for persistence.
|
|
87
88
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
89
|
+
Use this when deterministic replay must cross a broader boundary such as
|
|
90
|
+
JSON export, checkpointing, or test snapshots. The returned number is the
|
|
91
|
+
compact controller-facing representation of the current random stream.
|
|
91
92
|
|
|
92
|
-
|
|
93
|
+
Unlike `snapshotRngState()`, this helper is named for the portability use
|
|
94
|
+
case: the returned token is meant to leave the immediate call site and later
|
|
95
|
+
come back through `restoreRngState()` or `importRngState()`.
|
|
93
96
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
};
|
|
99
|
-
```
|
|
97
|
+
Parameters:
|
|
98
|
+
- `host` - - Object holding RNG state.
|
|
99
|
+
|
|
100
|
+
Returns: The numeric RNG state or undefined when not set.
|
|
100
101
|
|
|
101
102
|
### getOrCreateRng
|
|
102
103
|
|
|
@@ -138,29 +139,23 @@ const firstDraw = rng();
|
|
|
138
139
|
const checkpoint = snapshotRngState(neat);
|
|
139
140
|
```
|
|
140
141
|
|
|
141
|
-
###
|
|
142
|
+
### importRngState
|
|
142
143
|
|
|
143
144
|
```ts
|
|
144
|
-
|
|
145
|
+
importRngState(
|
|
145
146
|
host: RngHost,
|
|
146
|
-
|
|
147
|
+
state: string | number | undefined,
|
|
148
|
+
): void
|
|
147
149
|
```
|
|
148
150
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
Use this when you want an in-memory checkpoint before a risky controller
|
|
152
|
-
action such as a mutation batch, debugging session, or deterministic test.
|
|
153
|
-
Unlike exporting a whole controller state, this is the smallest replay token:
|
|
154
|
-
it captures only the numeric RNG position.
|
|
151
|
+
Alias for restoring RNG state kept for compatibility with prior surface.
|
|
155
152
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
boundary such as JSON serialization, checkpoint files, or fixture snapshots.
|
|
153
|
+
This exists so older callers can keep using the import-style name while the
|
|
154
|
+
underlying behavior remains the same replay boundary as `restoreRngState()`.
|
|
159
155
|
|
|
160
156
|
Parameters:
|
|
161
157
|
- `host` - - Object holding RNG state.
|
|
162
|
-
|
|
163
|
-
Returns: The numeric RNG state or undefined when uninitialized.
|
|
158
|
+
- `state` - - Numeric RNG state to restore.
|
|
164
159
|
|
|
165
160
|
### restoreRngState
|
|
166
161
|
|
|
@@ -190,47 +185,28 @@ const savedState = exportRngState(neat);
|
|
|
190
185
|
restoreRngState(neat, savedState);
|
|
191
186
|
```
|
|
192
187
|
|
|
193
|
-
###
|
|
194
|
-
|
|
195
|
-
```ts
|
|
196
|
-
importRngState(
|
|
197
|
-
host: RngHost,
|
|
198
|
-
state: string | number | undefined,
|
|
199
|
-
): void
|
|
200
|
-
```
|
|
188
|
+
### RngHost
|
|
201
189
|
|
|
202
|
-
|
|
190
|
+
Minimal host surface required by the RNG replay utilities.
|
|
203
191
|
|
|
204
|
-
This
|
|
205
|
-
|
|
192
|
+
This contract is deliberately smaller than the full controller. The replay
|
|
193
|
+
helpers only need four kinds of state: the live RNG closure, the numeric
|
|
194
|
+
checkpoint behind that closure, a little population context for fallback
|
|
195
|
+
seeding, and the optional hooks that let callers override the default path.
|
|
206
196
|
|
|
207
|
-
|
|
208
|
-
-
|
|
209
|
-
|
|
197
|
+
That small seam is what makes deterministic replay portable. Tests,
|
|
198
|
+
diagnostics, import-export helpers, and the controller itself can all reuse
|
|
199
|
+
the same RNG utilities without pretending they share one large runtime type.
|
|
210
200
|
|
|
211
|
-
|
|
201
|
+
Example:
|
|
212
202
|
|
|
213
203
|
```ts
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
204
|
+
const host: RngHost = {
|
|
205
|
+
population: new Array(10),
|
|
206
|
+
options: { seed: 42 },
|
|
207
|
+
};
|
|
217
208
|
```
|
|
218
209
|
|
|
219
|
-
Export the current RNG state for persistence.
|
|
220
|
-
|
|
221
|
-
Use this when deterministic replay must cross a broader boundary such as
|
|
222
|
-
JSON export, checkpointing, or test snapshots. The returned number is the
|
|
223
|
-
compact controller-facing representation of the current random stream.
|
|
224
|
-
|
|
225
|
-
Unlike `snapshotRngState()`, this helper is named for the portability use
|
|
226
|
-
case: the returned token is meant to leave the immediate call site and later
|
|
227
|
-
come back through `restoreRngState()` or `importRngState()`.
|
|
228
|
-
|
|
229
|
-
Parameters:
|
|
230
|
-
- `host` - - Object holding RNG state.
|
|
231
|
-
|
|
232
|
-
Returns: The numeric RNG state or undefined when not set.
|
|
233
|
-
|
|
234
210
|
### sampleRandomSequence
|
|
235
211
|
|
|
236
212
|
```ts
|
|
@@ -265,16 +241,31 @@ const samples = sampleRandomSequence(neat, 3);
|
|
|
265
241
|
restoreRngState(neat, before);
|
|
266
242
|
```
|
|
267
243
|
|
|
268
|
-
|
|
244
|
+
### snapshotRngState
|
|
269
245
|
|
|
270
|
-
|
|
271
|
-
|
|
246
|
+
```ts
|
|
247
|
+
snapshotRngState(
|
|
248
|
+
host: RngHost,
|
|
249
|
+
): number | undefined
|
|
250
|
+
```
|
|
272
251
|
|
|
273
|
-
|
|
274
|
-
ever created. It matters only when callers did not already provide an RNG,
|
|
275
|
-
explicit seed, or restored numeric state.
|
|
252
|
+
Snapshot the current RNG state for deterministic replay.
|
|
276
253
|
|
|
277
|
-
|
|
254
|
+
Use this when you want an in-memory checkpoint before a risky controller
|
|
255
|
+
action such as a mutation batch, debugging session, or deterministic test.
|
|
256
|
+
Unlike exporting a whole controller state, this is the smallest replay token:
|
|
257
|
+
it captures only the numeric RNG position.
|
|
258
|
+
|
|
259
|
+
Prefer this helper when the state is staying in memory inside the current
|
|
260
|
+
process. Use `exportRngState()` when the same token is about to cross a wider
|
|
261
|
+
boundary such as JSON serialization, checkpoint files, or fixture snapshots.
|
|
262
|
+
|
|
263
|
+
Parameters:
|
|
264
|
+
- `host` - - Object holding RNG state.
|
|
265
|
+
|
|
266
|
+
Returns: The numeric RNG state or undefined when uninitialized.
|
|
267
|
+
|
|
268
|
+
## neat/rng/core/rng.constants.ts
|
|
278
269
|
|
|
279
270
|
Odd scramble factor used while deriving a default seed from time and host
|
|
280
271
|
context.
|
|
@@ -291,18 +282,6 @@ Xorshift32 cannot advance from a zero state, so this constant is the guarded
|
|
|
291
282
|
non-zero escape hatch that keeps initialization and restore flows valid.
|
|
292
283
|
It is the last-resort seed, not the normal source of entropy.
|
|
293
284
|
|
|
294
|
-
### RNG_SHIFT_LEFT_PRIMARY
|
|
295
|
-
|
|
296
|
-
Left-shift used by the first xorshift32 mixing step.
|
|
297
|
-
|
|
298
|
-
### RNG_SHIFT_RIGHT_PRIMARY
|
|
299
|
-
|
|
300
|
-
Right-shift used by the middle xorshift32 mixing step.
|
|
301
|
-
|
|
302
|
-
### RNG_SHIFT_LEFT_SECONDARY
|
|
303
|
-
|
|
304
|
-
Left-shift used by the final xorshift32 mixing step.
|
|
305
|
-
|
|
306
285
|
### RNG_NORMALIZATION_DIVISOR
|
|
307
286
|
|
|
308
287
|
Divisor used to normalize the 32-bit integer state into the `[0, 1)` range.
|
|
@@ -320,6 +299,27 @@ The offset keeps empty or tiny populations from collapsing the derived seed
|
|
|
320
299
|
toward zero too easily during initialization. It exists to stabilize the
|
|
321
300
|
fallback path, not to encode a meaningful NEAT population heuristic.
|
|
322
301
|
|
|
302
|
+
### RNG_SHIFT_LEFT_PRIMARY
|
|
303
|
+
|
|
304
|
+
Left-shift used by the first xorshift32 mixing step.
|
|
305
|
+
|
|
306
|
+
### RNG_SHIFT_LEFT_SECONDARY
|
|
307
|
+
|
|
308
|
+
Left-shift used by the final xorshift32 mixing step.
|
|
309
|
+
|
|
310
|
+
### RNG_SHIFT_RIGHT_PRIMARY
|
|
311
|
+
|
|
312
|
+
Right-shift used by the middle xorshift32 mixing step.
|
|
313
|
+
|
|
314
|
+
### RNG_TIME_SCRAMBLE_CONSTANT
|
|
315
|
+
|
|
316
|
+
Odd scramble factor used while deriving a default seed from time and host
|
|
317
|
+
context.
|
|
318
|
+
|
|
319
|
+
This constant helps mix the fallback seed path before the xorshift stream is
|
|
320
|
+
ever created. It matters only when callers did not already provide an RNG,
|
|
321
|
+
explicit seed, or restored numeric state.
|
|
322
|
+
|
|
323
323
|
## neat/rng/core/rng.utils.ts
|
|
324
324
|
|
|
325
325
|
Replay utilities for the deterministic NEAT RNG.
|
|
@@ -335,6 +335,29 @@ care about different slices of that lifecycle. The controller mostly wants a
|
|
|
335
335
|
live RNG, tests often want checkpoints plus short sample runs, and export
|
|
336
336
|
logic usually only needs the compact numeric state.
|
|
337
337
|
|
|
338
|
+
### exportRngState
|
|
339
|
+
|
|
340
|
+
```ts
|
|
341
|
+
exportRngState(
|
|
342
|
+
host: RngHost,
|
|
343
|
+
): number | undefined
|
|
344
|
+
```
|
|
345
|
+
|
|
346
|
+
Export the current RNG state for persistence.
|
|
347
|
+
|
|
348
|
+
Use this when deterministic replay must cross a broader boundary such as
|
|
349
|
+
JSON export, checkpointing, or test snapshots. The returned number is the
|
|
350
|
+
compact controller-facing representation of the current random stream.
|
|
351
|
+
|
|
352
|
+
Unlike `snapshotRngState()`, this helper is named for the portability use
|
|
353
|
+
case: the returned token is meant to leave the immediate call site and later
|
|
354
|
+
come back through `restoreRngState()` or `importRngState()`.
|
|
355
|
+
|
|
356
|
+
Parameters:
|
|
357
|
+
- `host` - - Object holding RNG state.
|
|
358
|
+
|
|
359
|
+
Returns: The numeric RNG state or undefined when not set.
|
|
360
|
+
|
|
338
361
|
### getOrCreateRng
|
|
339
362
|
|
|
340
363
|
```ts
|
|
@@ -375,29 +398,23 @@ const firstDraw = rng();
|
|
|
375
398
|
const checkpoint = snapshotRngState(neat);
|
|
376
399
|
```
|
|
377
400
|
|
|
378
|
-
###
|
|
401
|
+
### importRngState
|
|
379
402
|
|
|
380
403
|
```ts
|
|
381
|
-
|
|
404
|
+
importRngState(
|
|
382
405
|
host: RngHost,
|
|
383
|
-
|
|
406
|
+
state: string | number | undefined,
|
|
407
|
+
): void
|
|
384
408
|
```
|
|
385
409
|
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
Use this when you want an in-memory checkpoint before a risky controller
|
|
389
|
-
action such as a mutation batch, debugging session, or deterministic test.
|
|
390
|
-
Unlike exporting a whole controller state, this is the smallest replay token:
|
|
391
|
-
it captures only the numeric RNG position.
|
|
410
|
+
Alias for restoring RNG state kept for compatibility with prior surface.
|
|
392
411
|
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
boundary such as JSON serialization, checkpoint files, or fixture snapshots.
|
|
412
|
+
This exists so older callers can keep using the import-style name while the
|
|
413
|
+
underlying behavior remains the same replay boundary as `restoreRngState()`.
|
|
396
414
|
|
|
397
415
|
Parameters:
|
|
398
416
|
- `host` - - Object holding RNG state.
|
|
399
|
-
|
|
400
|
-
Returns: The numeric RNG state or undefined when uninitialized.
|
|
417
|
+
- `state` - - Numeric RNG state to restore.
|
|
401
418
|
|
|
402
419
|
### restoreRngState
|
|
403
420
|
|
|
@@ -427,47 +444,6 @@ const savedState = exportRngState(neat);
|
|
|
427
444
|
restoreRngState(neat, savedState);
|
|
428
445
|
```
|
|
429
446
|
|
|
430
|
-
### importRngState
|
|
431
|
-
|
|
432
|
-
```ts
|
|
433
|
-
importRngState(
|
|
434
|
-
host: RngHost,
|
|
435
|
-
state: string | number | undefined,
|
|
436
|
-
): void
|
|
437
|
-
```
|
|
438
|
-
|
|
439
|
-
Alias for restoring RNG state kept for compatibility with prior surface.
|
|
440
|
-
|
|
441
|
-
This exists so older callers can keep using the import-style name while the
|
|
442
|
-
underlying behavior remains the same replay boundary as `restoreRngState()`.
|
|
443
|
-
|
|
444
|
-
Parameters:
|
|
445
|
-
- `host` - - Object holding RNG state.
|
|
446
|
-
- `state` - - Numeric RNG state to restore.
|
|
447
|
-
|
|
448
|
-
### exportRngState
|
|
449
|
-
|
|
450
|
-
```ts
|
|
451
|
-
exportRngState(
|
|
452
|
-
host: RngHost,
|
|
453
|
-
): number | undefined
|
|
454
|
-
```
|
|
455
|
-
|
|
456
|
-
Export the current RNG state for persistence.
|
|
457
|
-
|
|
458
|
-
Use this when deterministic replay must cross a broader boundary such as
|
|
459
|
-
JSON export, checkpointing, or test snapshots. The returned number is the
|
|
460
|
-
compact controller-facing representation of the current random stream.
|
|
461
|
-
|
|
462
|
-
Unlike `snapshotRngState()`, this helper is named for the portability use
|
|
463
|
-
case: the returned token is meant to leave the immediate call site and later
|
|
464
|
-
come back through `restoreRngState()` or `importRngState()`.
|
|
465
|
-
|
|
466
|
-
Parameters:
|
|
467
|
-
- `host` - - Object holding RNG state.
|
|
468
|
-
|
|
469
|
-
Returns: The numeric RNG state or undefined when not set.
|
|
470
|
-
|
|
471
447
|
### sampleRandomSequence
|
|
472
448
|
|
|
473
449
|
```ts
|
|
@@ -501,3 +477,27 @@ const before = snapshotRngState(neat);
|
|
|
501
477
|
const samples = sampleRandomSequence(neat, 3);
|
|
502
478
|
restoreRngState(neat, before);
|
|
503
479
|
```
|
|
480
|
+
|
|
481
|
+
### snapshotRngState
|
|
482
|
+
|
|
483
|
+
```ts
|
|
484
|
+
snapshotRngState(
|
|
485
|
+
host: RngHost,
|
|
486
|
+
): number | undefined
|
|
487
|
+
```
|
|
488
|
+
|
|
489
|
+
Snapshot the current RNG state for deterministic replay.
|
|
490
|
+
|
|
491
|
+
Use this when you want an in-memory checkpoint before a risky controller
|
|
492
|
+
action such as a mutation batch, debugging session, or deterministic test.
|
|
493
|
+
Unlike exporting a whole controller state, this is the smallest replay token:
|
|
494
|
+
it captures only the numeric RNG position.
|
|
495
|
+
|
|
496
|
+
Prefer this helper when the state is staying in memory inside the current
|
|
497
|
+
process. Use `exportRngState()` when the same token is about to cross a wider
|
|
498
|
+
boundary such as JSON serialization, checkpoint files, or fixture snapshots.
|
|
499
|
+
|
|
500
|
+
Parameters:
|
|
501
|
+
- `host` - - Object holding RNG state.
|
|
502
|
+
|
|
503
|
+
Returns: The numeric RNG state or undefined when uninitialized.
|