@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
|
@@ -20,20 +20,65 @@ Protocol flow at a glance:
|
|
|
20
20
|
|
|
21
21
|
## flappy-evolution-worker/flappy-evolution-worker.ts
|
|
22
22
|
|
|
23
|
-
###
|
|
23
|
+
### beginWorkerGenerationRequest
|
|
24
24
|
|
|
25
25
|
```ts
|
|
26
|
-
|
|
26
|
+
beginWorkerGenerationRequest(
|
|
27
|
+
workerMutableRuntimeState: WorkerMutableRuntimeState,
|
|
28
|
+
): void
|
|
27
29
|
```
|
|
28
30
|
|
|
29
|
-
|
|
31
|
+
Begins one asynchronous generation request and captures failures.
|
|
30
32
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
single dependency object through the orchestration helpers.
|
|
33
|
+
This is intentionally fire-and-forget from the protocol perspective. The
|
|
34
|
+
actual completion signal is the later `generation-ready` or `error` message
|
|
35
|
+
posted back to the host.
|
|
35
36
|
|
|
36
|
-
|
|
37
|
+
Parameters:
|
|
38
|
+
- `workerMutableRuntimeState` - - Mutable worker runtime state.
|
|
39
|
+
|
|
40
|
+
Returns: Nothing.
|
|
41
|
+
|
|
42
|
+
### beginWorkerInitialization
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
beginWorkerInitialization(
|
|
46
|
+
workerMutableRuntimeState: WorkerMutableRuntimeState,
|
|
47
|
+
initPayload: { populationSize: number; elitismCount: number; rngSeed: number; },
|
|
48
|
+
): void
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Begins worker initialization and captures asynchronous failures.
|
|
52
|
+
|
|
53
|
+
The worker retains the initialization promise so later generation requests can
|
|
54
|
+
await setup completion instead of racing against it.
|
|
55
|
+
|
|
56
|
+
Parameters:
|
|
57
|
+
- `workerMutableRuntimeState` - - Mutable worker runtime state.
|
|
58
|
+
- `initPayload` - - Initialization payload.
|
|
59
|
+
|
|
60
|
+
Returns: Nothing.
|
|
61
|
+
|
|
62
|
+
### beginWorkerPlayback
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
beginWorkerPlayback(
|
|
66
|
+
workerMutableRuntimeState: WorkerMutableRuntimeState,
|
|
67
|
+
payload: { visibleWorldWidthPx: number; visibleWorldHeightPx: number; },
|
|
68
|
+
): void
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Begins a new playback session from the current evolved population.
|
|
72
|
+
|
|
73
|
+
A playback session is a deterministic simulation snapshot seeded from the
|
|
74
|
+
current population. Each new session resets playback RNG and world state so
|
|
75
|
+
the host can replay generations cleanly.
|
|
76
|
+
|
|
77
|
+
Parameters:
|
|
78
|
+
- `workerMutableRuntimeState` - - Mutable worker runtime state.
|
|
79
|
+
- `payload` - - Playback start payload.
|
|
80
|
+
|
|
81
|
+
Returns: Nothing.
|
|
37
82
|
|
|
38
83
|
### createWorkerMessageHandler
|
|
39
84
|
|
|
@@ -60,6 +105,21 @@ Example:
|
|
|
60
105
|
self.onmessage = createWorkerMessageHandler(workerMutableRuntimeState);
|
|
61
106
|
```
|
|
62
107
|
|
|
108
|
+
### createWorkerMutableRuntimeState
|
|
109
|
+
|
|
110
|
+
```ts
|
|
111
|
+
createWorkerMutableRuntimeState(): WorkerMutableRuntimeState
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
Creates the mutable worker runtime state container.
|
|
115
|
+
|
|
116
|
+
Educational note:
|
|
117
|
+
The worker keeps one small mutable state bag instead of scattering globals.
|
|
118
|
+
That makes the protocol flow easier to explain and lets the entrypoint pass a
|
|
119
|
+
single dependency object through the orchestration helpers.
|
|
120
|
+
|
|
121
|
+
Returns: Mutable worker runtime state.
|
|
122
|
+
|
|
63
123
|
### createWorkerProtocolHandlers
|
|
64
124
|
|
|
65
125
|
```ts
|
|
@@ -79,31 +139,6 @@ Parameters:
|
|
|
79
139
|
|
|
80
140
|
Returns: Protocol handler bundle.
|
|
81
141
|
|
|
82
|
-
### initializeRuntime
|
|
83
|
-
|
|
84
|
-
```ts
|
|
85
|
-
initializeRuntime(
|
|
86
|
-
workerMutableRuntimeState: WorkerMutableRuntimeState,
|
|
87
|
-
initPayload: { populationSize: number; elitismCount: number; rngSeed: number; },
|
|
88
|
-
): Promise<void>
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
Initializes the worker-local NEAT runtime used by browser evolution playback.
|
|
92
|
-
|
|
93
|
-
Educational note:
|
|
94
|
-
The runtime is configured once with deterministic RNG state and a lightweight
|
|
95
|
-
early-termination fitness rollout. Keeping this setup centralized helps ensure
|
|
96
|
-
reproducibility between runs and keeps host<->worker contracts simple.
|
|
97
|
-
|
|
98
|
-
This function only prepares the evolutionary controller. It does not start
|
|
99
|
-
playback and it does not evolve a generation yet; those remain separate
|
|
100
|
-
protocol steps so the host can control them explicitly.
|
|
101
|
-
|
|
102
|
-
Parameters:
|
|
103
|
-
- `initPayload` - - Initialization values from the browser host.
|
|
104
|
-
|
|
105
|
-
Returns: Promise resolved when runtime setup is complete.
|
|
106
|
-
|
|
107
142
|
### evolveAndPublishGeneration
|
|
108
143
|
|
|
109
144
|
```ts
|
|
@@ -121,63 +156,48 @@ a compact payload for UI state updates.
|
|
|
121
156
|
|
|
122
157
|
Returns: Promise resolved after generation payload is posted.
|
|
123
158
|
|
|
124
|
-
###
|
|
159
|
+
### initializeRuntime
|
|
125
160
|
|
|
126
161
|
```ts
|
|
127
|
-
|
|
162
|
+
initializeRuntime(
|
|
128
163
|
workerMutableRuntimeState: WorkerMutableRuntimeState,
|
|
129
164
|
initPayload: { populationSize: number; elitismCount: number; rngSeed: number; },
|
|
130
|
-
): void
|
|
165
|
+
): Promise<void>
|
|
131
166
|
```
|
|
132
167
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
The worker retains the initialization promise so later generation requests can
|
|
136
|
-
await setup completion instead of racing against it.
|
|
137
|
-
|
|
138
|
-
Parameters:
|
|
139
|
-
- `workerMutableRuntimeState` - - Mutable worker runtime state.
|
|
140
|
-
- `initPayload` - - Initialization payload.
|
|
141
|
-
|
|
142
|
-
Returns: Nothing.
|
|
143
|
-
|
|
144
|
-
### beginWorkerGenerationRequest
|
|
145
|
-
|
|
146
|
-
```ts
|
|
147
|
-
beginWorkerGenerationRequest(
|
|
148
|
-
workerMutableRuntimeState: WorkerMutableRuntimeState,
|
|
149
|
-
): void
|
|
150
|
-
```
|
|
168
|
+
Initializes the worker-local NEAT runtime used by browser evolution playback.
|
|
151
169
|
|
|
152
|
-
|
|
170
|
+
Educational note:
|
|
171
|
+
The runtime is configured once with deterministic RNG state and a lightweight
|
|
172
|
+
early-termination fitness rollout. Keeping this setup centralized helps ensure
|
|
173
|
+
reproducibility between runs and keeps host<->worker contracts simple.
|
|
153
174
|
|
|
154
|
-
This
|
|
155
|
-
|
|
156
|
-
|
|
175
|
+
This function only prepares the evolutionary controller. It does not start
|
|
176
|
+
playback and it does not evolve a generation yet; those remain separate
|
|
177
|
+
protocol steps so the host can control them explicitly.
|
|
157
178
|
|
|
158
179
|
Parameters:
|
|
159
|
-
- `
|
|
180
|
+
- `initPayload` - - Initialization values from the browser host.
|
|
160
181
|
|
|
161
|
-
Returns:
|
|
182
|
+
Returns: Promise resolved when runtime setup is complete.
|
|
162
183
|
|
|
163
|
-
###
|
|
184
|
+
### postWorkerMessage
|
|
164
185
|
|
|
165
186
|
```ts
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
187
|
+
postWorkerMessage(
|
|
188
|
+
workerMessage: WorkerResponseMessage,
|
|
189
|
+
transferList: Transferable[] | undefined,
|
|
169
190
|
): void
|
|
170
191
|
```
|
|
171
192
|
|
|
172
|
-
|
|
193
|
+
Posts a typed message from worker to host.
|
|
173
194
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
the host can replay generations cleanly.
|
|
195
|
+
This is the narrowest possible transport helper: all message construction is
|
|
196
|
+
done elsewhere so the README can point to one stable worker-to-host boundary.
|
|
177
197
|
|
|
178
198
|
Parameters:
|
|
179
|
-
- `
|
|
180
|
-
- `
|
|
199
|
+
- `workerMessage` - - Outbound worker response payload.
|
|
200
|
+
- `transferList` - - Optional transferable buffers moved with the payload.
|
|
181
201
|
|
|
182
202
|
Returns: Nothing.
|
|
183
203
|
|
|
@@ -205,26 +225,6 @@ Parameters:
|
|
|
205
225
|
|
|
206
226
|
Returns: Nothing.
|
|
207
227
|
|
|
208
|
-
### postWorkerMessage
|
|
209
|
-
|
|
210
|
-
```ts
|
|
211
|
-
postWorkerMessage(
|
|
212
|
-
workerMessage: WorkerResponseMessage,
|
|
213
|
-
transferList: Transferable[] | undefined,
|
|
214
|
-
): void
|
|
215
|
-
```
|
|
216
|
-
|
|
217
|
-
Posts a typed message from worker to host.
|
|
218
|
-
|
|
219
|
-
This is the narrowest possible transport helper: all message construction is
|
|
220
|
-
done elsewhere so the README can point to one stable worker-to-host boundary.
|
|
221
|
-
|
|
222
|
-
Parameters:
|
|
223
|
-
- `workerMessage` - - Outbound worker response payload.
|
|
224
|
-
- `transferList` - - Optional transferable buffers moved with the payload.
|
|
225
|
-
|
|
226
|
-
Returns: Nothing.
|
|
227
|
-
|
|
228
228
|
## flappy-evolution-worker/flappy-evolution-worker.types.ts
|
|
229
229
|
|
|
230
230
|
### SerializedNetwork
|
|
@@ -235,29 +235,12 @@ The worker never posts live `Network` instances back to the browser host.
|
|
|
235
235
|
Instead it sends the result of `network.toJSON()` so the payload stays
|
|
236
236
|
structured-clone safe and easy to inspect in devtools.
|
|
237
237
|
|
|
238
|
-
###
|
|
239
|
-
|
|
240
|
-
Mutable pipe state tracked by the worker playback simulation.
|
|
241
|
-
|
|
242
|
-
These objects exist only inside the worker runtime. The host later receives a
|
|
243
|
-
packed snapshot derived from them rather than these live mutable records.
|
|
244
|
-
|
|
245
|
-
### WorkerPopulationBird
|
|
246
|
-
|
|
247
|
-
Mutable bird state tracked by the worker playback simulation.
|
|
248
|
-
|
|
249
|
-
Educational note:
|
|
250
|
-
Each bird keeps both physics state and policy state. The observation-memory
|
|
251
|
-
field lets feed-forward networks approximate short-term temporal memory by
|
|
252
|
-
carrying previous observation features between simulation steps.
|
|
253
|
-
|
|
254
|
-
### WorkerPlaybackState
|
|
238
|
+
### WorkerErrorMessage
|
|
255
239
|
|
|
256
|
-
|
|
240
|
+
Worker error response message.
|
|
257
241
|
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
simulation steps.
|
|
242
|
+
Errors are normalized into a display-safe string so the host UI can surface
|
|
243
|
+
failures without depending on worker-specific exception classes.
|
|
261
244
|
|
|
262
245
|
### WorkerFrameBirdSnapshot
|
|
263
246
|
|
|
@@ -273,13 +256,27 @@ Render-only pipe snapshot DTO posted to host.
|
|
|
273
256
|
Like `WorkerFrameBirdSnapshot`, this documents the logical payload shape even
|
|
274
257
|
though the worker currently sends the packed transport form.
|
|
275
258
|
|
|
276
|
-
###
|
|
259
|
+
### WorkerGenerationReadyMessage
|
|
277
260
|
|
|
278
|
-
|
|
261
|
+
Worker generation-ready response message.
|
|
279
262
|
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
263
|
+
The browser host uses this message to refresh HUD state and optionally render
|
|
264
|
+
the current best network visualization.
|
|
265
|
+
|
|
266
|
+
### WorkerHeuristicObservationFeatures
|
|
267
|
+
|
|
268
|
+
Structured features used by heuristic generation-0 teacher policy.
|
|
269
|
+
|
|
270
|
+
The warm-start service reuses the same high-level observation semantics as the
|
|
271
|
+
real policy inference path, which keeps the heuristic teacher aligned with the
|
|
272
|
+
features evolved networks will later see.
|
|
273
|
+
|
|
274
|
+
### WorkerInitMessage
|
|
275
|
+
|
|
276
|
+
Worker init request message.
|
|
277
|
+
|
|
278
|
+
This is the first message the host should send. It seeds deterministic RNG
|
|
279
|
+
state and configures the worker-local NEAT runtime.
|
|
283
280
|
|
|
284
281
|
### WorkerPackedPlaybackBirdSnapshot
|
|
285
282
|
|
|
@@ -288,6 +285,14 @@ Packed typed-array payload for playback bird snapshot transport.
|
|
|
288
285
|
The host can reconstruct renderer-friendly bird views from these arrays while
|
|
289
286
|
the worker keeps the authoritative mutable simulation objects private.
|
|
290
287
|
|
|
288
|
+
### WorkerPackedPlaybackPipeSnapshot
|
|
289
|
+
|
|
290
|
+
Packed typed-array payload for playback pipe snapshot transport.
|
|
291
|
+
|
|
292
|
+
Packing the per-pipe fields into column-oriented typed arrays makes the
|
|
293
|
+
browser/worker boundary cheaper than sending large arrays of object literals
|
|
294
|
+
on every animation frame.
|
|
295
|
+
|
|
291
296
|
### WorkerPlaybackFrameSnapshot
|
|
292
297
|
|
|
293
298
|
Full frame snapshot payload posted to host.
|
|
@@ -310,43 +315,48 @@ const message = {
|
|
|
310
315
|
};
|
|
311
316
|
```
|
|
312
317
|
|
|
313
|
-
###
|
|
318
|
+
### WorkerPlaybackState
|
|
314
319
|
|
|
315
|
-
|
|
320
|
+
Mutable simulation state stored between worker playback requests.
|
|
316
321
|
|
|
317
|
-
|
|
318
|
-
|
|
322
|
+
A `start-playback` message creates this state once, and each
|
|
323
|
+
`request-playback-step` message advances it by a host-selected number of
|
|
324
|
+
simulation steps.
|
|
319
325
|
|
|
320
|
-
###
|
|
326
|
+
### WorkerPlaybackStepMessage
|
|
321
327
|
|
|
322
|
-
Worker
|
|
328
|
+
Worker playback-step response message.
|
|
323
329
|
|
|
324
|
-
The
|
|
325
|
-
|
|
330
|
+
The message carries the packed frame snapshot plus optional instrumentation
|
|
331
|
+
and end-of-run summary statistics when the whole simulated population has
|
|
332
|
+
been eliminated.
|
|
326
333
|
|
|
327
|
-
|
|
334
|
+
The split between per-frame snapshot data and end-of-run summary fields keeps
|
|
335
|
+
the hot path compact while still giving the host enough telemetry to update
|
|
336
|
+
HUD metrics when a playback session completes.
|
|
328
337
|
|
|
329
|
-
|
|
338
|
+
### WorkerPopulationBird
|
|
330
339
|
|
|
331
|
-
|
|
332
|
-
After this message succeeds, the host can begin issuing playback-step
|
|
333
|
-
requests.
|
|
340
|
+
Mutable bird state tracked by the worker playback simulation.
|
|
334
341
|
|
|
335
|
-
|
|
342
|
+
Educational note:
|
|
343
|
+
Each bird keeps both physics state and policy state. The observation-memory
|
|
344
|
+
field lets feed-forward networks approximate short-term temporal memory by
|
|
345
|
+
carrying previous observation features between simulation steps.
|
|
336
346
|
|
|
337
|
-
|
|
347
|
+
### WorkerPopulationPipe
|
|
338
348
|
|
|
339
|
-
|
|
340
|
-
`simulationSteps` based on how much simulation throughput it wants relative to
|
|
341
|
-
rendering smoothness.
|
|
349
|
+
Mutable pipe state tracked by the worker playback simulation.
|
|
342
350
|
|
|
343
|
-
|
|
351
|
+
These objects exist only inside the worker runtime. The host later receives a
|
|
352
|
+
packed snapshot derived from them rather than these live mutable records.
|
|
344
353
|
|
|
345
|
-
|
|
354
|
+
### WorkerRequestGenerationMessage
|
|
346
355
|
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
356
|
+
Worker request asking to evolve one generation.
|
|
357
|
+
|
|
358
|
+
The worker responds with `generation-ready` once the NEAT runtime finishes
|
|
359
|
+
one evolution pass.
|
|
350
360
|
|
|
351
361
|
### WorkerRequestMessage
|
|
352
362
|
|
|
@@ -355,31 +365,13 @@ Union of inbound worker request messages.
|
|
|
355
365
|
Reading this union top-to-bottom is the quickest way to understand the worker
|
|
356
366
|
protocol: initialize, evolve, start playback, step playback, then stop.
|
|
357
367
|
|
|
358
|
-
###
|
|
359
|
-
|
|
360
|
-
Worker generation-ready response message.
|
|
361
|
-
|
|
362
|
-
The browser host uses this message to refresh HUD state and optionally render
|
|
363
|
-
the current best network visualization.
|
|
364
|
-
|
|
365
|
-
### WorkerPlaybackStepMessage
|
|
366
|
-
|
|
367
|
-
Worker playback-step response message.
|
|
368
|
-
|
|
369
|
-
The message carries the packed frame snapshot plus optional instrumentation
|
|
370
|
-
and end-of-run summary statistics when the whole simulated population has
|
|
371
|
-
been eliminated.
|
|
372
|
-
|
|
373
|
-
The split between per-frame snapshot data and end-of-run summary fields keeps
|
|
374
|
-
the hot path compact while still giving the host enough telemetry to update
|
|
375
|
-
HUD metrics when a playback session completes.
|
|
376
|
-
|
|
377
|
-
### WorkerErrorMessage
|
|
368
|
+
### WorkerRequestPlaybackStepMessage
|
|
378
369
|
|
|
379
|
-
Worker
|
|
370
|
+
Worker request asking to advance playback by N simulation steps.
|
|
380
371
|
|
|
381
|
-
|
|
382
|
-
|
|
372
|
+
The host typically sends this once per animation frame and chooses
|
|
373
|
+
`simulationSteps` based on how much simulation throughput it wants relative to
|
|
374
|
+
rendering smoothness.
|
|
383
375
|
|
|
384
376
|
### WorkerResponseMessage
|
|
385
377
|
|
|
@@ -388,13 +380,21 @@ Union of outbound worker response messages.
|
|
|
388
380
|
Together with `WorkerRequestMessage`, this forms the full host/worker
|
|
389
381
|
protocol contract for the demo.
|
|
390
382
|
|
|
391
|
-
###
|
|
383
|
+
### WorkerStartPlaybackMessage
|
|
392
384
|
|
|
393
|
-
|
|
385
|
+
Worker request asking to initialize playback state.
|
|
394
386
|
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
387
|
+
This materializes the mutable world state for the current evolved population.
|
|
388
|
+
After this message succeeds, the host can begin issuing playback-step
|
|
389
|
+
requests.
|
|
390
|
+
|
|
391
|
+
### WorkerStopMessage
|
|
392
|
+
|
|
393
|
+
Worker stop request message.
|
|
394
|
+
|
|
395
|
+
This is a cooperative shutdown signal. Long-running worker flows can observe
|
|
396
|
+
the stopped flag and fail fast instead of continuing work the UI no longer
|
|
397
|
+
cares about.
|
|
398
398
|
|
|
399
399
|
## flappy-evolution-worker/flappy-evolution-worker.runtime.service.ts
|
|
400
400
|
|
|
@@ -690,49 +690,52 @@ const playbackState = createWorkerPopulationRenderState(
|
|
|
690
690
|
|
|
691
691
|
## flappy-evolution-worker/flappy-evolution-worker.simulation.frame.service.ts
|
|
692
692
|
|
|
693
|
-
###
|
|
693
|
+
### advanceBirdPhysics
|
|
694
694
|
|
|
695
695
|
```ts
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
difficultyProfile: SharedDifficultyProfile,
|
|
700
|
-
): number
|
|
696
|
+
advanceBirdPhysics(
|
|
697
|
+
frameContext: WorkerPlaybackFrameContext,
|
|
698
|
+
): void
|
|
701
699
|
```
|
|
702
700
|
|
|
703
|
-
|
|
701
|
+
Integrates bird velocity and vertical motion for one control substep.
|
|
704
702
|
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
worker can make flap decisions, apply gravity, move pipes, spawn new pipes,
|
|
708
|
-
and resolve collisions with better numerical stability than a single large
|
|
709
|
-
integration jump.
|
|
703
|
+
Parameters:
|
|
704
|
+
- `frameContext` - - Shared frame context for this logical frame.
|
|
710
705
|
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
706
|
+
Returns: Nothing.
|
|
707
|
+
|
|
708
|
+
### advancePipes
|
|
709
|
+
|
|
710
|
+
```ts
|
|
711
|
+
advancePipes(
|
|
712
|
+
frameContext: WorkerPlaybackFrameContext,
|
|
713
|
+
): void
|
|
714
|
+
```
|
|
715
|
+
|
|
716
|
+
Advances all visible pipes and culls those that have left the camera window.
|
|
714
717
|
|
|
715
718
|
Parameters:
|
|
716
|
-
- `
|
|
717
|
-
- `rng` - - Deterministic random source for spawn variation.
|
|
718
|
-
- `difficultyProfile` - - Active dynamic difficulty profile.
|
|
719
|
+
- `frameContext` - - Shared frame context for this logical frame.
|
|
719
720
|
|
|
720
|
-
Returns:
|
|
721
|
+
Returns: Nothing.
|
|
721
722
|
|
|
722
|
-
###
|
|
723
|
+
### commitPassedPipeProgress
|
|
723
724
|
|
|
724
725
|
```ts
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
726
|
+
commitPassedPipeProgress(
|
|
727
|
+
bird: WorkerPopulationBird,
|
|
728
|
+
pipe: WorkerPopulationPipe,
|
|
729
|
+
): void
|
|
728
730
|
```
|
|
729
731
|
|
|
730
|
-
|
|
732
|
+
Commits one passed-pipe progress increment for a bird when eligible.
|
|
731
733
|
|
|
732
734
|
Parameters:
|
|
733
|
-
- `
|
|
735
|
+
- `bird` - - Mutable bird state.
|
|
736
|
+
- `pipe` - - Pipe candidate to mark as passed.
|
|
734
737
|
|
|
735
|
-
Returns:
|
|
738
|
+
Returns: Nothing.
|
|
736
739
|
|
|
737
740
|
### incrementLivingBirdFrameCounters
|
|
738
741
|
|
|
@@ -749,20 +752,24 @@ Parameters:
|
|
|
749
752
|
|
|
750
753
|
Returns: Nothing.
|
|
751
754
|
|
|
752
|
-
###
|
|
755
|
+
### resolveBirdCollisionAgainstPipe
|
|
753
756
|
|
|
754
757
|
```ts
|
|
755
|
-
|
|
758
|
+
resolveBirdCollisionAgainstPipe(
|
|
759
|
+
bird: WorkerPopulationBird,
|
|
760
|
+
pipe: WorkerPopulationPipe,
|
|
756
761
|
frameContext: WorkerPlaybackFrameContext,
|
|
757
|
-
):
|
|
762
|
+
): boolean
|
|
758
763
|
```
|
|
759
764
|
|
|
760
|
-
|
|
765
|
+
Resolves whether a bird collides with one pipe corridor during this substep.
|
|
761
766
|
|
|
762
767
|
Parameters:
|
|
768
|
+
- `bird` - - Mutable bird state.
|
|
769
|
+
- `pipe` - - Pipe candidate to test.
|
|
763
770
|
- `frameContext` - - Shared frame context for this logical frame.
|
|
764
771
|
|
|
765
|
-
Returns:
|
|
772
|
+
Returns: `true` when the bird overlaps the pipe body instead of the gap.
|
|
766
773
|
|
|
767
774
|
### resolveBirdControlActions
|
|
768
775
|
|
|
@@ -779,50 +786,22 @@ Parameters:
|
|
|
779
786
|
|
|
780
787
|
Returns: Number of activation calls performed in the substep.
|
|
781
788
|
|
|
782
|
-
###
|
|
783
|
-
|
|
784
|
-
```ts
|
|
785
|
-
advanceBirdPhysics(
|
|
786
|
-
frameContext: WorkerPlaybackFrameContext,
|
|
787
|
-
): void
|
|
788
|
-
```
|
|
789
|
-
|
|
790
|
-
Integrates bird velocity and vertical motion for one control substep.
|
|
791
|
-
|
|
792
|
-
Parameters:
|
|
793
|
-
- `frameContext` - - Shared frame context for this logical frame.
|
|
794
|
-
|
|
795
|
-
Returns: Nothing.
|
|
796
|
-
|
|
797
|
-
### advancePipes
|
|
798
|
-
|
|
799
|
-
```ts
|
|
800
|
-
advancePipes(
|
|
801
|
-
frameContext: WorkerPlaybackFrameContext,
|
|
802
|
-
): void
|
|
803
|
-
```
|
|
804
|
-
|
|
805
|
-
Advances all visible pipes and culls those that have left the camera window.
|
|
806
|
-
|
|
807
|
-
Parameters:
|
|
808
|
-
- `frameContext` - - Shared frame context for this logical frame.
|
|
809
|
-
|
|
810
|
-
Returns: Nothing.
|
|
811
|
-
|
|
812
|
-
### spawnPipeIfNeeded
|
|
789
|
+
### resolveBirdOutOfBounds
|
|
813
790
|
|
|
814
791
|
```ts
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
792
|
+
resolveBirdOutOfBounds(
|
|
793
|
+
bird: WorkerPopulationBird,
|
|
794
|
+
visibleWorldHeightPx: number,
|
|
795
|
+
): boolean
|
|
818
796
|
```
|
|
819
797
|
|
|
820
|
-
|
|
798
|
+
Resolves whether a bird has exceeded the vertical play area.
|
|
821
799
|
|
|
822
800
|
Parameters:
|
|
823
|
-
- `
|
|
801
|
+
- `bird` - - Mutable bird state.
|
|
802
|
+
- `visibleWorldHeightPx` - - Current visible world height.
|
|
824
803
|
|
|
825
|
-
Returns:
|
|
804
|
+
Returns: `true` when the bird is outside the vertical bounds.
|
|
826
805
|
|
|
827
806
|
### resolveBirdTerminationAndProgress
|
|
828
807
|
|
|
@@ -839,112 +818,106 @@ Parameters:
|
|
|
839
818
|
|
|
840
819
|
Returns: Nothing.
|
|
841
820
|
|
|
842
|
-
###
|
|
821
|
+
### resolveCameraLeftXPx
|
|
843
822
|
|
|
844
823
|
```ts
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
): boolean
|
|
824
|
+
resolveCameraLeftXPx(
|
|
825
|
+
visibleWorldWidthPx: number,
|
|
826
|
+
): number
|
|
849
827
|
```
|
|
850
828
|
|
|
851
|
-
Resolves
|
|
829
|
+
Resolves the current left-edge of the visible world in world-space pixels.
|
|
852
830
|
|
|
853
831
|
Parameters:
|
|
854
|
-
- `
|
|
855
|
-
- `visibleWorldHeightPx` - - Current visible world height.
|
|
832
|
+
- `visibleWorldWidthPx` - - Current visible world width.
|
|
856
833
|
|
|
857
|
-
Returns:
|
|
834
|
+
Returns: Left edge x-position in world coordinates.
|
|
858
835
|
|
|
859
|
-
###
|
|
836
|
+
### runWorkerPopulationControlSubstep
|
|
860
837
|
|
|
861
838
|
```ts
|
|
862
|
-
|
|
863
|
-
bird: WorkerPopulationBird,
|
|
864
|
-
pipe: WorkerPopulationPipe,
|
|
839
|
+
runWorkerPopulationControlSubstep(
|
|
865
840
|
frameContext: WorkerPlaybackFrameContext,
|
|
866
|
-
):
|
|
841
|
+
): number
|
|
867
842
|
```
|
|
868
843
|
|
|
869
|
-
|
|
844
|
+
Advances one control substep of the worker playback simulation.
|
|
870
845
|
|
|
871
846
|
Parameters:
|
|
872
|
-
- `bird` - - Mutable bird state.
|
|
873
|
-
- `pipe` - - Pipe candidate to test.
|
|
874
847
|
- `frameContext` - - Shared frame context for this logical frame.
|
|
875
848
|
|
|
876
|
-
Returns:
|
|
849
|
+
Returns: Number of activation calls performed in the substep.
|
|
877
850
|
|
|
878
|
-
###
|
|
851
|
+
### spawnPipeIfNeeded
|
|
879
852
|
|
|
880
853
|
```ts
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
pipe: WorkerPopulationPipe,
|
|
854
|
+
spawnPipeIfNeeded(
|
|
855
|
+
frameContext: WorkerPlaybackFrameContext,
|
|
884
856
|
): void
|
|
885
857
|
```
|
|
886
858
|
|
|
887
|
-
|
|
859
|
+
Spawns a new pipe when the substep budget crosses the spawn boundary.
|
|
888
860
|
|
|
889
861
|
Parameters:
|
|
890
|
-
- `
|
|
891
|
-
- `pipe` - - Pipe candidate to mark as passed.
|
|
862
|
+
- `frameContext` - - Shared frame context for this logical frame.
|
|
892
863
|
|
|
893
864
|
Returns: Nothing.
|
|
894
865
|
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
### warmStartWorkerGenerationZeroIfNeeded
|
|
866
|
+
### stepWorkerPopulationFrame
|
|
898
867
|
|
|
899
868
|
```ts
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
):
|
|
869
|
+
stepWorkerPopulationFrame(
|
|
870
|
+
renderState: WorkerPlaybackState,
|
|
871
|
+
rng: RngLike,
|
|
872
|
+
difficultyProfile: SharedDifficultyProfile,
|
|
873
|
+
): number
|
|
905
874
|
```
|
|
906
875
|
|
|
907
|
-
|
|
876
|
+
Advances the whole population simulation by one logical frame.
|
|
908
877
|
|
|
909
878
|
Educational note:
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
879
|
+
One logical frame is internally split into smaller control substeps so the
|
|
880
|
+
worker can make flap decisions, apply gravity, move pipes, spawn new pipes,
|
|
881
|
+
and resolve collisions with better numerical stability than a single large
|
|
882
|
+
integration jump.
|
|
913
883
|
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
884
|
+
This function is the main simulation ownership boundary for the folder.
|
|
885
|
+
The companion `simulation.utils` file creates initial state; this service is
|
|
886
|
+
responsible for mutating that state over time.
|
|
917
887
|
|
|
918
888
|
Parameters:
|
|
919
|
-
- `
|
|
920
|
-
- `
|
|
889
|
+
- `renderState` - - Mutable simulation state.
|
|
890
|
+
- `rng` - - Deterministic random source for spawn variation.
|
|
891
|
+
- `difficultyProfile` - - Active dynamic difficulty profile.
|
|
921
892
|
|
|
922
|
-
Returns:
|
|
893
|
+
Returns: Number of policy activation calls made in this frame.
|
|
923
894
|
|
|
924
|
-
|
|
895
|
+
## flappy-evolution-worker/flappy-evolution-worker.warm-start.service.ts
|
|
896
|
+
|
|
897
|
+
### applyTemplateWeightsWithNoise
|
|
925
898
|
|
|
926
899
|
```ts
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
900
|
+
applyTemplateWeightsWithNoise(
|
|
901
|
+
genome: default,
|
|
902
|
+
template: default,
|
|
903
|
+
rng: FlappyRng,
|
|
904
|
+
noise: { weightStdDev: number; biasStdDev: number; },
|
|
905
|
+
): void
|
|
931
906
|
```
|
|
932
907
|
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
State carried between generation requests for one worker runtime.
|
|
936
|
-
|
|
937
|
-
The warm-start service is intentionally one-shot. These fields let the worker
|
|
938
|
-
remember whether generation 0 has already been bootstrapped and which initial
|
|
939
|
-
RNG seed should be reused for deterministic synthetic sample generation.
|
|
908
|
+
Copies template parameters into a genome and injects small Gaussian noise.
|
|
940
909
|
|
|
941
|
-
|
|
910
|
+
Educational note:
|
|
911
|
+
The template network gives generation 0 a shared prior, while the noise terms
|
|
912
|
+
restore diversity so the population is still worth evolving.
|
|
942
913
|
|
|
943
|
-
|
|
914
|
+
Parameters:
|
|
915
|
+
- `genome` - - Target genome to mutate in-place.
|
|
916
|
+
- `template` - - Trained template source network.
|
|
917
|
+
- `rng` - - Deterministic random source for noise sampling.
|
|
918
|
+
- `noise` - - Standard deviations for weight and bias perturbations.
|
|
944
919
|
|
|
945
|
-
|
|
946
|
-
template refinement. Tests can override these seams to keep assertions small
|
|
947
|
-
and deterministic.
|
|
920
|
+
Returns: Nothing.
|
|
948
921
|
|
|
949
922
|
### buildHeuristicPretrainSet
|
|
950
923
|
|
|
@@ -953,43 +926,20 @@ buildHeuristicPretrainSet(
|
|
|
953
926
|
rng: FlappyRng,
|
|
954
927
|
sampleCount: number,
|
|
955
928
|
): { input: number[]; output: number[]; }[]
|
|
956
|
-
```
|
|
957
|
-
|
|
958
|
-
Builds synthetic supervised samples for generation-0 behavior cloning.
|
|
959
|
-
|
|
960
|
-
Educational note:
|
|
961
|
-
These samples are not recorded gameplay traces. They are synthetic states
|
|
962
|
-
generated from the same observation pipeline used during real playback so the
|
|
963
|
-
teacher labels and the evolved policy inputs stay in the same feature space.
|
|
964
|
-
|
|
965
|
-
Parameters:
|
|
966
|
-
- `rng` - - Deterministic random source.
|
|
967
|
-
- `sampleCount` - - Requested number of synthetic samples.
|
|
968
|
-
|
|
969
|
-
Returns: Supervised dataset of input/output pairs.
|
|
970
|
-
|
|
971
|
-
### optimizeWarmStartTemplateNetwork
|
|
972
|
-
|
|
973
|
-
```ts
|
|
974
|
-
optimizeWarmStartTemplateNetwork(
|
|
975
|
-
templateNetwork: default,
|
|
976
|
-
workerInitSeed: number,
|
|
977
|
-
): default
|
|
978
|
-
```
|
|
979
|
-
|
|
980
|
-
Refines the generation-0 template against real Flappy rollouts.
|
|
981
|
-
|
|
982
|
-
The warm-start teacher gets the template out of pure-random territory, but it
|
|
983
|
-
still only imitates a simple flap heuristic. This refinement pass keeps the
|
|
984
|
-
topology fixed and searches the parameter surface directly against actual
|
|
985
|
-
rollout fitness so the first visible generation starts closer to competent
|
|
986
|
-
control.
|
|
929
|
+
```
|
|
930
|
+
|
|
931
|
+
Builds synthetic supervised samples for generation-0 behavior cloning.
|
|
932
|
+
|
|
933
|
+
Educational note:
|
|
934
|
+
These samples are not recorded gameplay traces. They are synthetic states
|
|
935
|
+
generated from the same observation pipeline used during real playback so the
|
|
936
|
+
teacher labels and the evolved policy inputs stay in the same feature space.
|
|
987
937
|
|
|
988
938
|
Parameters:
|
|
989
|
-
- `
|
|
990
|
-
- `
|
|
939
|
+
- `rng` - - Deterministic random source.
|
|
940
|
+
- `sampleCount` - - Requested number of synthetic samples.
|
|
991
941
|
|
|
992
|
-
Returns:
|
|
942
|
+
Returns: Supervised dataset of input/output pairs.
|
|
993
943
|
|
|
994
944
|
### buildWarmStartRolloutSeedBatch
|
|
995
945
|
|
|
@@ -1025,6 +975,25 @@ Parameters:
|
|
|
1025
975
|
|
|
1026
976
|
Returns: Aggregate shared-seed evaluation.
|
|
1027
977
|
|
|
978
|
+
### interpolateValue
|
|
979
|
+
|
|
980
|
+
```ts
|
|
981
|
+
interpolateValue(
|
|
982
|
+
startValue: number,
|
|
983
|
+
endValue: number,
|
|
984
|
+
ratio: number,
|
|
985
|
+
): number
|
|
986
|
+
```
|
|
987
|
+
|
|
988
|
+
Linearly interpolates between two scalar values.
|
|
989
|
+
|
|
990
|
+
Parameters:
|
|
991
|
+
- `startValue` - - Value at ratio `0`.
|
|
992
|
+
- `endValue` - - Value at ratio `1`.
|
|
993
|
+
- `ratio` - - Interpolation ratio.
|
|
994
|
+
|
|
995
|
+
Returns: Interpolated value.
|
|
996
|
+
|
|
1028
997
|
### isWarmStartEvaluationBetter
|
|
1029
998
|
|
|
1030
999
|
```ts
|
|
@@ -1046,22 +1015,28 @@ Parameters:
|
|
|
1046
1015
|
|
|
1047
1016
|
Returns: True when the candidate should replace the incumbent template.
|
|
1048
1017
|
|
|
1049
|
-
###
|
|
1018
|
+
### optimizeWarmStartTemplateNetwork
|
|
1050
1019
|
|
|
1051
1020
|
```ts
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
):
|
|
1021
|
+
optimizeWarmStartTemplateNetwork(
|
|
1022
|
+
templateNetwork: default,
|
|
1023
|
+
workerInitSeed: number,
|
|
1024
|
+
): default
|
|
1056
1025
|
```
|
|
1057
1026
|
|
|
1058
|
-
|
|
1027
|
+
Refines the generation-0 template against real Flappy rollouts.
|
|
1028
|
+
|
|
1029
|
+
The warm-start teacher gets the template out of pure-random territory, but it
|
|
1030
|
+
still only imitates a simple flap heuristic. This refinement pass keeps the
|
|
1031
|
+
topology fixed and searches the parameter surface directly against actual
|
|
1032
|
+
rollout fitness so the first visible generation starts closer to competent
|
|
1033
|
+
control.
|
|
1059
1034
|
|
|
1060
1035
|
Parameters:
|
|
1061
|
-
- `
|
|
1062
|
-
- `
|
|
1036
|
+
- `templateNetwork` - - Heuristic-pretrained template network.
|
|
1037
|
+
- `workerInitSeed` - - Deterministic worker seed.
|
|
1063
1038
|
|
|
1064
|
-
Returns:
|
|
1039
|
+
Returns: Best rollout-refined template found within the bounded budget.
|
|
1065
1040
|
|
|
1066
1041
|
### perturbNetworkParametersInPlace
|
|
1067
1042
|
|
|
@@ -1086,25 +1061,6 @@ Parameters:
|
|
|
1086
1061
|
|
|
1087
1062
|
Returns: Nothing.
|
|
1088
1063
|
|
|
1089
|
-
### interpolateValue
|
|
1090
|
-
|
|
1091
|
-
```ts
|
|
1092
|
-
interpolateValue(
|
|
1093
|
-
startValue: number,
|
|
1094
|
-
endValue: number,
|
|
1095
|
-
ratio: number,
|
|
1096
|
-
): number
|
|
1097
|
-
```
|
|
1098
|
-
|
|
1099
|
-
Linearly interpolates between two scalar values.
|
|
1100
|
-
|
|
1101
|
-
Parameters:
|
|
1102
|
-
- `startValue` - - Value at ratio `0`.
|
|
1103
|
-
- `endValue` - - Value at ratio `1`.
|
|
1104
|
-
- `ratio` - - Interpolation ratio.
|
|
1105
|
-
|
|
1106
|
-
Returns: Interpolated value.
|
|
1107
|
-
|
|
1108
1064
|
### resolveHeuristicTeacherFlapDecision
|
|
1109
1065
|
|
|
1110
1066
|
```ts
|
|
@@ -1124,30 +1080,22 @@ Parameters:
|
|
|
1124
1080
|
|
|
1125
1081
|
Returns: True when the teacher says to flap.
|
|
1126
1082
|
|
|
1127
|
-
###
|
|
1083
|
+
### resolveWarmStartAnnealRatio
|
|
1128
1084
|
|
|
1129
1085
|
```ts
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
noise: { weightStdDev: number; biasStdDev: number; },
|
|
1135
|
-
): void
|
|
1086
|
+
resolveWarmStartAnnealRatio(
|
|
1087
|
+
optimizationStepIndex: number,
|
|
1088
|
+
totalOptimizationSteps: number,
|
|
1089
|
+
): number
|
|
1136
1090
|
```
|
|
1137
1091
|
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
Educational note:
|
|
1141
|
-
The template network gives generation 0 a shared prior, while the noise terms
|
|
1142
|
-
restore diversity so the population is still worth evolving.
|
|
1092
|
+
Resolves the annealing ratio for rollout-guided warm-start refinement.
|
|
1143
1093
|
|
|
1144
1094
|
Parameters:
|
|
1145
|
-
- `
|
|
1146
|
-
- `
|
|
1147
|
-
- `rng` - - Deterministic random source for noise sampling.
|
|
1148
|
-
- `noise` - - Standard deviations for weight and bias perturbations.
|
|
1095
|
+
- `optimizationStepIndex` - - Zero-based optimization step index.
|
|
1096
|
+
- `totalOptimizationSteps` - - Total number of optimization steps.
|
|
1149
1097
|
|
|
1150
|
-
Returns:
|
|
1098
|
+
Returns: Clamped ratio in the inclusive range [0, 1].
|
|
1151
1099
|
|
|
1152
1100
|
### sampleGaussian
|
|
1153
1101
|
|
|
@@ -1169,27 +1117,59 @@ Parameters:
|
|
|
1169
1117
|
|
|
1170
1118
|
Returns: One approximately standard-normal random value.
|
|
1171
1119
|
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
### resolveWorkerUnknownErrorMessage
|
|
1120
|
+
### warmStartWorkerGenerationZeroIfNeeded
|
|
1175
1121
|
|
|
1176
1122
|
```ts
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1123
|
+
warmStartWorkerGenerationZeroIfNeeded(
|
|
1124
|
+
neatController: default,
|
|
1125
|
+
warmStartState: WorkerWarmStartState,
|
|
1126
|
+
dependencies: WorkerWarmStartDependencies,
|
|
1127
|
+
): Promise<void>
|
|
1180
1128
|
```
|
|
1181
1129
|
|
|
1182
|
-
|
|
1130
|
+
Applies a one-time generation-0 warm-start to improve initial demo quality.
|
|
1183
1131
|
|
|
1184
1132
|
Educational note:
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1133
|
+
The worker entry should stay protocol-first. This service owns the short
|
|
1134
|
+
supervised bootstrap pass that nudges generation 0 away from pure noise while
|
|
1135
|
+
preserving the later NEAT-driven search loop.
|
|
1136
|
+
|
|
1137
|
+
Conceptually this is a lightweight behavior-cloning pass. If you want more
|
|
1138
|
+
background, the Wikipedia article on "imitation learning" is a helpful bridge
|
|
1139
|
+
between the heuristic teacher used here and the later evolutionary search.
|
|
1188
1140
|
|
|
1189
1141
|
Parameters:
|
|
1190
|
-
- `
|
|
1142
|
+
- `neatController` - - Initialized NEAT runtime.
|
|
1143
|
+
- `warmStartState` - - Mutable warm-start lifecycle state.
|
|
1191
1144
|
|
|
1192
|
-
Returns:
|
|
1145
|
+
Returns: Promise resolved when warm-start evaluation finishes.
|
|
1146
|
+
|
|
1147
|
+
Example:
|
|
1148
|
+
|
|
1149
|
+
```ts
|
|
1150
|
+
await warmStartWorkerGenerationZeroIfNeeded(neatRuntime, {
|
|
1151
|
+
workerInitSeed: 123,
|
|
1152
|
+
generationZeroWarmStartApplied: false,
|
|
1153
|
+
});
|
|
1154
|
+
```
|
|
1155
|
+
|
|
1156
|
+
### WorkerWarmStartDependencies
|
|
1157
|
+
|
|
1158
|
+
Dependency bag for generation-0 warm-start orchestration.
|
|
1159
|
+
|
|
1160
|
+
The production path uses the real heuristic dataset builder and rollout-guided
|
|
1161
|
+
template refinement. Tests can override these seams to keep assertions small
|
|
1162
|
+
and deterministic.
|
|
1163
|
+
|
|
1164
|
+
### WorkerWarmStartState
|
|
1165
|
+
|
|
1166
|
+
State carried between generation requests for one worker runtime.
|
|
1167
|
+
|
|
1168
|
+
The warm-start service is intentionally one-shot. These fields let the worker
|
|
1169
|
+
remember whether generation 0 has already been bootstrapped and which initial
|
|
1170
|
+
RNG seed should be reused for deterministic synthetic sample generation.
|
|
1171
|
+
|
|
1172
|
+
## flappy-evolution-worker/flappy-evolution-worker.errors.ts
|
|
1193
1173
|
|
|
1194
1174
|
### createWorkerErrorMessage
|
|
1195
1175
|
|
|
@@ -1254,18 +1234,27 @@ Worker error emitted when playback stepping is requested before playback start.
|
|
|
1254
1234
|
The protocol is stateful: `start-playback` materializes the mutable playback
|
|
1255
1235
|
state that later `request-playback-step` messages advance.
|
|
1256
1236
|
|
|
1257
|
-
|
|
1237
|
+
### resolveWorkerUnknownErrorMessage
|
|
1258
1238
|
|
|
1259
|
-
|
|
1239
|
+
```ts
|
|
1240
|
+
resolveWorkerUnknownErrorMessage(
|
|
1241
|
+
error: unknown,
|
|
1242
|
+
): string
|
|
1243
|
+
```
|
|
1244
|
+
|
|
1245
|
+
Resolves unknown error-like values into display-safe worker error messages.
|
|
1260
1246
|
|
|
1261
1247
|
Educational note:
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
Larger values usually make the teacher signal more stable, but they also
|
|
1266
|
-
increase startup latency inside the worker.
|
|
1248
|
+
Browser workers can throw anything, including strings or arbitrary objects.
|
|
1249
|
+
Normalizing that value here gives the rest of the protocol a simple
|
|
1250
|
+
`string`-only error surface.
|
|
1267
1251
|
|
|
1268
|
-
|
|
1252
|
+
Parameters:
|
|
1253
|
+
- `error` - - Unknown error value thrown by worker logic.
|
|
1254
|
+
|
|
1255
|
+
Returns: Normalized error message string.
|
|
1256
|
+
|
|
1257
|
+
## flappy-evolution-worker/flappy-evolution-worker.constants.ts
|
|
1269
1258
|
|
|
1270
1259
|
Synthetic sample count used for generation-0 warm-start pretraining.
|
|
1271
1260
|
|
|
@@ -1276,13 +1265,19 @@ many synthetic state/action examples are generated for that bootstrap pass.
|
|
|
1276
1265
|
Larger values usually make the teacher signal more stable, but they also
|
|
1277
1266
|
increase startup latency inside the worker.
|
|
1278
1267
|
|
|
1279
|
-
###
|
|
1268
|
+
### FLAPPY_WORKER_GEN0_PRETRAIN_BATCH_SIZE
|
|
1280
1269
|
|
|
1281
|
-
|
|
1270
|
+
Batch size for generation-0 warm-start pretraining.
|
|
1282
1271
|
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1272
|
+
Smaller batches inject a bit more stochasticity into the bootstrap fit,
|
|
1273
|
+
while still keeping the pass cheap enough for a browser worker.
|
|
1274
|
+
|
|
1275
|
+
### FLAPPY_WORKER_GEN0_PRETRAIN_BIAS_NOISE_STDDEV
|
|
1276
|
+
|
|
1277
|
+
Gaussian standard deviation used for post-pretrain node-bias diversification.
|
|
1278
|
+
|
|
1279
|
+
Bias noise is slightly smaller than weight noise so the warm-start remains a
|
|
1280
|
+
prior, not a rigid clone of the teacher-fitted template.
|
|
1286
1281
|
|
|
1287
1282
|
### FLAPPY_WORKER_GEN0_PRETRAIN_ITERATIONS
|
|
1288
1283
|
|
|
@@ -1292,13 +1287,6 @@ The goal is not to fully solve Flappy Bird with supervised learning. The
|
|
|
1292
1287
|
worker only needs a short nudge away from completely random action logits so
|
|
1293
1288
|
the first browser-visible generation looks less chaotic.
|
|
1294
1289
|
|
|
1295
|
-
### FLAPPY_WORKER_GEN0_PRETRAIN_BATCH_SIZE
|
|
1296
|
-
|
|
1297
|
-
Batch size for generation-0 warm-start pretraining.
|
|
1298
|
-
|
|
1299
|
-
Smaller batches inject a bit more stochasticity into the bootstrap fit,
|
|
1300
|
-
while still keeping the pass cheap enough for a browser worker.
|
|
1301
|
-
|
|
1302
1290
|
### FLAPPY_WORKER_GEN0_PRETRAIN_RATE
|
|
1303
1291
|
|
|
1304
1292
|
Learning rate for generation-0 warm-start pretraining.
|
|
@@ -1306,14 +1294,13 @@ Learning rate for generation-0 warm-start pretraining.
|
|
|
1306
1294
|
This is intentionally moderate: the template network should learn a simple
|
|
1307
1295
|
corridor-following prior without overfitting the heuristic teacher.
|
|
1308
1296
|
|
|
1309
|
-
###
|
|
1297
|
+
### FLAPPY_WORKER_GEN0_PRETRAIN_ROLLOUT_BIAS_STDDEV_END
|
|
1310
1298
|
|
|
1311
|
-
|
|
1299
|
+
Final node-bias noise scale for rollout-guided template refinement.
|
|
1312
1300
|
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
teacher labels.
|
|
1301
|
+
### FLAPPY_WORKER_GEN0_PRETRAIN_ROLLOUT_BIAS_STDDEV_START
|
|
1302
|
+
|
|
1303
|
+
Initial node-bias noise scale for rollout-guided template refinement.
|
|
1317
1304
|
|
|
1318
1305
|
### FLAPPY_WORKER_GEN0_PRETRAIN_ROLLOUT_OPTIMIZATION_STEPS
|
|
1319
1306
|
|
|
@@ -1323,6 +1310,19 @@ Each step perturbs the current best template, evaluates it on the shared
|
|
|
1323
1310
|
rollout seed batch, and keeps the candidate only when it improves robust
|
|
1324
1311
|
fitness. The budget stays intentionally small so worker startup remains fast.
|
|
1325
1312
|
|
|
1313
|
+
### FLAPPY_WORKER_GEN0_PRETRAIN_ROLLOUT_SEED_COUNT
|
|
1314
|
+
|
|
1315
|
+
Shared-seed batch size used by rollout-guided generation-0 template refinement.
|
|
1316
|
+
|
|
1317
|
+
After the heuristic teacher fit, the worker evaluates the fixed topology on a
|
|
1318
|
+
few real Flappy rollouts so the warm-start prior is pushed toward trajectories
|
|
1319
|
+
that actually survive the environment instead of only matching the synthetic
|
|
1320
|
+
teacher labels.
|
|
1321
|
+
|
|
1322
|
+
### FLAPPY_WORKER_GEN0_PRETRAIN_ROLLOUT_WEIGHT_STDDEV_END
|
|
1323
|
+
|
|
1324
|
+
Final connection-weight noise scale for rollout-guided template refinement.
|
|
1325
|
+
|
|
1326
1326
|
### FLAPPY_WORKER_GEN0_PRETRAIN_ROLLOUT_WEIGHT_STDDEV_START
|
|
1327
1327
|
|
|
1328
1328
|
Initial connection-weight noise scale for rollout-guided template refinement.
|
|
@@ -1330,17 +1330,24 @@ Initial connection-weight noise scale for rollout-guided template refinement.
|
|
|
1330
1330
|
Early optimization steps search broadly, then later steps cool toward the
|
|
1331
1331
|
smaller end scale below for finer local refinement.
|
|
1332
1332
|
|
|
1333
|
-
###
|
|
1333
|
+
### FLAPPY_WORKER_GEN0_PRETRAIN_SAMPLE_COUNT
|
|
1334
1334
|
|
|
1335
|
-
|
|
1335
|
+
Synthetic sample count used for generation-0 warm-start pretraining.
|
|
1336
1336
|
|
|
1337
|
-
|
|
1337
|
+
Educational note:
|
|
1338
|
+
The warm-start service briefly trains a template network on a heuristic
|
|
1339
|
+
teacher before the first NEAT generation is evolved. This value controls how
|
|
1340
|
+
many synthetic state/action examples are generated for that bootstrap pass.
|
|
1341
|
+
Larger values usually make the teacher signal more stable, but they also
|
|
1342
|
+
increase startup latency inside the worker.
|
|
1338
1343
|
|
|
1339
|
-
|
|
1344
|
+
### FLAPPY_WORKER_GEN0_PRETRAIN_VISIBLE_WORLD_WIDTH_PX
|
|
1340
1345
|
|
|
1341
|
-
|
|
1346
|
+
Visible world width used when generating synthetic warm-start samples.
|
|
1342
1347
|
|
|
1343
|
-
|
|
1348
|
+
This should roughly match the browser playback framing so the generated
|
|
1349
|
+
observation vectors look like the states the policy will later see during
|
|
1350
|
+
real worker playback.
|
|
1344
1351
|
|
|
1345
1352
|
### FLAPPY_WORKER_GEN0_PRETRAIN_WEIGHT_NOISE_STDDEV
|
|
1346
1353
|
|
|
@@ -1349,10 +1356,3 @@ Gaussian standard deviation used for post-pretrain connection-weight diversifica
|
|
|
1349
1356
|
After the template network is trained once, each genome receives a noisy copy
|
|
1350
1357
|
of its weights. That keeps generation 0 visually coherent while preserving
|
|
1351
1358
|
enough diversity for NEAT to search meaningfully.
|
|
1352
|
-
|
|
1353
|
-
### FLAPPY_WORKER_GEN0_PRETRAIN_BIAS_NOISE_STDDEV
|
|
1354
|
-
|
|
1355
|
-
Gaussian standard deviation used for post-pretrain node-bias diversification.
|
|
1356
|
-
|
|
1357
|
-
Bias noise is slightly smaller than weight noise so the warm-start remains a
|
|
1358
|
-
prior, not a rigid clone of the teacher-fitted template.
|