@reicek/neataptic-ts 0.1.25 → 0.1.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/copilot-instructions.md +11 -0
- package/.github/skills/trace-analyzer-extension/SKILL.md +3 -3
- package/.github/skills/trace-analyzer-extension/assets/extension-checklist.md +1 -1
- package/.github/skills/trace-analyzer-extension/references/analyzer-extension-workflow.md +1 -1
- package/.github/skills/trace-audit-reporting/SKILL.md +3 -3
- package/.github/skills/trace-audit-reporting/references/trace-analysis-workflow.md +1 -1
- package/package.json +19 -13
- package/plans/Flappy_Bird_Folder_Documentation_Pass.md +4 -4
- package/plans/README.md +24 -0
- package/plans/Roadmap.md +62 -40
- package/plans/analyze-trace-solid-split.plans.md +66 -0
- package/plans/architecture-solid-split.plans.md +9 -15
- package/plans/asciiMaze-typescript-repair.plans.md +1 -1
- package/plans/generate-docs-solid-split.plans.md +87 -0
- package/plans/methods-docs.plans.md +25 -1
- package/plans/methods-solid-split.plans.md +14 -14
- package/plans/neat-docs.plans.md +9 -1
- package/plans/neat-test-surface-repair.plans.md +1 -1
- package/plans/render-docs-html-solid-split.plans.md +68 -0
- package/plans/src-no-explicit-any-cleanup.plans.md +1 -1
- package/plans/utils-docs.plans.md +6 -1
- package/scripts/analyze-trace/analyze-trace.analysis.ts +479 -0
- package/scripts/analyze-trace/analyze-trace.constants.ts +35 -0
- package/scripts/analyze-trace/analyze-trace.io.ts +69 -0
- package/scripts/analyze-trace/analyze-trace.report.ts +100 -0
- package/scripts/analyze-trace/analyze-trace.shared.ts +116 -0
- package/scripts/analyze-trace/analyze-trace.ts +45 -0
- package/scripts/analyze-trace/analyze-trace.types.ts +72 -0
- package/scripts/assets/theme.css +80 -23
- package/scripts/copy-examples.ts +239 -0
- package/scripts/export-onnx.ts +223 -0
- package/scripts/generate-bench-tables.ts +378 -37
- package/scripts/generate-docs/generate-docs.constants.ts +107 -0
- package/scripts/generate-docs/generate-docs.order.ts +355 -0
- package/scripts/generate-docs/generate-docs.state.ts +31 -0
- package/scripts/generate-docs/generate-docs.targets.ts +165 -0
- package/scripts/generate-docs/generate-docs.ts +63 -0
- package/scripts/generate-docs/generate-docs.types.ts +112 -0
- package/scripts/generate-docs/output/generate-docs.output.folder-index.utils.ts +167 -0
- package/scripts/generate-docs/output/generate-docs.output.ordering.utils.ts +353 -0
- package/scripts/generate-docs/output/generate-docs.output.readme.utils.ts +420 -0
- package/scripts/generate-docs/output/generate-docs.output.ts +123 -0
- package/scripts/generate-docs/output/generate-docs.output.warnings.utils.ts +219 -0
- package/scripts/generate-docs/symbols/generate-docs.symbols.collection.utils.ts +365 -0
- package/scripts/generate-docs/symbols/generate-docs.symbols.jsdoc.utils.ts +373 -0
- package/scripts/generate-docs/symbols/generate-docs.symbols.normalize.utils.ts +155 -0
- package/scripts/generate-docs/symbols/generate-docs.symbols.render.utils.ts +149 -0
- package/scripts/generate-docs/symbols/generate-docs.symbols.signature.utils.ts +289 -0
- package/scripts/generate-docs/symbols/generate-docs.symbols.ts +11 -0
- package/scripts/mermaid-cli.mjs +102 -22
- package/scripts/mermaid-cli.ts +736 -0
- package/scripts/render-docs-html/render-docs-html.assets.ts +54 -0
- package/scripts/render-docs-html/render-docs-html.mermaid.ts +245 -0
- package/scripts/{render-docs-html.sidebar.ts → render-docs-html/render-docs-html.navigation.ts} +141 -144
- package/scripts/render-docs-html/render-docs-html.pages.ts +333 -0
- package/scripts/render-docs-html/render-docs-html.shared.ts +333 -0
- package/scripts/render-docs-html/render-docs-html.types.ts +42 -0
- package/scripts/render-docs-html.ts +23 -587
- package/scripts/run-docs.ts +238 -0
- package/scripts/write-dist-docs-pkg.ts +40 -0
- package/src/README.md +75 -75
- package/src/architecture/connection/README.md +5 -5
- package/src/architecture/layer/README.md +508 -508
- package/src/architecture/network/README.md +1458 -1458
- package/src/architecture/network/activate/README.md +694 -694
- package/src/architecture/network/bootstrap/README.md +77 -77
- package/src/architecture/network/connect/README.md +74 -74
- package/src/architecture/network/deterministic/README.md +135 -135
- package/src/architecture/network/evolve/README.md +364 -364
- package/src/architecture/network/gating/README.md +130 -130
- package/src/architecture/network/genetic/README.md +399 -399
- package/src/architecture/network/mutate/README.md +897 -897
- package/src/architecture/network/onnx/README.md +720 -720
- package/src/architecture/network/onnx/export/README.md +728 -728
- package/src/architecture/network/onnx/export/layers/README.md +450 -450
- package/src/architecture/network/onnx/import/README.md +618 -618
- package/src/architecture/network/onnx/schema/README.md +32 -32
- package/src/architecture/network/prune/README.md +245 -245
- package/src/architecture/network/remove/README.md +135 -135
- package/src/architecture/network/runtime/README.md +106 -106
- package/src/architecture/network/serialize/README.md +542 -542
- package/src/architecture/network/slab/README.md +608 -608
- package/src/architecture/network/standalone/README.md +212 -212
- package/src/architecture/network/stats/README.md +84 -84
- package/src/architecture/network/topology/README.md +465 -465
- package/src/architecture/network/training/README.md +200 -200
- package/src/architecture/node/README.md +5 -5
- package/src/architecture/nodePool/README.md +14 -14
- package/src/methods/README.md +99 -99
- package/src/methods/activation/README.md +189 -189
- package/src/methods/cost/README.md +131 -131
- package/src/methods/rate/README.md +86 -86
- package/src/multithreading/README.md +77 -77
- package/src/multithreading/workers/browser/README.md +8 -8
- package/src/multithreading/workers/node/README.md +8 -8
- package/src/neat/README.md +148 -148
- package/src/neat/adaptive/README.md +120 -120
- package/src/neat/adaptive/acceptance/README.md +40 -40
- package/src/neat/adaptive/complexity/README.md +137 -137
- package/src/neat/adaptive/core/README.md +197 -197
- package/src/neat/adaptive/lineage/README.md +90 -90
- package/src/neat/adaptive/mutation/README.md +284 -284
- package/src/neat/compat/README.md +43 -43
- package/src/neat/compat/core/README.md +90 -90
- package/src/neat/diversity/README.md +35 -35
- package/src/neat/diversity/core/README.md +88 -88
- package/src/neat/evaluate/README.md +85 -85
- package/src/neat/evaluate/auto-distance/README.md +75 -75
- package/src/neat/evaluate/entropy-compat/README.md +37 -37
- package/src/neat/evaluate/entropy-sharing/README.md +43 -43
- package/src/neat/evaluate/fitness/README.md +23 -23
- package/src/neat/evaluate/novelty/README.md +120 -120
- package/src/neat/evaluate/objectives/README.md +17 -17
- package/src/neat/evaluate/shared/README.md +94 -94
- package/src/neat/evolve/README.md +96 -96
- package/src/neat/evolve/adaptive/README.md +60 -60
- package/src/neat/evolve/objectives/README.md +63 -63
- package/src/neat/evolve/offspring/README.md +56 -56
- package/src/neat/evolve/population/README.md +171 -171
- package/src/neat/evolve/runtime/README.md +79 -79
- package/src/neat/evolve/speciation/README.md +74 -74
- package/src/neat/evolve/warnings/README.md +10 -10
- package/src/neat/export/README.md +114 -114
- package/src/neat/helpers/README.md +50 -50
- package/src/neat/init/README.md +9 -9
- package/src/neat/lineage/core/README.md +101 -101
- package/src/neat/multiobjective/category/README.md +74 -74
- package/src/neat/multiobjective/crowding/README.md +272 -272
- package/src/neat/multiobjective/dominance/README.md +171 -171
- package/src/neat/multiobjective/fronts/README.md +68 -68
- package/src/neat/multiobjective/metrics/README.md +43 -43
- package/src/neat/multiobjective/objectives/README.md +31 -31
- package/src/neat/multiobjective/shared/README.md +27 -27
- package/src/neat/mutation/README.md +97 -97
- package/src/neat/mutation/add-conn/README.md +115 -115
- package/src/neat/mutation/add-node/README.md +126 -126
- package/src/neat/mutation/flow/README.md +149 -149
- package/src/neat/mutation/repair/README.md +185 -185
- package/src/neat/mutation/select/README.md +117 -117
- package/src/neat/mutation/shared/README.md +32 -32
- package/src/neat/objectives/README.md +25 -25
- package/src/neat/objectives/core/README.md +67 -67
- package/src/neat/pruning/README.md +40 -40
- package/src/neat/pruning/core/README.md +171 -171
- package/src/neat/pruning/facade/README.md +32 -32
- package/src/neat/rng/README.md +104 -104
- package/src/neat/rng/core/README.md +137 -137
- package/src/neat/rng/facade/README.md +50 -50
- package/src/neat/selection/README.md +111 -111
- package/src/neat/selection/core/README.md +227 -227
- package/src/neat/selection/facade/README.md +61 -61
- package/src/neat/shared/README.md +163 -163
- package/src/neat/speciation/README.md +31 -31
- package/src/neat/speciation/threshold/README.md +35 -35
- package/src/neat/species/README.md +25 -25
- package/src/neat/species/core/README.md +20 -20
- package/src/neat/species/core/shared/README.md +18 -18
- package/src/neat/species/history/context/README.md +22 -22
- package/src/neat/telemetry/accessors/README.md +58 -58
- package/src/neat/telemetry/exports/README.md +233 -233
- package/src/neat/telemetry/facade/README.md +252 -252
- package/src/neat/telemetry/facade/archive/README.md +57 -57
- package/src/neat/telemetry/facade/buffer/README.md +43 -43
- package/src/neat/telemetry/facade/lineage/README.md +12 -12
- package/src/neat/telemetry/facade/objectives/README.md +44 -44
- package/src/neat/telemetry/facade/runtime/README.md +26 -26
- package/src/neat/telemetry/facade/species/README.md +27 -27
- package/src/neat/telemetry/metrics/README.md +696 -696
- package/src/neat/telemetry/recorder/README.md +57 -57
- package/src/neat/telemetry/types/README.md +32 -32
- package/src/neat/topology-intent/README.md +75 -75
- package/src/utils/README.md +193 -193
- package/test/examples/asciiMaze/browser-entry/README.md +92 -92
- package/test/examples/asciiMaze/dashboardManager/README.md +109 -109
- package/test/examples/asciiMaze/dashboardManager/telemetry/README.md +28 -28
- package/test/examples/asciiMaze/evolutionEngine/README.md +1527 -1527
- package/test/examples/asciiMaze/mazeMovement/README.md +105 -105
- package/test/examples/asciiMaze/mazeMovement/finalization/README.md +16 -16
- package/test/examples/asciiMaze/mazeMovement/policy/README.md +57 -57
- package/test/examples/asciiMaze/mazeMovement/runtime/README.md +52 -52
- package/test/examples/asciiMaze/mazeMovement/shaping/README.md +46 -46
- package/test/examples/flappy_bird/browser-entry/README.md +508 -508
- package/test/examples/flappy_bird/browser-entry/host/README.md +101 -101
- package/test/examples/flappy_bird/browser-entry/host/resize/README.md +144 -144
- package/test/examples/flappy_bird/browser-entry/network-view/README.md +194 -194
- package/test/examples/flappy_bird/browser-entry/playback/README.md +278 -278
- package/test/examples/flappy_bird/browser-entry/playback/background/README.md +129 -129
- package/test/examples/flappy_bird/browser-entry/playback/background/ground-grid/README.md +502 -502
- package/test/examples/flappy_bird/browser-entry/playback/frame-render/README.md +139 -139
- package/test/examples/flappy_bird/browser-entry/playback/snapshot/README.md +10 -10
- package/test/examples/flappy_bird/browser-entry/playback/trail/README.md +43 -43
- package/test/examples/flappy_bird/browser-entry/playback/worker-channel/README.md +30 -30
- package/test/examples/flappy_bird/browser-entry/runtime/README.md +59 -59
- package/test/examples/flappy_bird/browser-entry/visualization/README.md +276 -276
- package/test/examples/flappy_bird/browser-entry/worker-channel/README.md +16 -16
- package/test/examples/flappy_bird/constants/README.md +1070 -1070
- package/test/examples/flappy_bird/environment/README.md +22 -22
- package/test/examples/flappy_bird/evaluation/README.md +32 -32
- package/test/examples/flappy_bird/evaluation/rollout/README.md +141 -141
- package/test/examples/flappy_bird/flappy-evolution-worker/README.md +425 -425
- package/test/examples/flappy_bird/simulation-shared/README.md +170 -170
- package/test/examples/flappy_bird/simulation-shared/observation/README.md +109 -109
- package/test/examples/flappy_bird/trainer/README.md +325 -325
- package/test/examples/flappy_bird/trainer/evaluation/README.md +74 -74
- package/scripts/analyze-trace.ts +0 -590
- package/scripts/copy-examples.mjs +0 -114
- package/scripts/export-onnx.mjs +0 -86
- package/scripts/generate-bench-tables.mjs +0 -182
- package/scripts/generate-docs.ts +0 -2900
- package/scripts/write-dist-docs-pkg.mjs +0 -16
|
@@ -26,52 +26,26 @@ The wrapper surface naturally falls into three pairs:
|
|
|
26
26
|
|
|
27
27
|
## neat/rng/facade/rng.facade.ts
|
|
28
28
|
|
|
29
|
-
###
|
|
29
|
+
### exportRNGState
|
|
30
30
|
|
|
31
31
|
```ts
|
|
32
|
-
|
|
32
|
+
exportRNGState(
|
|
33
33
|
host: RngHost,
|
|
34
34
|
): number | undefined
|
|
35
35
|
```
|
|
36
36
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
This is mainly useful for deterministic replay, test fixtures, and bug
|
|
40
|
-
reports that need to resume the same random subsequence.
|
|
37
|
+
Export the current RNG state for persistence or debugging.
|
|
41
38
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
39
|
+
Use this wrapper when the replay token is likely to leave the immediate call
|
|
40
|
+
site, such as checkpoint serialization, fixture capture, or bug-report
|
|
41
|
+
handoff. Compared with `snapshotRNGState()`, the emphasis here is portability
|
|
42
|
+
rather than momentary inspection.
|
|
45
43
|
|
|
46
44
|
Parameters:
|
|
47
45
|
- `host` - - `Neat` instance exposing RNG state.
|
|
48
46
|
|
|
49
47
|
Returns: Numeric RNG state or `undefined` when the RNG has not been initialized.
|
|
50
48
|
|
|
51
|
-
### restoreRNGState
|
|
52
|
-
|
|
53
|
-
```ts
|
|
54
|
-
restoreRNGState(
|
|
55
|
-
host: RngHost,
|
|
56
|
-
state: string | number | undefined,
|
|
57
|
-
): void
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
Restore a previously captured RNG state.
|
|
61
|
-
|
|
62
|
-
The next RNG access will continue from the restored subsequence, which makes
|
|
63
|
-
it useful for replaying evolution bugs or comparing deterministic traces.
|
|
64
|
-
|
|
65
|
-
Pair this with `snapshotRNGState()` or `exportRNGState()` when you want to
|
|
66
|
-
prove that two runs consume the same future subsequence. The wrapper does not
|
|
67
|
-
draw a random number itself; it only repositions the next draw.
|
|
68
|
-
|
|
69
|
-
Parameters:
|
|
70
|
-
- `host` - - `Neat` instance exposing RNG state.
|
|
71
|
-
- `state` - - Numeric or string seed snapshot to restore.
|
|
72
|
-
|
|
73
|
-
Returns: Nothing. The helper mutates the host RNG state in place.
|
|
74
|
-
|
|
75
49
|
### importRNGState
|
|
76
50
|
|
|
77
51
|
```ts
|
|
@@ -95,25 +69,41 @@ Parameters:
|
|
|
95
69
|
|
|
96
70
|
Returns: Nothing. The helper mutates the host RNG state in place.
|
|
97
71
|
|
|
98
|
-
###
|
|
72
|
+
### NeatRngFacadeHost
|
|
73
|
+
|
|
74
|
+
Narrow `Neat` host surface required by the public RNG facade.
|
|
75
|
+
|
|
76
|
+
This stays intentionally small because the facade only forwards state
|
|
77
|
+
snapshot, restore, export, and sampling calls into the existing RNG helpers.
|
|
78
|
+
|
|
79
|
+
Keeping the host contract tiny protects the public wrapper boundary from the
|
|
80
|
+
rest of the controller. Replay helpers need RNG state, optional configuration,
|
|
81
|
+
and lightweight population context, but they do not need mutation, selection,
|
|
82
|
+
or telemetry internals.
|
|
83
|
+
|
|
84
|
+
### restoreRNGState
|
|
99
85
|
|
|
100
86
|
```ts
|
|
101
|
-
|
|
87
|
+
restoreRNGState(
|
|
102
88
|
host: RngHost,
|
|
103
|
-
|
|
89
|
+
state: string | number | undefined,
|
|
90
|
+
): void
|
|
104
91
|
```
|
|
105
92
|
|
|
106
|
-
|
|
93
|
+
Restore a previously captured RNG state.
|
|
107
94
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
95
|
+
The next RNG access will continue from the restored subsequence, which makes
|
|
96
|
+
it useful for replaying evolution bugs or comparing deterministic traces.
|
|
97
|
+
|
|
98
|
+
Pair this with `snapshotRNGState()` or `exportRNGState()` when you want to
|
|
99
|
+
prove that two runs consume the same future subsequence. The wrapper does not
|
|
100
|
+
draw a random number itself; it only repositions the next draw.
|
|
112
101
|
|
|
113
102
|
Parameters:
|
|
114
103
|
- `host` - - `Neat` instance exposing RNG state.
|
|
104
|
+
- `state` - - Numeric or string seed snapshot to restore.
|
|
115
105
|
|
|
116
|
-
Returns:
|
|
106
|
+
Returns: Nothing. The helper mutates the host RNG state in place.
|
|
117
107
|
|
|
118
108
|
### sampleRandom
|
|
119
109
|
|
|
@@ -149,14 +139,24 @@ const repeatedSequence = neat.sampleRandom(3);
|
|
|
149
139
|
console.log(firstSequence, repeatedSequence);
|
|
150
140
|
```
|
|
151
141
|
|
|
152
|
-
###
|
|
142
|
+
### snapshotRNGState
|
|
153
143
|
|
|
154
|
-
|
|
144
|
+
```ts
|
|
145
|
+
snapshotRNGState(
|
|
146
|
+
host: RngHost,
|
|
147
|
+
): number | undefined
|
|
148
|
+
```
|
|
155
149
|
|
|
156
|
-
|
|
157
|
-
snapshot, restore, export, and sampling calls into the existing RNG helpers.
|
|
150
|
+
Return the current opaque RNG numeric state used by the instance.
|
|
158
151
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
152
|
+
This is mainly useful for deterministic replay, test fixtures, and bug
|
|
153
|
+
reports that need to resume the same random subsequence.
|
|
154
|
+
|
|
155
|
+
Prefer this wrapper when the state is staying inside the current debugging or
|
|
156
|
+
test session. It captures the current numeric position without implying that
|
|
157
|
+
the token is about to cross a persistence boundary.
|
|
158
|
+
|
|
159
|
+
Parameters:
|
|
160
|
+
- `host` - - `Neat` instance exposing RNG state.
|
|
161
|
+
|
|
162
|
+
Returns: Numeric RNG state or `undefined` when the RNG has not been initialized.
|
|
@@ -98,59 +98,79 @@ const parent = neat.getParent();
|
|
|
98
98
|
|
|
99
99
|
## neat/selection/selection.ts
|
|
100
100
|
|
|
101
|
-
###
|
|
101
|
+
### DEFAULT_POWER
|
|
102
102
|
|
|
103
|
-
|
|
104
|
-
sort(): void
|
|
105
|
-
```
|
|
103
|
+
Default power exponent for POWER selection when none is configured.
|
|
106
104
|
|
|
107
|
-
|
|
105
|
+
A value of `1` keeps POWER selection as a direct index-bias curve without
|
|
106
|
+
adding extra front-loading beyond the strategy's normal rank preference.
|
|
107
|
+
That makes this the mildest built-in pressure setting: strong enough to
|
|
108
|
+
prefer the front of the sorted population, but not so aggressive that the
|
|
109
|
+
champion becomes nearly inevitable on every draw.
|
|
108
110
|
|
|
109
|
-
|
|
110
|
-
best-first order. The helper applies the same fallback-score semantics used
|
|
111
|
-
elsewhere in selection, so genomes without a score are treated as if they had
|
|
112
|
-
{@link DEFAULT_SCORE} until evaluation supplies a real value.
|
|
111
|
+
### DEFAULT_SCORE
|
|
113
112
|
|
|
114
|
-
|
|
115
|
-
It does not evaluate genomes, mutate them, or change the active parent
|
|
116
|
-
selection strategy.
|
|
113
|
+
Default score when a genome has no explicit score.
|
|
117
114
|
|
|
118
|
-
|
|
115
|
+
Selection uses one shared fallback so summaries, sorting, and threshold scans
|
|
116
|
+
all interpret unevaluated or missing scores consistently. That matters for
|
|
117
|
+
chapter coherence as much as runtime behavior: every inspection helper and
|
|
118
|
+
parent-selection guard speaks the same "missing score" language instead of
|
|
119
|
+
inventing its own local default.
|
|
119
120
|
|
|
120
|
-
|
|
121
|
+
### DEFAULT_TOURNAMENT_PROBABILITY
|
|
121
122
|
|
|
122
|
-
|
|
123
|
-
neat.sort();
|
|
124
|
-
const bestScore = neat.population[0]?.score;
|
|
125
|
-
```
|
|
123
|
+
Default tournament win probability when none is configured.
|
|
126
124
|
|
|
127
|
-
|
|
125
|
+
This keeps the top sampled participant favored while still allowing weaker
|
|
126
|
+
entrants to remain reachable later in the tournament walk. Read it as the
|
|
127
|
+
tournament counterpart to selection pressure: a balanced default that keeps
|
|
128
|
+
the bracket competitive instead of turning every mini-tournament into a
|
|
129
|
+
guaranteed top-seed march.
|
|
130
|
+
|
|
131
|
+
### DEFAULT_TOURNAMENT_SIZE
|
|
132
|
+
|
|
133
|
+
Default tournament size when none is configured.
|
|
134
|
+
|
|
135
|
+
The built-in bracket stays intentionally small so tournament selection keeps
|
|
136
|
+
some competitive pressure without collapsing into near-deterministic champion
|
|
137
|
+
picks. In practice this means the default strategy samples just enough local
|
|
138
|
+
competition to reward strong genomes while still letting non-champion genomes
|
|
139
|
+
remain reachable.
|
|
140
|
+
|
|
141
|
+
### FIRST_INDEX
|
|
142
|
+
|
|
143
|
+
First element index used by guards, fallbacks, and best-first reads.
|
|
144
|
+
|
|
145
|
+
Selection logic names this index explicitly because the front of the
|
|
146
|
+
population has semantic meaning: it is where champion reads and sorted-bias
|
|
147
|
+
strategies begin.
|
|
148
|
+
|
|
149
|
+
### getAverage
|
|
128
150
|
|
|
129
151
|
```ts
|
|
130
|
-
|
|
152
|
+
getAverage(): number
|
|
131
153
|
```
|
|
132
154
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
This is the controller-facing gateway into the three built-in strategies:
|
|
155
|
+
Compute the average fitness across the population.
|
|
136
156
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
win probability.
|
|
157
|
+
Use this when you want a coarse health signal for the whole generation rather
|
|
158
|
+
than the single best genome. The helper ensures evaluation has happened,
|
|
159
|
+
folds the total score across the full population, and returns the arithmetic
|
|
160
|
+
mean that telemetry, progress logging, and quick sanity checks usually need.
|
|
142
161
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
162
|
+
Unlike parent selection, this helper does not care about order. It reports on
|
|
163
|
+
the population as a group, which makes it a convenient companion to
|
|
164
|
+
{@link getFittest} when you want both "best genome" and "overall generation"
|
|
165
|
+
signals side by side.
|
|
146
166
|
|
|
147
|
-
Returns:
|
|
167
|
+
Returns: Mean fitness across the current population.
|
|
148
168
|
|
|
149
169
|
Example:
|
|
150
170
|
|
|
151
171
|
```ts
|
|
152
|
-
const
|
|
153
|
-
|
|
172
|
+
const meanScore = neat.getAverage();
|
|
173
|
+
console.log(`Average score: ${meanScore}`);
|
|
154
174
|
```
|
|
155
175
|
|
|
156
176
|
### getFittest
|
|
@@ -179,88 +199,64 @@ const champion = neat.getFittest();
|
|
|
179
199
|
console.log(champion.score);
|
|
180
200
|
```
|
|
181
201
|
|
|
182
|
-
###
|
|
202
|
+
### getParent
|
|
183
203
|
|
|
184
204
|
```ts
|
|
185
|
-
|
|
205
|
+
getParent(): GenomeWithScore
|
|
186
206
|
```
|
|
187
207
|
|
|
188
|
-
|
|
208
|
+
Select a parent genome according to the configured selection strategy.
|
|
189
209
|
|
|
190
|
-
|
|
191
|
-
than the single best genome. The helper ensures evaluation has happened,
|
|
192
|
-
folds the total score across the full population, and returns the arithmetic
|
|
193
|
-
mean that telemetry, progress logging, and quick sanity checks usually need.
|
|
210
|
+
This is the controller-facing gateway into the three built-in strategies:
|
|
194
211
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
212
|
+
- `POWER` biases selection toward the front of the sorted population,
|
|
213
|
+
- `FITNESS_PROPORTIONATE` performs roulette-style sampling and shifts
|
|
214
|
+
negative scores into a usable threshold space,
|
|
215
|
+
- `TOURNAMENT` samples a temporary bracket and walks it with the configured
|
|
216
|
+
win probability.
|
|
199
217
|
|
|
200
|
-
|
|
218
|
+
If the selection mode is unrecognized, the helper falls back to the first
|
|
219
|
+
genome in the current population so the controller still has a deterministic
|
|
220
|
+
parent candidate instead of failing deep inside crossover logic.
|
|
221
|
+
|
|
222
|
+
Returns: Genome chosen according to the active selection strategy.
|
|
201
223
|
|
|
202
224
|
Example:
|
|
203
225
|
|
|
204
226
|
```ts
|
|
205
|
-
const
|
|
206
|
-
|
|
227
|
+
const parent = neat.getParent();
|
|
228
|
+
const strategyName = neat.options.selection?.name;
|
|
207
229
|
```
|
|
208
230
|
|
|
209
|
-
###
|
|
210
|
-
|
|
211
|
-
Default power exponent for POWER selection when none is configured.
|
|
212
|
-
|
|
213
|
-
A value of `1` keeps POWER selection as a direct index-bias curve without
|
|
214
|
-
adding extra front-loading beyond the strategy's normal rank preference.
|
|
215
|
-
That makes this the mildest built-in pressure setting: strong enough to
|
|
216
|
-
prefer the front of the sorted population, but not so aggressive that the
|
|
217
|
-
champion becomes nearly inevitable on every draw.
|
|
218
|
-
|
|
219
|
-
### DEFAULT_TOURNAMENT_SIZE
|
|
220
|
-
|
|
221
|
-
Default tournament size when none is configured.
|
|
222
|
-
|
|
223
|
-
The built-in bracket stays intentionally small so tournament selection keeps
|
|
224
|
-
some competitive pressure without collapsing into near-deterministic champion
|
|
225
|
-
picks. In practice this means the default strategy samples just enough local
|
|
226
|
-
competition to reward strong genomes while still letting non-champion genomes
|
|
227
|
-
remain reachable.
|
|
228
|
-
|
|
229
|
-
### DEFAULT_TOURNAMENT_PROBABILITY
|
|
231
|
+
### INITIAL_CUMULATIVE_FITNESS
|
|
230
232
|
|
|
231
|
-
|
|
233
|
+
Initial cumulative fitness value for roulette threshold scans.
|
|
232
234
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
the bracket competitive instead of turning every mini-tournament into a
|
|
237
|
-
guaranteed top-seed march.
|
|
235
|
+
Roulette-style selection accumulates shifted fitness as it walks the
|
|
236
|
+
population. This zero point keeps that running threshold explicit and aligned
|
|
237
|
+
with the rest of the selection fallback semantics.
|
|
238
238
|
|
|
239
|
-
###
|
|
239
|
+
### INITIAL_MOST_NEGATIVE_SCORE
|
|
240
240
|
|
|
241
|
-
|
|
241
|
+
Initial most-negative score sentinel for shifted-fitness scans.
|
|
242
242
|
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
parent-selection guard speaks the same "missing score" language instead of
|
|
247
|
-
inventing its own local default.
|
|
243
|
+
FITNESS_PROPORTIONATE selection may need to lift negative scores into a
|
|
244
|
+
usable roulette space, and this sentinel marks the baseline from which that
|
|
245
|
+
most-negative search starts.
|
|
248
246
|
|
|
249
|
-
###
|
|
247
|
+
### INITIAL_TOTAL_FITNESS
|
|
250
248
|
|
|
251
|
-
|
|
249
|
+
Initial accumulator value for generation-wide score folds.
|
|
252
250
|
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
strategies begin.
|
|
251
|
+
Summary helpers begin from this neutral total so whole-population averages
|
|
252
|
+
and other folds remain explicit about their starting score semantics.
|
|
256
253
|
|
|
257
|
-
###
|
|
254
|
+
### LAST_ELEMENT_INDEX
|
|
258
255
|
|
|
259
|
-
|
|
256
|
+
Index used with `at()` when checking the tail of the population.
|
|
260
257
|
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
comparison boundary.
|
|
258
|
+
The evaluation guard only needs the final genome to answer one practical
|
|
259
|
+
question: has this generation already been scored all the way through?
|
|
264
260
|
|
|
265
261
|
### LAST_INDEX_OFFSET
|
|
266
262
|
|
|
@@ -276,32 +272,36 @@ Loop step used by explicit tournament and threshold walks.
|
|
|
276
272
|
Naming the increment makes the small index-based scans read like deliberate
|
|
277
273
|
traversal code instead of scattered magic numbers.
|
|
278
274
|
|
|
279
|
-
###
|
|
280
|
-
|
|
281
|
-
Index used with `at()` when checking the tail of the population.
|
|
275
|
+
### SECOND_INDEX
|
|
282
276
|
|
|
283
|
-
|
|
284
|
-
question: has this generation already been scored all the way through?
|
|
277
|
+
Second element index used by the cheap leading-edge ordering guard.
|
|
285
278
|
|
|
286
|
-
|
|
279
|
+
Comparing the first two genomes is enough for the root helpers' fast
|
|
280
|
+
"probably already sorted" check, so this constant marks the smallest useful
|
|
281
|
+
comparison boundary.
|
|
287
282
|
|
|
288
|
-
|
|
283
|
+
### sort
|
|
289
284
|
|
|
290
|
-
|
|
291
|
-
|
|
285
|
+
```ts
|
|
286
|
+
sort(): void
|
|
287
|
+
```
|
|
292
288
|
|
|
293
|
-
|
|
289
|
+
Sort the internal population in place by descending fitness.
|
|
294
290
|
|
|
295
|
-
|
|
291
|
+
Use this when later controller steps should read the population in explicit
|
|
292
|
+
best-first order. The helper applies the same fallback-score semantics used
|
|
293
|
+
elsewhere in selection, so genomes without a score are treated as if they had
|
|
294
|
+
{@link DEFAULT_SCORE} until evaluation supplies a real value.
|
|
296
295
|
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
296
|
+
This helper is intentionally narrow: it only reorders the current population.
|
|
297
|
+
It does not evaluate genomes, mutate them, or change the active parent
|
|
298
|
+
selection strategy.
|
|
300
299
|
|
|
301
|
-
|
|
300
|
+
Returns: Nothing. The population array is reordered in place.
|
|
302
301
|
|
|
303
|
-
|
|
302
|
+
Example:
|
|
304
303
|
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
304
|
+
```ts
|
|
305
|
+
neat.sort();
|
|
306
|
+
const bestScore = neat.population[0]?.score;
|
|
307
|
+
```
|