@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
|
@@ -88,49 +88,6 @@ if (distance < neat.options.compatibilityThreshold) {
|
|
|
88
88
|
|
|
89
89
|
## neat/compat/compat.ts
|
|
90
90
|
|
|
91
|
-
### _fallbackInnov
|
|
92
|
-
|
|
93
|
-
```ts
|
|
94
|
-
_fallbackInnov(
|
|
95
|
-
connection: ConnectionLike,
|
|
96
|
-
): number
|
|
97
|
-
```
|
|
98
|
-
|
|
99
|
-
Generate a deterministic fallback innovation id for a connection when the
|
|
100
|
-
connection does not provide an explicit innovation number.
|
|
101
|
-
|
|
102
|
-
Innovation numbers are the canonical alignment key because they let NEAT
|
|
103
|
-
distinguish matching genes from disjoint or excess ones across topology
|
|
104
|
-
changes. This fallback only exists for the boundary cases where a connection
|
|
105
|
-
arrives without that explicit identifier. In that case the helper derives a
|
|
106
|
-
stable directional id from the connection endpoints so the comparison can
|
|
107
|
-
still proceed instead of silently dropping structure from the distance read.
|
|
108
|
-
|
|
109
|
-
Interpret the fallback as a bridge, not as a replacement for properly tracked
|
|
110
|
-
innovations. It keeps compatibility useful for legacy, test, or partially
|
|
111
|
-
normalized genomes, but explicit innovation numbers remain the source of
|
|
112
|
-
truth whenever they are available. A fallback match should therefore be read
|
|
113
|
-
as "these connections occupy the same directed slot" rather than "these two
|
|
114
|
-
genes are proven to share the same historical innovation event."
|
|
115
|
-
|
|
116
|
-
Parameters:
|
|
117
|
-
- `this` - - NEAT context kept for symmetry with the other compatibility helpers.
|
|
118
|
-
- `connection` - - Connection object expected to contain `from.index` and `to.index`.
|
|
119
|
-
|
|
120
|
-
Returns: Numeric innovation id derived from the directional endpoint pair.
|
|
121
|
-
|
|
122
|
-
Example:
|
|
123
|
-
|
|
124
|
-
```ts
|
|
125
|
-
const fallbackInnovation = neat._fallbackInnov({
|
|
126
|
-
from: { index: 4 },
|
|
127
|
-
to: { index: 9 },
|
|
128
|
-
weight: 0.75,
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
// The same endpoint pair always resolves to the same synthetic id.
|
|
132
|
-
```
|
|
133
|
-
|
|
134
91
|
### _compatibilityDistance
|
|
135
92
|
|
|
136
93
|
```ts
|
|
@@ -184,3 +141,46 @@ const speciesBoundaryDistance = neat._compatibilityDistance(genomeA, genomeB);
|
|
|
184
141
|
const sameSpecies =
|
|
185
142
|
speciesBoundaryDistance <= neat.options.compatibilityThreshold;
|
|
186
143
|
```
|
|
144
|
+
|
|
145
|
+
### _fallbackInnov
|
|
146
|
+
|
|
147
|
+
```ts
|
|
148
|
+
_fallbackInnov(
|
|
149
|
+
connection: ConnectionLike,
|
|
150
|
+
): number
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
Generate a deterministic fallback innovation id for a connection when the
|
|
154
|
+
connection does not provide an explicit innovation number.
|
|
155
|
+
|
|
156
|
+
Innovation numbers are the canonical alignment key because they let NEAT
|
|
157
|
+
distinguish matching genes from disjoint or excess ones across topology
|
|
158
|
+
changes. This fallback only exists for the boundary cases where a connection
|
|
159
|
+
arrives without that explicit identifier. In that case the helper derives a
|
|
160
|
+
stable directional id from the connection endpoints so the comparison can
|
|
161
|
+
still proceed instead of silently dropping structure from the distance read.
|
|
162
|
+
|
|
163
|
+
Interpret the fallback as a bridge, not as a replacement for properly tracked
|
|
164
|
+
innovations. It keeps compatibility useful for legacy, test, or partially
|
|
165
|
+
normalized genomes, but explicit innovation numbers remain the source of
|
|
166
|
+
truth whenever they are available. A fallback match should therefore be read
|
|
167
|
+
as "these connections occupy the same directed slot" rather than "these two
|
|
168
|
+
genes are proven to share the same historical innovation event."
|
|
169
|
+
|
|
170
|
+
Parameters:
|
|
171
|
+
- `this` - - NEAT context kept for symmetry with the other compatibility helpers.
|
|
172
|
+
- `connection` - - Connection object expected to contain `from.index` and `to.index`.
|
|
173
|
+
|
|
174
|
+
Returns: Numeric innovation id derived from the directional endpoint pair.
|
|
175
|
+
|
|
176
|
+
Example:
|
|
177
|
+
|
|
178
|
+
```ts
|
|
179
|
+
const fallbackInnovation = neat._fallbackInnov({
|
|
180
|
+
from: { index: 4 },
|
|
181
|
+
to: { index: 9 },
|
|
182
|
+
weight: 0.75,
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
// The same endpoint pair always resolves to the same synthetic id.
|
|
186
|
+
```
|
|
@@ -36,6 +36,15 @@ Practical reading order:
|
|
|
36
36
|
|
|
37
37
|
## neat/compat/core/compat.types.ts
|
|
38
38
|
|
|
39
|
+
### ComparisonMetrics
|
|
40
|
+
|
|
41
|
+
Aggregated comparison metrics for compatibility calculations.
|
|
42
|
+
|
|
43
|
+
`compareInnovationLists()` produces this structure so the final distance fold
|
|
44
|
+
can stay separate from the merge walk that discovered the evidence. That
|
|
45
|
+
split keeps the algorithm easier to explain: one pass classifies the gene
|
|
46
|
+
relationship, a later pass applies the NEAT weighting policy.
|
|
47
|
+
|
|
39
48
|
### ConnectionLike
|
|
40
49
|
|
|
41
50
|
Shape of a connection entry used during compatibility checks.
|
|
@@ -61,15 +70,6 @@ This keeps the boundary tightly focused on generation-scoped caches,
|
|
|
61
70
|
compatibility coefficients, and the fallback innovation resolver instead of
|
|
62
71
|
coupling the mechanics layer to the full `Neat` surface.
|
|
63
72
|
|
|
64
|
-
### ComparisonMetrics
|
|
65
|
-
|
|
66
|
-
Aggregated comparison metrics for compatibility calculations.
|
|
67
|
-
|
|
68
|
-
`compareInnovationLists()` produces this structure so the final distance fold
|
|
69
|
-
can stay separate from the merge walk that discovered the evidence. That
|
|
70
|
-
split keeps the algorithm easier to explain: one pass classifies the gene
|
|
71
|
-
relationship, a later pass applies the NEAT weighting policy.
|
|
72
|
-
|
|
73
73
|
## neat/compat/core/compat.core.ts
|
|
74
74
|
|
|
75
75
|
Compatibility-distance mechanics used by NEAT speciation.
|
|
@@ -84,27 +84,6 @@ The helpers are deliberately small and ordered to match the real execution
|
|
|
84
84
|
path: stabilize caches, normalize genomes, compare aligned innovations, then
|
|
85
85
|
fold the discovered evidence into the NEAT distance formula.
|
|
86
86
|
|
|
87
|
-
### ensureGenerationCache
|
|
88
|
-
|
|
89
|
-
```ts
|
|
90
|
-
ensureGenerationCache(
|
|
91
|
-
neatContext: NeatLikeForCompat,
|
|
92
|
-
): void
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
Ensure generation-scoped compatibility caches exist.
|
|
96
|
-
|
|
97
|
-
The compatibility layer keeps pairwise distance results only for the current
|
|
98
|
-
generation because the population can mutate between generations. Once that
|
|
99
|
-
happens, earlier distances are no longer trustworthy. This helper provides
|
|
100
|
-
the safety boundary that drops stale cache state before later helpers assume
|
|
101
|
-
a cache map exists.
|
|
102
|
-
|
|
103
|
-
Parameters:
|
|
104
|
-
- `neatContext` - - Current NEAT context holding generation and caches.
|
|
105
|
-
|
|
106
|
-
Returns: Nothing. The helper resets caches when the generation changes.
|
|
107
|
-
|
|
108
87
|
### buildPairKey
|
|
109
88
|
|
|
110
89
|
```ts
|
|
@@ -126,6 +105,87 @@ Parameters:
|
|
|
126
105
|
|
|
127
106
|
Returns: Stable cache key in the form `minId|maxId`.
|
|
128
107
|
|
|
108
|
+
### compareInnovationLists
|
|
109
|
+
|
|
110
|
+
```ts
|
|
111
|
+
compareInnovationLists(
|
|
112
|
+
firstList: [number, number][],
|
|
113
|
+
secondList: [number, number][],
|
|
114
|
+
): ComparisonMetrics
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Compare two sorted innovation lists and derive compatibility metrics.
|
|
118
|
+
|
|
119
|
+
This is the heart of the compatibility read. Because both lists are sorted,
|
|
120
|
+
the helper can walk them once like a merge step: matching innovations count
|
|
121
|
+
toward aligned genes, gaps inside the shared innovation range become disjoint
|
|
122
|
+
genes, and the remaining tail genes become excess. Weight differences are
|
|
123
|
+
only measured for matching genes because that is the only case where the two
|
|
124
|
+
genomes clearly refer to the same structural gene.
|
|
125
|
+
|
|
126
|
+
Parameters:
|
|
127
|
+
- `firstList` - - Sorted innovation list for the first genome.
|
|
128
|
+
- `secondList` - - Sorted innovation list for the second genome.
|
|
129
|
+
|
|
130
|
+
Returns: Aggregated comparison metrics for distance computation.
|
|
131
|
+
|
|
132
|
+
### computeCompatibilityDistance
|
|
133
|
+
|
|
134
|
+
```ts
|
|
135
|
+
computeCompatibilityDistance(
|
|
136
|
+
neatContext: NeatLikeForCompat,
|
|
137
|
+
metrics: ComparisonMetrics,
|
|
138
|
+
): number
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
Compute the compatibility distance from precomputed metrics.
|
|
142
|
+
|
|
143
|
+
This fold turns the raw comparison evidence into the familiar NEAT distance:
|
|
144
|
+
excess structure penalty, disjoint structure penalty, and average matching
|
|
145
|
+
weight drift. Structural counts are normalized by the larger genome size so
|
|
146
|
+
larger topologies do not inflate distance merely because they contain more
|
|
147
|
+
possible genes.
|
|
148
|
+
|
|
149
|
+
Parameters:
|
|
150
|
+
- `neatContext` - - NEAT context providing compatibility coefficients.
|
|
151
|
+
- `metrics` - - Aggregated comparison metrics.
|
|
152
|
+
|
|
153
|
+
Returns: Final compatibility distance for the genome pair.
|
|
154
|
+
|
|
155
|
+
Example:
|
|
156
|
+
|
|
157
|
+
```ts
|
|
158
|
+
const distance = computeCompatibilityDistance(neat, {
|
|
159
|
+
firstGenomeSize: 12,
|
|
160
|
+
secondGenomeSize: 10,
|
|
161
|
+
matchingCount: 8,
|
|
162
|
+
disjointCount: 1,
|
|
163
|
+
excessCount: 2,
|
|
164
|
+
weightDifferenceSum: 0.9,
|
|
165
|
+
});
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
### ensureGenerationCache
|
|
169
|
+
|
|
170
|
+
```ts
|
|
171
|
+
ensureGenerationCache(
|
|
172
|
+
neatContext: NeatLikeForCompat,
|
|
173
|
+
): void
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
Ensure generation-scoped compatibility caches exist.
|
|
177
|
+
|
|
178
|
+
The compatibility layer keeps pairwise distance results only for the current
|
|
179
|
+
generation because the population can mutate between generations. Once that
|
|
180
|
+
happens, earlier distances are no longer trustworthy. This helper provides
|
|
181
|
+
the safety boundary that drops stale cache state before later helpers assume
|
|
182
|
+
a cache map exists.
|
|
183
|
+
|
|
184
|
+
Parameters:
|
|
185
|
+
- `neatContext` - - Current NEAT context holding generation and caches.
|
|
186
|
+
|
|
187
|
+
Returns: Nothing. The helper resets caches when the generation changes.
|
|
188
|
+
|
|
129
189
|
### getDistanceCacheMap
|
|
130
190
|
|
|
131
191
|
```ts
|
|
@@ -176,30 +236,6 @@ const innovationPairs = getSortedInnovationCache(neat, genome);
|
|
|
176
236
|
// [[3, 0.12], [8, -0.7], [11, 0.44]]
|
|
177
237
|
```
|
|
178
238
|
|
|
179
|
-
### compareInnovationLists
|
|
180
|
-
|
|
181
|
-
```ts
|
|
182
|
-
compareInnovationLists(
|
|
183
|
-
firstList: [number, number][],
|
|
184
|
-
secondList: [number, number][],
|
|
185
|
-
): ComparisonMetrics
|
|
186
|
-
```
|
|
187
|
-
|
|
188
|
-
Compare two sorted innovation lists and derive compatibility metrics.
|
|
189
|
-
|
|
190
|
-
This is the heart of the compatibility read. Because both lists are sorted,
|
|
191
|
-
the helper can walk them once like a merge step: matching innovations count
|
|
192
|
-
toward aligned genes, gaps inside the shared innovation range become disjoint
|
|
193
|
-
genes, and the remaining tail genes become excess. Weight differences are
|
|
194
|
-
only measured for matching genes because that is the only case where the two
|
|
195
|
-
genomes clearly refer to the same structural gene.
|
|
196
|
-
|
|
197
|
-
Parameters:
|
|
198
|
-
- `firstList` - - Sorted innovation list for the first genome.
|
|
199
|
-
- `secondList` - - Sorted innovation list for the second genome.
|
|
200
|
-
|
|
201
|
-
Returns: Aggregated comparison metrics for distance computation.
|
|
202
|
-
|
|
203
239
|
### resolveMaxInnovation
|
|
204
240
|
|
|
205
241
|
```ts
|
|
@@ -219,39 +255,3 @@ Parameters:
|
|
|
219
255
|
- `list` - - Sorted innovation list for a genome.
|
|
220
256
|
|
|
221
257
|
Returns: Highest innovation id or `0` when the list is empty.
|
|
222
|
-
|
|
223
|
-
### computeCompatibilityDistance
|
|
224
|
-
|
|
225
|
-
```ts
|
|
226
|
-
computeCompatibilityDistance(
|
|
227
|
-
neatContext: NeatLikeForCompat,
|
|
228
|
-
metrics: ComparisonMetrics,
|
|
229
|
-
): number
|
|
230
|
-
```
|
|
231
|
-
|
|
232
|
-
Compute the compatibility distance from precomputed metrics.
|
|
233
|
-
|
|
234
|
-
This fold turns the raw comparison evidence into the familiar NEAT distance:
|
|
235
|
-
excess structure penalty, disjoint structure penalty, and average matching
|
|
236
|
-
weight drift. Structural counts are normalized by the larger genome size so
|
|
237
|
-
larger topologies do not inflate distance merely because they contain more
|
|
238
|
-
possible genes.
|
|
239
|
-
|
|
240
|
-
Parameters:
|
|
241
|
-
- `neatContext` - - NEAT context providing compatibility coefficients.
|
|
242
|
-
- `metrics` - - Aggregated comparison metrics.
|
|
243
|
-
|
|
244
|
-
Returns: Final compatibility distance for the genome pair.
|
|
245
|
-
|
|
246
|
-
Example:
|
|
247
|
-
|
|
248
|
-
```ts
|
|
249
|
-
const distance = computeCompatibilityDistance(neat, {
|
|
250
|
-
firstGenomeSize: 12,
|
|
251
|
-
secondGenomeSize: 10,
|
|
252
|
-
matchingCount: 8,
|
|
253
|
-
disjointCount: 1,
|
|
254
|
-
excessCount: 2,
|
|
255
|
-
weightDifferenceSum: 0.9,
|
|
256
|
-
});
|
|
257
|
-
```
|
|
@@ -39,30 +39,24 @@ public read flow and the meaning of the resulting summary.
|
|
|
39
39
|
|
|
40
40
|
## neat/diversity/diversity.ts
|
|
41
41
|
|
|
42
|
-
###
|
|
42
|
+
### buildEmptyDiversityStats
|
|
43
43
|
|
|
44
44
|
```ts
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
):
|
|
45
|
+
buildEmptyDiversityStats(
|
|
46
|
+
populationSize: number,
|
|
47
|
+
): DiversityStats
|
|
48
48
|
```
|
|
49
49
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
Structural entropy here is a lightweight topology fingerprint: it measures
|
|
53
|
-
how evenly outgoing connections are distributed across nodes. It does not
|
|
54
|
-
inspect weights or recurrent dynamics, so it works well as a cheap structural
|
|
55
|
-
diversity signal.
|
|
50
|
+
Build a zeroed diversity snapshot when no sampled metrics exist yet.
|
|
56
51
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
concentrated into a few hubs.
|
|
52
|
+
This helper gives controller facades and diagnostics a safe fallback object
|
|
53
|
+
whose shape matches ordinary diversity output without pretending that real
|
|
54
|
+
real sampling work has happened yet.
|
|
61
55
|
|
|
62
56
|
Parameters:
|
|
63
|
-
- `
|
|
57
|
+
- `populationSize` - - Population size to echo into the empty snapshot.
|
|
64
58
|
|
|
65
|
-
Returns:
|
|
59
|
+
Returns: Diversity stats object with zeroed aggregates.
|
|
66
60
|
|
|
67
61
|
### computeDiversityStats
|
|
68
62
|
|
|
@@ -106,25 +100,6 @@ if (diversity) {
|
|
|
106
100
|
}
|
|
107
101
|
```
|
|
108
102
|
|
|
109
|
-
### buildEmptyDiversityStats
|
|
110
|
-
|
|
111
|
-
```ts
|
|
112
|
-
buildEmptyDiversityStats(
|
|
113
|
-
populationSize: number,
|
|
114
|
-
): DiversityStats
|
|
115
|
-
```
|
|
116
|
-
|
|
117
|
-
Build a zeroed diversity snapshot when no sampled metrics exist yet.
|
|
118
|
-
|
|
119
|
-
This helper gives controller facades and diagnostics a safe fallback object
|
|
120
|
-
whose shape matches ordinary diversity output without pretending that real
|
|
121
|
-
real sampling work has happened yet.
|
|
122
|
-
|
|
123
|
-
Parameters:
|
|
124
|
-
- `populationSize` - - Population size to echo into the empty snapshot.
|
|
125
|
-
|
|
126
|
-
Returns: Diversity stats object with zeroed aggregates.
|
|
127
|
-
|
|
128
103
|
### DiversityStats
|
|
129
104
|
|
|
130
105
|
Diversity statistics returned by sampled population analysis.
|
|
@@ -158,3 +133,28 @@ Lineage spread is useful for telemetry, but full all-pairs ancestry distance
|
|
|
158
133
|
becomes expensive quickly. This cap keeps the lineage side of the report
|
|
159
134
|
bounded while still surfacing whether ancestry depth is bunching up or
|
|
160
135
|
staying distributed.
|
|
136
|
+
|
|
137
|
+
### structuralEntropy
|
|
138
|
+
|
|
139
|
+
```ts
|
|
140
|
+
structuralEntropy(
|
|
141
|
+
graph: default,
|
|
142
|
+
): number
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
Compute the Shannon-style entropy of a network's out-degree distribution.
|
|
146
|
+
|
|
147
|
+
Structural entropy here is a lightweight topology fingerprint: it measures
|
|
148
|
+
how evenly outgoing connections are distributed across nodes. It does not
|
|
149
|
+
inspect weights or recurrent dynamics, so it works well as a cheap structural
|
|
150
|
+
diversity signal.
|
|
151
|
+
|
|
152
|
+
Use this when you want to compare the shape of individual networks or add one
|
|
153
|
+
more structural signal beside raw node and connection counts. Higher values
|
|
154
|
+
generally mean connectivity is spread across more nodes instead of being
|
|
155
|
+
concentrated into a few hubs.
|
|
156
|
+
|
|
157
|
+
Parameters:
|
|
158
|
+
- `graph` - - Network to summarize structurally.
|
|
159
|
+
|
|
160
|
+
Returns: Shannon-style entropy of the out-degree distribution.
|
|
@@ -17,30 +17,6 @@ Read the chapter in this order:
|
|
|
17
17
|
|
|
18
18
|
## neat/diversity/core/diversity.types.ts
|
|
19
19
|
|
|
20
|
-
### NodeWithConnections
|
|
21
|
-
|
|
22
|
-
Minimal node interface used by diversity computations.
|
|
23
|
-
|
|
24
|
-
Diversity helpers only need each node's outgoing connection count to build a
|
|
25
|
-
structural-entropy fingerprint, so this type keeps the reporting boundary
|
|
26
|
-
narrower than the full runtime node model.
|
|
27
|
-
|
|
28
|
-
### GenomeWithMetrics
|
|
29
|
-
|
|
30
|
-
Minimal genome shape used by diversity computations.
|
|
31
|
-
|
|
32
|
-
This projection is the per-genome input to the diversity report. It exposes
|
|
33
|
-
exactly the data needed to answer four cheap read-side questions:
|
|
34
|
-
|
|
35
|
-
- how large genomes are right now,
|
|
36
|
-
- how uneven that structural size has become,
|
|
37
|
-
- how far sampled ancestry depth has spread,
|
|
38
|
-
- and how compatible each genome remains with sampled peers.
|
|
39
|
-
|
|
40
|
-
Keeping the contract this small lets diagnostics and telemetry reuse the
|
|
41
|
-
diversity helpers against genome-like snapshots rather than the full NEAT
|
|
42
|
-
controller state.
|
|
43
|
-
|
|
44
20
|
### CompatComputer
|
|
45
21
|
|
|
46
22
|
Minimal interface for computing compatibility distance between genomes.
|
|
@@ -67,6 +43,30 @@ In practice, telemetry consumers compare this object across generations to
|
|
|
67
43
|
see whether mutation, speciation, and pruning are still producing meaningful
|
|
68
44
|
variation without paying for exhaustive all-pairs analysis.
|
|
69
45
|
|
|
46
|
+
### GenomeWithMetrics
|
|
47
|
+
|
|
48
|
+
Minimal genome shape used by diversity computations.
|
|
49
|
+
|
|
50
|
+
This projection is the per-genome input to the diversity report. It exposes
|
|
51
|
+
exactly the data needed to answer four cheap read-side questions:
|
|
52
|
+
|
|
53
|
+
- how large genomes are right now,
|
|
54
|
+
- how uneven that structural size has become,
|
|
55
|
+
- how far sampled ancestry depth has spread,
|
|
56
|
+
- and how compatible each genome remains with sampled peers.
|
|
57
|
+
|
|
58
|
+
Keeping the contract this small lets diagnostics and telemetry reuse the
|
|
59
|
+
diversity helpers against genome-like snapshots rather than the full NEAT
|
|
60
|
+
controller state.
|
|
61
|
+
|
|
62
|
+
### NodeWithConnections
|
|
63
|
+
|
|
64
|
+
Minimal node interface used by diversity computations.
|
|
65
|
+
|
|
66
|
+
Diversity helpers only need each node's outgoing connection count to build a
|
|
67
|
+
structural-entropy fingerprint, so this type keeps the reporting boundary
|
|
68
|
+
narrower than the full runtime node model.
|
|
69
|
+
|
|
70
70
|
## neat/diversity/core/diversity.core.ts
|
|
71
71
|
|
|
72
72
|
Diversity-statistics mechanics used by telemetry and diagnostics.
|
|
@@ -84,26 +84,6 @@ analysis, they sample the expensive comparisons and fold the results into a
|
|
|
84
84
|
report that is accurate enough for telemetry trends, diagnostics, and
|
|
85
85
|
generation-over-generation comparisons.
|
|
86
86
|
|
|
87
|
-
### calculateStructuralEntropy
|
|
88
|
-
|
|
89
|
-
```ts
|
|
90
|
-
calculateStructuralEntropy(
|
|
91
|
-
graph: default,
|
|
92
|
-
): number
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
Compute the Shannon-style entropy of a network's out-degree distribution.
|
|
96
|
-
|
|
97
|
-
This is the chapter's shape metric. Two genomes can share similar node and
|
|
98
|
-
connection counts while still distributing edges very differently, so the
|
|
99
|
-
entropy read adds a lightweight topology fingerprint beside the raw size
|
|
100
|
-
aggregates.
|
|
101
|
-
|
|
102
|
-
Parameters:
|
|
103
|
-
- `graph` - - Network instance to evaluate.
|
|
104
|
-
|
|
105
|
-
Returns: Shannon-style entropy value.
|
|
106
|
-
|
|
107
87
|
### calculateDiversityStats
|
|
108
88
|
|
|
109
89
|
```ts
|
|
@@ -141,59 +121,25 @@ if (diversity) {
|
|
|
141
121
|
}
|
|
142
122
|
```
|
|
143
123
|
|
|
144
|
-
###
|
|
145
|
-
|
|
146
|
-
Maximum lineage sample size for pairwise depth comparisons.
|
|
147
|
-
|
|
148
|
-
Lineage spread is useful for telemetry, but full all-pairs ancestry distance
|
|
149
|
-
becomes expensive quickly. This cap keeps the lineage side of the report
|
|
150
|
-
bounded while still surfacing whether ancestry depth is bunching up or
|
|
151
|
-
staying distributed.
|
|
152
|
-
|
|
153
|
-
### MAX_COMPATIBILITY_SAMPLE
|
|
154
|
-
|
|
155
|
-
Maximum population sample size for compatibility comparisons.
|
|
156
|
-
|
|
157
|
-
Compatibility distance is the most obviously quadratic part of the diversity
|
|
158
|
-
report. Sampling lets the controller estimate genetic separation cheaply
|
|
159
|
-
enough to keep diversity reporting on the hot path for telemetry.
|
|
160
|
-
|
|
161
|
-
### mean
|
|
162
|
-
|
|
163
|
-
```ts
|
|
164
|
-
mean(
|
|
165
|
-
values: number[],
|
|
166
|
-
): number
|
|
167
|
-
```
|
|
168
|
-
|
|
169
|
-
Compute the arithmetic mean of a numeric array.
|
|
170
|
-
|
|
171
|
-
The diversity report uses this helper for the direct summary columns such as
|
|
172
|
-
average lineage depth, average node count, average connection count, and the
|
|
173
|
-
mean entropy across genomes.
|
|
174
|
-
|
|
175
|
-
Parameters:
|
|
176
|
-
- `values` - - Values to average.
|
|
177
|
-
|
|
178
|
-
Returns: Arithmetic mean, or `0` when the array is empty.
|
|
179
|
-
|
|
180
|
-
### variance
|
|
124
|
+
### calculateStructuralEntropy
|
|
181
125
|
|
|
182
126
|
```ts
|
|
183
|
-
|
|
184
|
-
|
|
127
|
+
calculateStructuralEntropy(
|
|
128
|
+
graph: default,
|
|
185
129
|
): number
|
|
186
130
|
```
|
|
187
131
|
|
|
188
|
-
Compute the
|
|
132
|
+
Compute the Shannon-style entropy of a network's out-degree distribution.
|
|
189
133
|
|
|
190
|
-
|
|
191
|
-
|
|
134
|
+
This is the chapter's shape metric. Two genomes can share similar node and
|
|
135
|
+
connection counts while still distributing edges very differently, so the
|
|
136
|
+
entropy read adds a lightweight topology fingerprint beside the raw size
|
|
137
|
+
aggregates.
|
|
192
138
|
|
|
193
139
|
Parameters:
|
|
194
|
-
- `
|
|
140
|
+
- `graph` - - Network instance to evaluate.
|
|
195
141
|
|
|
196
|
-
Returns:
|
|
142
|
+
Returns: Shannon-style entropy value.
|
|
197
143
|
|
|
198
144
|
### computeMeanAbsolutePairDistance
|
|
199
145
|
|
|
@@ -240,3 +186,57 @@ Parameters:
|
|
|
240
186
|
- `sampleLimit` - - Maximum number of genomes to include.
|
|
241
187
|
|
|
242
188
|
Returns: Mean compatibility distance across the sampled pairs.
|
|
189
|
+
|
|
190
|
+
### MAX_COMPATIBILITY_SAMPLE
|
|
191
|
+
|
|
192
|
+
Maximum population sample size for compatibility comparisons.
|
|
193
|
+
|
|
194
|
+
Compatibility distance is the most obviously quadratic part of the diversity
|
|
195
|
+
report. Sampling lets the controller estimate genetic separation cheaply
|
|
196
|
+
enough to keep diversity reporting on the hot path for telemetry.
|
|
197
|
+
|
|
198
|
+
### MAX_LINEAGE_PAIR_SAMPLE
|
|
199
|
+
|
|
200
|
+
Maximum lineage sample size for pairwise depth comparisons.
|
|
201
|
+
|
|
202
|
+
Lineage spread is useful for telemetry, but full all-pairs ancestry distance
|
|
203
|
+
becomes expensive quickly. This cap keeps the lineage side of the report
|
|
204
|
+
bounded while still surfacing whether ancestry depth is bunching up or
|
|
205
|
+
staying distributed.
|
|
206
|
+
|
|
207
|
+
### mean
|
|
208
|
+
|
|
209
|
+
```ts
|
|
210
|
+
mean(
|
|
211
|
+
values: number[],
|
|
212
|
+
): number
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
Compute the arithmetic mean of a numeric array.
|
|
216
|
+
|
|
217
|
+
The diversity report uses this helper for the direct summary columns such as
|
|
218
|
+
average lineage depth, average node count, average connection count, and the
|
|
219
|
+
mean entropy across genomes.
|
|
220
|
+
|
|
221
|
+
Parameters:
|
|
222
|
+
- `values` - - Values to average.
|
|
223
|
+
|
|
224
|
+
Returns: Arithmetic mean, or `0` when the array is empty.
|
|
225
|
+
|
|
226
|
+
### variance
|
|
227
|
+
|
|
228
|
+
```ts
|
|
229
|
+
variance(
|
|
230
|
+
values: number[],
|
|
231
|
+
): number
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
Compute the population variance of a numeric array.
|
|
235
|
+
|
|
236
|
+
Variance complements the raw averages by showing whether the population is
|
|
237
|
+
staying structurally tight or spreading into a wider range of topology sizes.
|
|
238
|
+
|
|
239
|
+
Parameters:
|
|
240
|
+
- `values` - - Values to evaluate.
|
|
241
|
+
|
|
242
|
+
Returns: Population variance, or `0` when the array is empty.
|