@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.
Files changed (210) hide show
  1. package/.github/copilot-instructions.md +11 -0
  2. package/.github/skills/trace-analyzer-extension/SKILL.md +3 -3
  3. package/.github/skills/trace-analyzer-extension/assets/extension-checklist.md +1 -1
  4. package/.github/skills/trace-analyzer-extension/references/analyzer-extension-workflow.md +1 -1
  5. package/.github/skills/trace-audit-reporting/SKILL.md +3 -3
  6. package/.github/skills/trace-audit-reporting/references/trace-analysis-workflow.md +1 -1
  7. package/package.json +19 -13
  8. package/plans/Flappy_Bird_Folder_Documentation_Pass.md +4 -4
  9. package/plans/README.md +24 -0
  10. package/plans/Roadmap.md +62 -40
  11. package/plans/analyze-trace-solid-split.plans.md +66 -0
  12. package/plans/architecture-solid-split.plans.md +9 -15
  13. package/plans/asciiMaze-typescript-repair.plans.md +1 -1
  14. package/plans/generate-docs-solid-split.plans.md +87 -0
  15. package/plans/methods-docs.plans.md +25 -1
  16. package/plans/methods-solid-split.plans.md +14 -14
  17. package/plans/neat-docs.plans.md +9 -1
  18. package/plans/neat-test-surface-repair.plans.md +1 -1
  19. package/plans/render-docs-html-solid-split.plans.md +68 -0
  20. package/plans/src-no-explicit-any-cleanup.plans.md +1 -1
  21. package/plans/utils-docs.plans.md +6 -1
  22. package/scripts/analyze-trace/analyze-trace.analysis.ts +479 -0
  23. package/scripts/analyze-trace/analyze-trace.constants.ts +35 -0
  24. package/scripts/analyze-trace/analyze-trace.io.ts +69 -0
  25. package/scripts/analyze-trace/analyze-trace.report.ts +100 -0
  26. package/scripts/analyze-trace/analyze-trace.shared.ts +116 -0
  27. package/scripts/analyze-trace/analyze-trace.ts +45 -0
  28. package/scripts/analyze-trace/analyze-trace.types.ts +72 -0
  29. package/scripts/assets/theme.css +80 -23
  30. package/scripts/copy-examples.ts +239 -0
  31. package/scripts/export-onnx.ts +223 -0
  32. package/scripts/generate-bench-tables.ts +378 -37
  33. package/scripts/generate-docs/generate-docs.constants.ts +107 -0
  34. package/scripts/generate-docs/generate-docs.order.ts +355 -0
  35. package/scripts/generate-docs/generate-docs.state.ts +31 -0
  36. package/scripts/generate-docs/generate-docs.targets.ts +165 -0
  37. package/scripts/generate-docs/generate-docs.ts +63 -0
  38. package/scripts/generate-docs/generate-docs.types.ts +112 -0
  39. package/scripts/generate-docs/output/generate-docs.output.folder-index.utils.ts +167 -0
  40. package/scripts/generate-docs/output/generate-docs.output.ordering.utils.ts +353 -0
  41. package/scripts/generate-docs/output/generate-docs.output.readme.utils.ts +420 -0
  42. package/scripts/generate-docs/output/generate-docs.output.ts +123 -0
  43. package/scripts/generate-docs/output/generate-docs.output.warnings.utils.ts +219 -0
  44. package/scripts/generate-docs/symbols/generate-docs.symbols.collection.utils.ts +365 -0
  45. package/scripts/generate-docs/symbols/generate-docs.symbols.jsdoc.utils.ts +373 -0
  46. package/scripts/generate-docs/symbols/generate-docs.symbols.normalize.utils.ts +155 -0
  47. package/scripts/generate-docs/symbols/generate-docs.symbols.render.utils.ts +149 -0
  48. package/scripts/generate-docs/symbols/generate-docs.symbols.signature.utils.ts +289 -0
  49. package/scripts/generate-docs/symbols/generate-docs.symbols.ts +11 -0
  50. package/scripts/mermaid-cli.mjs +102 -22
  51. package/scripts/mermaid-cli.ts +736 -0
  52. package/scripts/render-docs-html/render-docs-html.assets.ts +54 -0
  53. package/scripts/render-docs-html/render-docs-html.mermaid.ts +245 -0
  54. package/scripts/{render-docs-html.sidebar.ts → render-docs-html/render-docs-html.navigation.ts} +141 -144
  55. package/scripts/render-docs-html/render-docs-html.pages.ts +333 -0
  56. package/scripts/render-docs-html/render-docs-html.shared.ts +333 -0
  57. package/scripts/render-docs-html/render-docs-html.types.ts +42 -0
  58. package/scripts/render-docs-html.ts +23 -587
  59. package/scripts/run-docs.ts +238 -0
  60. package/scripts/write-dist-docs-pkg.ts +40 -0
  61. package/src/README.md +75 -75
  62. package/src/architecture/connection/README.md +5 -5
  63. package/src/architecture/layer/README.md +508 -508
  64. package/src/architecture/network/README.md +1458 -1458
  65. package/src/architecture/network/activate/README.md +694 -694
  66. package/src/architecture/network/bootstrap/README.md +77 -77
  67. package/src/architecture/network/connect/README.md +74 -74
  68. package/src/architecture/network/deterministic/README.md +135 -135
  69. package/src/architecture/network/evolve/README.md +364 -364
  70. package/src/architecture/network/gating/README.md +130 -130
  71. package/src/architecture/network/genetic/README.md +399 -399
  72. package/src/architecture/network/mutate/README.md +897 -897
  73. package/src/architecture/network/onnx/README.md +720 -720
  74. package/src/architecture/network/onnx/export/README.md +728 -728
  75. package/src/architecture/network/onnx/export/layers/README.md +450 -450
  76. package/src/architecture/network/onnx/import/README.md +618 -618
  77. package/src/architecture/network/onnx/schema/README.md +32 -32
  78. package/src/architecture/network/prune/README.md +245 -245
  79. package/src/architecture/network/remove/README.md +135 -135
  80. package/src/architecture/network/runtime/README.md +106 -106
  81. package/src/architecture/network/serialize/README.md +542 -542
  82. package/src/architecture/network/slab/README.md +608 -608
  83. package/src/architecture/network/standalone/README.md +212 -212
  84. package/src/architecture/network/stats/README.md +84 -84
  85. package/src/architecture/network/topology/README.md +465 -465
  86. package/src/architecture/network/training/README.md +200 -200
  87. package/src/architecture/node/README.md +5 -5
  88. package/src/architecture/nodePool/README.md +14 -14
  89. package/src/methods/README.md +99 -99
  90. package/src/methods/activation/README.md +189 -189
  91. package/src/methods/cost/README.md +131 -131
  92. package/src/methods/rate/README.md +86 -86
  93. package/src/multithreading/README.md +77 -77
  94. package/src/multithreading/workers/browser/README.md +8 -8
  95. package/src/multithreading/workers/node/README.md +8 -8
  96. package/src/neat/README.md +148 -148
  97. package/src/neat/adaptive/README.md +120 -120
  98. package/src/neat/adaptive/acceptance/README.md +40 -40
  99. package/src/neat/adaptive/complexity/README.md +137 -137
  100. package/src/neat/adaptive/core/README.md +197 -197
  101. package/src/neat/adaptive/lineage/README.md +90 -90
  102. package/src/neat/adaptive/mutation/README.md +284 -284
  103. package/src/neat/compat/README.md +43 -43
  104. package/src/neat/compat/core/README.md +90 -90
  105. package/src/neat/diversity/README.md +35 -35
  106. package/src/neat/diversity/core/README.md +88 -88
  107. package/src/neat/evaluate/README.md +85 -85
  108. package/src/neat/evaluate/auto-distance/README.md +75 -75
  109. package/src/neat/evaluate/entropy-compat/README.md +37 -37
  110. package/src/neat/evaluate/entropy-sharing/README.md +43 -43
  111. package/src/neat/evaluate/fitness/README.md +23 -23
  112. package/src/neat/evaluate/novelty/README.md +120 -120
  113. package/src/neat/evaluate/objectives/README.md +17 -17
  114. package/src/neat/evaluate/shared/README.md +94 -94
  115. package/src/neat/evolve/README.md +96 -96
  116. package/src/neat/evolve/adaptive/README.md +60 -60
  117. package/src/neat/evolve/objectives/README.md +63 -63
  118. package/src/neat/evolve/offspring/README.md +56 -56
  119. package/src/neat/evolve/population/README.md +171 -171
  120. package/src/neat/evolve/runtime/README.md +79 -79
  121. package/src/neat/evolve/speciation/README.md +74 -74
  122. package/src/neat/evolve/warnings/README.md +10 -10
  123. package/src/neat/export/README.md +114 -114
  124. package/src/neat/helpers/README.md +50 -50
  125. package/src/neat/init/README.md +9 -9
  126. package/src/neat/lineage/core/README.md +101 -101
  127. package/src/neat/multiobjective/category/README.md +74 -74
  128. package/src/neat/multiobjective/crowding/README.md +272 -272
  129. package/src/neat/multiobjective/dominance/README.md +171 -171
  130. package/src/neat/multiobjective/fronts/README.md +68 -68
  131. package/src/neat/multiobjective/metrics/README.md +43 -43
  132. package/src/neat/multiobjective/objectives/README.md +31 -31
  133. package/src/neat/multiobjective/shared/README.md +27 -27
  134. package/src/neat/mutation/README.md +97 -97
  135. package/src/neat/mutation/add-conn/README.md +115 -115
  136. package/src/neat/mutation/add-node/README.md +126 -126
  137. package/src/neat/mutation/flow/README.md +149 -149
  138. package/src/neat/mutation/repair/README.md +185 -185
  139. package/src/neat/mutation/select/README.md +117 -117
  140. package/src/neat/mutation/shared/README.md +32 -32
  141. package/src/neat/objectives/README.md +25 -25
  142. package/src/neat/objectives/core/README.md +67 -67
  143. package/src/neat/pruning/README.md +40 -40
  144. package/src/neat/pruning/core/README.md +171 -171
  145. package/src/neat/pruning/facade/README.md +32 -32
  146. package/src/neat/rng/README.md +104 -104
  147. package/src/neat/rng/core/README.md +137 -137
  148. package/src/neat/rng/facade/README.md +50 -50
  149. package/src/neat/selection/README.md +111 -111
  150. package/src/neat/selection/core/README.md +227 -227
  151. package/src/neat/selection/facade/README.md +61 -61
  152. package/src/neat/shared/README.md +163 -163
  153. package/src/neat/speciation/README.md +31 -31
  154. package/src/neat/speciation/threshold/README.md +35 -35
  155. package/src/neat/species/README.md +25 -25
  156. package/src/neat/species/core/README.md +20 -20
  157. package/src/neat/species/core/shared/README.md +18 -18
  158. package/src/neat/species/history/context/README.md +22 -22
  159. package/src/neat/telemetry/accessors/README.md +58 -58
  160. package/src/neat/telemetry/exports/README.md +233 -233
  161. package/src/neat/telemetry/facade/README.md +252 -252
  162. package/src/neat/telemetry/facade/archive/README.md +57 -57
  163. package/src/neat/telemetry/facade/buffer/README.md +43 -43
  164. package/src/neat/telemetry/facade/lineage/README.md +12 -12
  165. package/src/neat/telemetry/facade/objectives/README.md +44 -44
  166. package/src/neat/telemetry/facade/runtime/README.md +26 -26
  167. package/src/neat/telemetry/facade/species/README.md +27 -27
  168. package/src/neat/telemetry/metrics/README.md +696 -696
  169. package/src/neat/telemetry/recorder/README.md +57 -57
  170. package/src/neat/telemetry/types/README.md +32 -32
  171. package/src/neat/topology-intent/README.md +75 -75
  172. package/src/utils/README.md +193 -193
  173. package/test/examples/asciiMaze/browser-entry/README.md +92 -92
  174. package/test/examples/asciiMaze/dashboardManager/README.md +109 -109
  175. package/test/examples/asciiMaze/dashboardManager/telemetry/README.md +28 -28
  176. package/test/examples/asciiMaze/evolutionEngine/README.md +1527 -1527
  177. package/test/examples/asciiMaze/mazeMovement/README.md +105 -105
  178. package/test/examples/asciiMaze/mazeMovement/finalization/README.md +16 -16
  179. package/test/examples/asciiMaze/mazeMovement/policy/README.md +57 -57
  180. package/test/examples/asciiMaze/mazeMovement/runtime/README.md +52 -52
  181. package/test/examples/asciiMaze/mazeMovement/shaping/README.md +46 -46
  182. package/test/examples/flappy_bird/browser-entry/README.md +508 -508
  183. package/test/examples/flappy_bird/browser-entry/host/README.md +101 -101
  184. package/test/examples/flappy_bird/browser-entry/host/resize/README.md +144 -144
  185. package/test/examples/flappy_bird/browser-entry/network-view/README.md +194 -194
  186. package/test/examples/flappy_bird/browser-entry/playback/README.md +278 -278
  187. package/test/examples/flappy_bird/browser-entry/playback/background/README.md +129 -129
  188. package/test/examples/flappy_bird/browser-entry/playback/background/ground-grid/README.md +502 -502
  189. package/test/examples/flappy_bird/browser-entry/playback/frame-render/README.md +139 -139
  190. package/test/examples/flappy_bird/browser-entry/playback/snapshot/README.md +10 -10
  191. package/test/examples/flappy_bird/browser-entry/playback/trail/README.md +43 -43
  192. package/test/examples/flappy_bird/browser-entry/playback/worker-channel/README.md +30 -30
  193. package/test/examples/flappy_bird/browser-entry/runtime/README.md +59 -59
  194. package/test/examples/flappy_bird/browser-entry/visualization/README.md +276 -276
  195. package/test/examples/flappy_bird/browser-entry/worker-channel/README.md +16 -16
  196. package/test/examples/flappy_bird/constants/README.md +1070 -1070
  197. package/test/examples/flappy_bird/environment/README.md +22 -22
  198. package/test/examples/flappy_bird/evaluation/README.md +32 -32
  199. package/test/examples/flappy_bird/evaluation/rollout/README.md +141 -141
  200. package/test/examples/flappy_bird/flappy-evolution-worker/README.md +425 -425
  201. package/test/examples/flappy_bird/simulation-shared/README.md +170 -170
  202. package/test/examples/flappy_bird/simulation-shared/observation/README.md +109 -109
  203. package/test/examples/flappy_bird/trainer/README.md +325 -325
  204. package/test/examples/flappy_bird/trainer/evaluation/README.md +74 -74
  205. package/scripts/analyze-trace.ts +0 -590
  206. package/scripts/copy-examples.mjs +0 -114
  207. package/scripts/export-onnx.mjs +0 -86
  208. package/scripts/generate-bench-tables.mjs +0 -182
  209. package/scripts/generate-docs.ts +0 -2900
  210. package/scripts/write-dist-docs-pkg.mjs +0 -16
@@ -824,6 +824,15 @@ Removes the connection from the network's `gates` list.
824
824
 
825
825
  ## architecture/network/network.utils.ts
826
826
 
827
+ ### __trainingInternals
828
+
829
+ Test-only internal helper bundle.
830
+
831
+ This is exported so unit tests can cover edge-cases in the smoothing logic without
832
+ running full end-to-end training loops.
833
+
834
+ Important: this is **not** considered stable public API. It may change between releases.
835
+
827
836
  ### activate
828
837
 
829
838
  ```ts
@@ -842,66 +851,35 @@ Parameters:
842
851
 
843
852
  Returns: Output activation values.
844
853
 
845
- ### gaussianRand
846
-
847
- ```ts
848
- gaussianRand(
849
- rng: () => number,
850
- ): number
851
- ```
852
-
853
- Produce a normally distributed random sample using the Box-Muller transform.
854
-
855
- Parameters:
856
- - `rng` - Pseudo-random source in the interval [0, 1).
857
-
858
- Returns: Standard normal sample with mean 0 and variance 1.
859
-
860
- ### noTraceActivate
854
+ ### activateBatch
861
855
 
862
856
  ```ts
863
- noTraceActivate(
864
- input: number[],
865
- ): number[]
857
+ activateBatch(
858
+ inputs: number[][],
859
+ training: boolean,
860
+ ): number[][]
866
861
  ```
867
862
 
868
- Perform a forward pass without creating or updating training / gradient traces.
869
-
870
- This is the most allocation‑sensitive activation path. Internally it will attempt
871
- to leverage a compact "fast slab" routine (an optimized, vectorized broadcast over
872
- contiguous activation buffers) when the Network instance indicates that such a path
873
- is currently valid. If that attempt fails (for instance because the slab is stale
874
- after a structural mutation) execution gracefully falls back to a node‑by‑node loop.
863
+ Activate the network over a mini‑batch (array) of input vectors, returning a 2‑D array of outputs.
875
864
 
876
- Algorithm outline:
877
- 1. (Optional) Refresh cached topological order if the network enforces acyclicity
878
- and a structural change marked the order as dirty.
879
- 2. Validate the input dimensionality.
880
- 3. Try the fast slab path; if it throws, continue with the standard path.
881
- 4. Acquire a pooled output buffer sized to the number of output neurons.
882
- 5. Iterate all nodes in their internal order:
883
- - Input nodes: directly assign provided input values.
884
- - Hidden nodes: compute activation via Node.noTraceActivate (no bookkeeping).
885
- - Output nodes: compute activation and store it (in sequence) inside the
886
- pooled output buffer.
887
- 6. Copy the pooled buffer into a fresh array (detaches user from the pool) and
888
- release the pooled buffer back to the pool.
865
+ This helper simply loops, invoking {@link Network.activate} (or its bound variant) for each
866
+ sample. It is intentionally naive: no attempt is made to fuse operations across the batch.
867
+ For very large batch sizes or performance‑critical paths consider implementing a custom
868
+ vectorized backend that exploits SIMD, GPU kernels, or parallel workers.
889
869
 
890
- Complexity considerations:
891
- - Time: O(N + E) where N = number of nodes, E = number of inbound edges processed
892
- inside each Node.noTraceActivate call (not explicit here but inside the node).
893
- - Space: O(O) transient (O = number of outputs) due to the pooled output buffer.
870
+ Input validation occurs per row to surface the earliest mismatch with a descriptive index.
894
871
 
895
872
  Parameters:
896
873
  - `this` - - Bound Network instance.
897
- - `input` - - Flat numeric vector whose length must equal network.input.
874
+ - `inputs` - - Array of input vectors; each must have length == network.input.
875
+ - `training` - - Whether each activation should keep training traces.
898
876
 
899
- Returns: Array of output neuron activations (length == network.output).
877
+ Returns: 2‑D array: outputs[i] is the activation result for inputs[i].
900
878
 
901
879
  Example:
902
880
 
903
- const out = net.noTraceActivate([0.1, 0.2, 0.3]);
904
- console.log(out); // => e.g. [0.5123, 0.0441]
881
+ const batchOut = net.activateBatch([[0,0,1],[1,0,0],[0,1,0]]);
882
+ console.log(batchOut.length); // 3 rows
905
883
 
906
884
  ### activateRaw
907
885
 
@@ -932,35 +910,94 @@ Example:
932
910
 
933
911
  const y = net.activateRaw([0,1,0]);
934
912
 
935
- ### activateBatch
913
+ ### addNodeBetweenImpl
936
914
 
937
915
  ```ts
938
- activateBatch(
939
- inputs: number[][],
916
+ addNodeBetweenImpl(): void
917
+ ```
918
+
919
+ Split one randomly selected connection by inserting a hidden node.
920
+
921
+ This preserves the long-standing public `addNodeBetween()` behavior:
922
+ - it does not opt into `ADD_NODE` deterministic-chain policy,
923
+ - it preserves the original source-edge weight on the first new connection,
924
+ - it uses `1` for the hidden-to-target edge to keep the split easy to reason about.
925
+
926
+ Parameters:
927
+ - `this` - Target network instance.
928
+
929
+ Returns: Nothing.
930
+
931
+ ### applyGradientClippingImpl
932
+
933
+ ```ts
934
+ applyGradientClippingImpl(
935
+ net: default,
936
+ cfg: GradientClipRuntimeConfig,
937
+ ): void
938
+ ```
939
+
940
+ Apply gradient clipping to a network using a normalized runtime configuration.
941
+
942
+ This is a small wrapper that forwards to the concrete implementation used by training.
943
+
944
+ Parameters:
945
+ - `net` - - Network instance to update.
946
+ - `cfg` - - Normalized clipping settings.
947
+
948
+ ### canUseFastSlab
949
+
950
+ ```ts
951
+ canUseFastSlab(
940
952
  training: boolean,
941
- ): number[][]
953
+ ): boolean
942
954
  ```
943
955
 
944
- Activate the network over a mini‑batch (array) of input vectors, returning a 2‑D array of outputs.
956
+ Public convenience wrapper exposing fast path eligibility.
957
+ Mirrors `_canUseFastSlab` internal predicate.
945
958
 
946
- This helper simply loops, invoking {@link Network.activate} (or its bound variant) for each
947
- sample. It is intentionally naive: no attempt is made to fuse operations across the batch.
948
- For very large batch sizes or performance‑critical paths consider implementing a custom
949
- vectorized backend that exploits SIMD, GPU kernels, or parallel workers.
959
+ Parameters:
960
+ - `training` - Whether caller is performing training (disables fast path if true).
950
961
 
951
- Input validation occurs per row to surface the earliest mismatch with a descriptive index.
962
+ Returns: True when slab fast path predicates hold.
963
+
964
+ ### clearState
965
+
966
+ ```ts
967
+ clearState(): void
968
+ ```
969
+
970
+ Clear all node runtime traces and states.
952
971
 
953
972
  Parameters:
954
- - `this` - - Bound Network instance.
955
- - `inputs` - - Array of input vectors; each must have length == network.input.
956
- - `training` - - Whether each activation should keep training traces.
973
+ - `this` - Bound network instance.
957
974
 
958
- Returns: 2‑D array: outputs[i] is the activation result for inputs[i].
975
+ ### cloneImpl
959
976
 
960
- Example:
977
+ ```ts
978
+ cloneImpl(): default
979
+ ```
961
980
 
962
- const batchOut = net.activateBatch([[0,0,1],[1,0,0],[0,1,0]]);
963
- console.log(batchOut.length); // 3 rows
981
+ Create a deep copy of one network through the verbose JSON round-trip.
982
+
983
+ This keeps cloning behavior aligned with the same versioned payload contract
984
+ used by `toJSON()` and `fromJSON()`, so clone semantics stay stable as the
985
+ serialization chapter evolves.
986
+
987
+ Parameters:
988
+ - `this` - Target network instance.
989
+
990
+ Returns: Deep-cloned network instance.
991
+
992
+ ### computeTopoOrder
993
+
994
+ ```ts
995
+ computeTopoOrder(): void
996
+ ```
997
+
998
+ Compute a topological ordering (Kahn's algorithm) for the current directed acyclic graph.
999
+ If cycles are detected (order shorter than node count) we fall back to raw node order to avoid breaking callers.
1000
+ In non-acyclic mode we simply clear cached order to signal use of sequential node array.
964
1001
 
965
1002
  ### connect
966
1003
 
@@ -1009,174 +1046,194 @@ Example:
1009
1046
 
1010
1047
  const [edge] = net.connect(nodeA, nodeB, 0.5);
1011
1048
 
1012
- ### disconnect
1049
+ ### createMLP
1013
1050
 
1014
1051
  ```ts
1015
- disconnect(
1016
- from: default,
1017
- to: default,
1018
- ): void
1052
+ createMLP(
1053
+ inputCount: number,
1054
+ hiddenCounts: number[],
1055
+ outputCount: number,
1056
+ ): default
1019
1057
  ```
1020
1058
 
1021
- Remove (at most) one directed connection from source 'from' to target 'to'.
1022
-
1023
- Only a single direct edge is removed because typical graph configurations maintain at most
1024
- one logical connection between a given pair of nodes (excluding potential future multi‑edge
1025
- semantics). If the target edge is gated we first call {@link Network.ungate} to maintain
1026
- gating invariants (ensuring the gater node's internal gate list remains consistent).
1027
-
1028
- Algorithm outline:
1029
- 1. Choose the correct list (selfconns vs connections) based on whether from === to.
1030
- 2. Linear scan to find the first edge with matching endpoints.
1031
- 3. If gated, ungate to detach gater bookkeeping.
1032
- 4. Splice the edge out; exit loop (only one expected).
1033
- 5. Delegate per‑node cleanup via from.disconnect(to) (clears reverse references, traces, etc.).
1034
- 6. Mark structural caches dirty for lazy recomputation.
1035
-
1036
- Complexity:
1037
- - Time: O(m) where m is length of the searched list (connections or selfconns).
1038
- - Space: O(1) extra.
1039
-
1040
- Idempotence: If no such edge exists we still perform node-level disconnect and flag caches dirty –
1041
- this conservative approach simplifies callers (they need not pre‑check existence).
1059
+ Build a strictly layered and fully connected MLP network.
1042
1060
 
1043
1061
  Parameters:
1044
- - `this` - - Bound Network instance.
1045
- - `from` - - Source node.
1046
- - `to` - - Target node.
1047
-
1048
- Example:
1062
+ - `this` - Network constructor.
1063
+ - `inputCount` - Number of input nodes.
1064
+ - `hiddenCounts` - Hidden-layer node counts.
1065
+ - `outputCount` - Number of output nodes.
1049
1066
 
1050
- net.disconnect(nodeA, nodeB);
1067
+ Returns: Newly created MLP network.
1051
1068
 
1052
- ### setSeed
1069
+ ### crossOver
1053
1070
 
1054
1071
  ```ts
1055
- setSeed(
1056
- seed: number,
1057
- ): void
1072
+ crossOver(
1073
+ parentNetwork1: default,
1074
+ parentNetwork2: default,
1075
+ equal: boolean,
1076
+ ): default
1058
1077
  ```
1059
1078
 
1060
- Sets deterministic randomness for a network by installing a seed-backed RNG.
1061
-
1062
- Overview:
1063
- - Use this before training, mutation, or stochastic operations when you need repeatable runs.
1064
- - The same seed and operation order produce the same random sequence and reproducible outcomes.
1065
- - This method delegates to setup utilities so behavior stays centralized across deterministic APIs.
1066
-
1067
- Parameters:
1068
- - `this` - - Bound network instance whose RNG state is being initialized.
1069
- - `seed` - - Seed value used to derive deterministic RNG state (low 32 bits are applied).
1070
-
1071
- Returns: Nothing.
1079
+ NEAT-inspired crossover between two parent networks producing a single offspring.
1072
1080
 
1073
- Example:
1081
+ Conceptual model:
1082
+ - A "gene" corresponds to either a node choice at a structural index or a connection
1083
+ keyed by innovation identity.
1084
+ - The offspring is assembled in two phases: node assignment first, then connection
1085
+ materialization constrained by available offspring endpoints.
1086
+ - Fitness controls inheritance pressure unless `equal` is enabled, in which case both
1087
+ parents contribute symmetrically where possible.
1074
1088
 
1075
- ```ts
1076
- network.setSeed(42);
1077
- ```
1089
+ Simplifications relative to canonical NEAT:
1090
+ - Innovation ID is synthesized from (from.index, to.index) via Connection.innovationID instead of
1091
+ maintaining a global innovation number per mutation event.
1092
+ - Node alignment relies on current index ordering. This is weaker than historical innovation
1093
+ tracking, but adequate for many lightweight evolutionary experiments.
1078
1094
 
1079
- ### snapshotRNG
1095
+ Compatibility assumptions:
1096
+ - Both parents must expose identical input/output counts.
1097
+ - Parent node index ordering should represent comparable structural positions.
1098
+ - Parent fitness scores are interpreted by setup helpers when deciding fitter-parent inheritance.
1080
1099
 
1081
- ```ts
1082
- snapshotRNG(): RNGSnapshot
1083
- ```
1084
-
1085
- Captures the current deterministic RNG lifecycle state as a portable snapshot.
1100
+ High-level algorithm:
1101
+ 1. Validate that parents have identical I/O dimensionality (required for compatibility).
1102
+ 2. Decide offspring node array length:
1103
+ - If equal flag set or scores tied: random length in [minNodes, maxNodes].
1104
+ - Else: length of fitter parent.
1105
+ 3. For each index up to chosen size, pick a node gene from parents per rules:
1106
+ - Input indices: always from parent1 (assumes identical input interface).
1107
+ - Output indices (aligned from end): randomly choose if both present else take existing.
1108
+ - Hidden indices: if both present pick randomly; else inherit from fitter (or either if equal).
1109
+ 4. Reindex offspring nodes.
1110
+ 5. Collect connections (standard + self) from each parent into maps keyed by innovationID capturing
1111
+ weight, enabled flag, and gater index.
1112
+ 6. For overlapping genes (present in both), randomly choose one; if either disabled apply optional
1113
+ re-enable probability (reenableProb) to possibly re-activate.
1114
+ 7. For disjoint/excess genes, inherit only from fitter parent (or both if equal flag set / scores tied).
1115
+ 8. Materialize selected connection genes if their endpoints both exist in offspring; set weight & enabled state.
1116
+ 9. Reattach gating if gater node exists in offspring.
1086
1117
 
1087
- Overview:
1088
- - Use this before temporary experiments, branching simulations, or stateful debug sessions.
1089
- - The snapshot preserves enough information to resume from the same deterministic point later.
1090
- - This is useful when comparing alternate algorithm branches from an identical random timeline.
1118
+ Enabled reactivation probability:
1119
+ - Parents may carry disabled connections; offspring may re-enable them with a probability derived
1120
+ from parent-specific _reenableProb (or default 0.25). This allows dormant structures to resurface.
1091
1121
 
1092
1122
  Parameters:
1093
- - `this` - - Bound network instance whose RNG lifecycle state is captured.
1123
+ - `parentNetwork1` - - First parent (ties resolved in its favor when scores equal and equal=false for some cases).
1124
+ - `parentNetwork2` - - Second parent.
1125
+ - `equal` - - Force symmetric treatment regardless of fitness (true => node count random between sizes and both parents equally contribute disjoint genes).
1094
1126
 
1095
- Returns: Snapshot containing deterministic progress metadata and RNG state payload.
1127
+ Returns: Offspring network instance.
1096
1128
 
1097
1129
  Example:
1098
1130
 
1099
1131
  ```ts
1100
- const snapshot = network.snapshotRNG();
1132
+ const offspring = crossOver(parentA, parentB);
1133
+ offspring.mutate();
1101
1134
  ```
1102
1135
 
1103
- ### restoreRNG
1136
+ ### describeArchitecture
1104
1137
 
1105
1138
  ```ts
1106
- restoreRNG(
1107
- fn: () => number,
1108
- ): void
1139
+ describeArchitecture(
1140
+ network: default,
1141
+ ): NetworkArchitectureDescriptor
1109
1142
  ```
1110
1143
 
1111
- Restores deterministic RNG lifecycle behavior from a provided RNG function.
1144
+ Describes network architecture for diagnostics, telemetry, and UI rendering.
1112
1145
 
1113
- Overview:
1114
- - Use this when replaying deterministic flows after custom serialization, hydration, or test setup.
1115
- - The restored RNG function becomes the active random source used by the network lifecycle helpers.
1116
- - This keeps deterministic plumbing explicit when external code owns RNG reconstruction.
1146
+ This function prefers factual sources over heuristics so downstream tooling
1147
+ can rely on the descriptor while still receiving useful output for partially
1148
+ specified runtime graphs.
1149
+
1150
+ Resolution priority is intentionally explicit:
1151
+ 1) node `layer` metadata (factual when present)
1152
+ 2) graph-derived feed-forward depth layering (factual for acyclic graphs)
1153
+ 3) hidden-node count fallback (heuristic inference)
1117
1154
 
1118
1155
  Parameters:
1119
- - `this` - - Bound network instance receiving the restored RNG lifecycle function.
1120
- - `fn` - - Deterministic RNG function to install (expected to return values in `[0, 1)`).
1156
+ - `network` - - Runtime network instance.
1121
1157
 
1122
- Returns: Nothing.
1158
+ Returns: Stable architecture descriptor.
1123
1159
 
1124
1160
  Example:
1125
1161
 
1126
1162
  ```ts
1127
- network.restoreRNG(restoredRandomFunction);
1163
+ const descriptor = describeArchitecture(network);
1164
+ // descriptor.hiddenLayerSizes -> [8, 4]
1165
+ // descriptor.source -> 'layer-metadata' | 'graph-topology' | 'inferred'
1128
1166
  ```
1129
1167
 
1130
- ### getRNGState
1168
+ ### deserialize
1131
1169
 
1132
1170
  ```ts
1133
- getRNGState(): number | undefined
1171
+ deserialize(
1172
+ data: CompactSerializedNetworkTuple,
1173
+ inputSize: number | undefined,
1174
+ outputSize: number | undefined,
1175
+ ): default
1134
1176
  ```
1135
1177
 
1136
- Returns the current deterministic RNG numeric state, when available.
1178
+ Rebuilds a network instance from compact tuple form.
1137
1179
 
1138
- Overview:
1139
- - Use this for lightweight checkpointing when full lifecycle snapshots are unnecessary.
1140
- - The value can be persisted and later reapplied through `setRNGState`.
1141
- - This is commonly used by tests that assert deterministic continuity across operations.
1180
+ Use this importer for compact payloads produced by `serialize`.
1181
+ Optional `inputSize` and `outputSize` let callers enforce shape overrides at import time.
1142
1182
 
1143
1183
  Parameters:
1144
- - `this` - - Bound network instance queried for deterministic RNG numeric state.
1184
+ - `data` - - Compact tuple payload.
1185
+ - `inputSize` - - Optional input-size override that takes precedence over serialized input.
1186
+ - `outputSize` - - Optional output-size override that takes precedence over serialized output.
1145
1187
 
1146
- Returns: Numeric RNG state value, or `undefined` when no deterministic state exists yet.
1188
+ Returns: Reconstructed network instance.
1147
1189
 
1148
1190
  Example:
1149
1191
 
1150
1192
  ```ts
1151
- const state = network.getRNGState();
1193
+ import { deserialize } from './network.serialize.utils';
1194
+
1195
+ const rebuiltNetwork = deserialize(compactTuple, 2, 1);
1152
1196
  ```
1153
1197
 
1154
- ### setRNGState
1198
+ ### disconnect
1155
1199
 
1156
1200
  ```ts
1157
- setRNGState(
1158
- state: number,
1201
+ disconnect(
1202
+ from: default,
1203
+ to: default,
1159
1204
  ): void
1160
1205
  ```
1161
1206
 
1162
- Applies a deterministic RNG numeric state to continue from a known checkpoint.
1207
+ Remove (at most) one directed connection from source 'from' to target 'to'.
1163
1208
 
1164
- Overview:
1165
- - Pair this with `getRNGState` to pause/resume deterministic sequences.
1166
- - Useful for reproducible tests, multi-stage training workflows, and deterministic replay.
1167
- - Delegation keeps the write path consistent with the rest of deterministic state utilities.
1209
+ Only a single direct edge is removed because typical graph configurations maintain at most
1210
+ one logical connection between a given pair of nodes (excluding potential future multi‑edge
1211
+ semantics). If the target edge is gated we first call {@link Network.ungate} to maintain
1212
+ gating invariants (ensuring the gater node's internal gate list remains consistent).
1168
1213
 
1169
- Parameters:
1170
- - `this` - - Bound network instance receiving deterministic RNG state.
1171
- - `state` - - Numeric RNG state checkpoint to install.
1214
+ Algorithm outline:
1215
+ 1. Choose the correct list (selfconns vs connections) based on whether from === to.
1216
+ 2. Linear scan to find the first edge with matching endpoints.
1217
+ 3. If gated, ungate to detach gater bookkeeping.
1218
+ 4. Splice the edge out; exit loop (only one expected).
1219
+ 5. Delegate per‑node cleanup via from.disconnect(to) (clears reverse references, traces, etc.).
1220
+ 6. Mark structural caches dirty for lazy recomputation.
1172
1221
 
1173
- Returns: Nothing.
1222
+ Complexity:
1223
+ - Time: O(m) where m is length of the searched list (connections or selfconns).
1224
+ - Space: O(1) extra.
1225
+
1226
+ Idempotence: If no such edge exists we still perform node-level disconnect and flag caches dirty –
1227
+ this conservative approach simplifies callers (they need not pre‑check existence).
1228
+
1229
+ Parameters:
1230
+ - `this` - - Bound Network instance.
1231
+ - `from` - - Source node.
1232
+ - `to` - - Target node.
1174
1233
 
1175
1234
  Example:
1176
1235
 
1177
- ```ts
1178
- network.setRNGState(savedState);
1179
- ```
1236
+ net.disconnect(nodeA, nodeB);
1180
1237
 
1181
1238
  ### evolveNetwork
1182
1239
 
@@ -1219,6 +1276,57 @@ const summary = await network.evolve(trainingSet, {
1219
1276
  console.log(summary.error, summary.iterations, summary.time);
1220
1277
  ```
1221
1278
 
1279
+ ### fastSlabActivate
1280
+
1281
+ ```ts
1282
+ fastSlabActivate(
1283
+ input: number[],
1284
+ ): number[]
1285
+ ```
1286
+
1287
+ High‑performance forward pass using packed slabs + CSR adjacency.
1288
+
1289
+ Fallback Conditions (auto‑detected):
1290
+ - Missing slabs / adjacency structures.
1291
+ - Topology/gating/stochastic predicates fail (see `_canUseFastSlab`).
1292
+ - Gating present, when applicable (explicit guard).
1293
+
1294
+ Implementation Notes:
1295
+ - Reuses internal activation/state buffers to reduce per‑step allocation churn.
1296
+ - Applies gain multiplication if optional gain slab exists.
1297
+ - Assumes acyclic graph; topological order recomputed on demand if marked dirty.
1298
+
1299
+ Parameters:
1300
+ - `input` - Input vector (length must equal `network.input`).
1301
+
1302
+ Returns: Output activations (detached plain array) of length `network.output`.
1303
+
1304
+ ### fromJSONImpl
1305
+
1306
+ ```ts
1307
+ fromJSONImpl(
1308
+ json: NetworkJSON,
1309
+ ): default
1310
+ ```
1311
+
1312
+ Reconstructs a network instance from the verbose JSON payload.
1313
+
1314
+ This importer validates payload shape, restores dropout and topology, and then rebuilds
1315
+ connections, gating relationships, and optional enabled flags.
1316
+
1317
+ Parameters:
1318
+ - `json` - - Verbose JSON payload.
1319
+
1320
+ Returns: Reconstructed network instance.
1321
+
1322
+ Example:
1323
+
1324
+ ```ts
1325
+ import { fromJSONImpl } from './network.serialize.utils';
1326
+
1327
+ const rebuiltNetwork = fromJSONImpl(snapshotJson);
1328
+ ```
1329
+
1222
1330
  ### gate
1223
1331
 
1224
1332
  ```ts
@@ -1242,110 +1350,152 @@ Parameters:
1242
1350
  - `node` - - Candidate gater node (must belong to network).
1243
1351
  - `connection` - - Connection to gate.
1244
1352
 
1245
- ### ungate
1353
+ ### gaussianRand
1246
1354
 
1247
1355
  ```ts
1248
- ungate(
1249
- connection: default,
1250
- ): void
1356
+ gaussianRand(
1357
+ rng: () => number,
1358
+ ): number
1251
1359
  ```
1252
1360
 
1253
- Remove gating from a connection, restoring its static weight contribution.
1361
+ Produce a normally distributed random sample using the Box-Muller transform.
1254
1362
 
1255
- Idempotent: If the connection is not currently gated, the call performs no structural changes
1256
- (and optionally logs a warning). After ungating, the connection's weight will be used directly
1257
- without modulation by a gater activation.
1363
+ Parameters:
1364
+ - `rng` - Pseudo-random source in the interval [0, 1).
1258
1365
 
1259
- Complexity: O(n) where n = number of gated connections (indexOf lookup) – typically small.
1366
+ Returns: Standard normal sample with mean 0 and variance 1.
1367
+
1368
+ ### generateStandalone
1369
+
1370
+ ```ts
1371
+ generateStandalone(
1372
+ net: default,
1373
+ ): string
1374
+ ```
1375
+
1376
+ Generate a standalone JavaScript source string that returns an `activate(input:number[])` function.
1377
+
1378
+ Implementation Steps:
1379
+ 1. Validate presence of output nodes (must produce something observable).
1380
+ 2. Assign stable sequential indices to nodes (used as array offsets in generated code).
1381
+ 3. Collect initial activation/state values into typed array initializers for warm starting.
1382
+ 4. For each non-input node, build a line computing S[i] (pre-activation sum with bias) and A[i]
1383
+ (post-activation output). Gating multiplies activation by gate activations; self-connection adds
1384
+ recurrent term S[i] * weight before activation.
1385
+ 5. De-duplicate activation functions: each unique squash name is emitted once; references become
1386
+ indices into array F of function references for compactness.
1387
+ 6. Emit an IIFE producing the activate function with internal arrays A (activations) and S (states).
1260
1388
 
1261
1389
  Parameters:
1262
- - `this` - - Bound Network instance.
1263
- - `connection` - - Connection to ungate.
1390
+ - `net` - Network instance to snapshot.
1264
1391
 
1265
- ### crossOver
1392
+ Returns: Source string (ES5-compatible) – safe to eval in sandbox to obtain activate function.
1393
+
1394
+ ### getConnectionSlab
1266
1395
 
1267
1396
  ```ts
1268
- crossOver(
1269
- parentNetwork1: default,
1270
- parentNetwork2: default,
1271
- equal: boolean,
1272
- ): default
1397
+ getConnectionSlab(): ConnectionSlabView
1273
1398
  ```
1274
1399
 
1275
- NEAT-inspired crossover between two parent networks producing a single offspring.
1400
+ Obtain (and lazily rebuild if dirty) the current packed SoA view of connections.
1276
1401
 
1277
- Conceptual model:
1278
- - A "gene" corresponds to either a node choice at a structural index or a connection
1279
- keyed by innovation identity.
1280
- - The offspring is assembled in two phases: node assignment first, then connection
1281
- materialization constrained by available offspring endpoints.
1282
- - Fitness controls inheritance pressure unless `equal` is enabled, in which case both
1283
- parents contribute symmetrically where possible.
1402
+ Gain Omission: If the internal gain slab is absent (all gains neutral) a synthetic
1403
+ neutral array is created and returned (NOT retained) to keep external educational
1404
+ tooling branch‑free while preserving omission memory savings internally.
1284
1405
 
1285
- Simplifications relative to canonical NEAT:
1286
- - Innovation ID is synthesized from (from.index, to.index) via Connection.innovationID instead of
1287
- maintaining a global innovation number per mutation event.
1288
- - Node alignment relies on current index ordering. This is weaker than historical innovation
1289
- tracking, but adequate for many lightweight evolutionary experiments.
1406
+ Returns: Read‑only style view (do not mutate) containing typed arrays + metadata.
1290
1407
 
1291
- Compatibility assumptions:
1292
- - Both parents must expose identical input/output counts.
1293
- - Parent node index ordering should represent comparable structural positions.
1294
- - Parent fitness scores are interpreted by setup helpers when deciding fitter-parent inheritance.
1408
+ ### getCurrentSparsity
1295
1409
 
1296
- High-level algorithm:
1297
- 1. Validate that parents have identical I/O dimensionality (required for compatibility).
1298
- 2. Decide offspring node array length:
1299
- - If equal flag set or scores tied: random length in [minNodes, maxNodes].
1300
- - Else: length of fitter parent.
1301
- 3. For each index up to chosen size, pick a node gene from parents per rules:
1302
- - Input indices: always from parent1 (assumes identical input interface).
1303
- - Output indices (aligned from end): randomly choose if both present else take existing.
1304
- - Hidden indices: if both present pick randomly; else inherit from fitter (or either if equal).
1305
- 4. Reindex offspring nodes.
1306
- 5. Collect connections (standard + self) from each parent into maps keyed by innovationID capturing
1307
- weight, enabled flag, and gater index.
1308
- 6. For overlapping genes (present in both), randomly choose one; if either disabled apply optional
1309
- re-enable probability (reenableProb) to possibly re-activate.
1310
- 7. For disjoint/excess genes, inherit only from fitter parent (or both if equal flag set / scores tied).
1311
- 8. Materialize selected connection genes if their endpoints both exist in offspring; set weight & enabled state.
1312
- 9. Reattach gating if gater node exists in offspring.
1410
+ ```ts
1411
+ getCurrentSparsity(): number
1412
+ ```
1313
1413
 
1314
- Enabled reactivation probability:
1315
- - Parents may carry disabled connections; offspring may re-enable them with a probability derived
1316
- from parent-specific _reenableProb (or default 0.25). This allows dormant structures to resurface.
1414
+ Current sparsity fraction relative to the training-time pruning baseline.
1415
+
1416
+ Returns: Current sparsity in the [0,1] range when baseline is available.
1417
+
1418
+ ### getRegularizationStats
1419
+
1420
+ ```ts
1421
+ getRegularizationStats(): Record<string, unknown> | null
1422
+ ```
1423
+
1424
+ Obtain the last recorded regularization / stochastic statistics snapshot.
1425
+
1426
+ Returns a defensive deep copy so callers can inspect metrics without risking mutation of the
1427
+ internal `_lastStats` object maintained by the training loop (e.g., during pruning, dropout, or
1428
+ noise scheduling updates).
1429
+
1430
+ Returns: A deep-cloned stats object or null if no stats have been recorded yet.
1431
+
1432
+ ### getRNGState
1433
+
1434
+ ```ts
1435
+ getRNGState(): number | undefined
1436
+ ```
1437
+
1438
+ Returns the current deterministic RNG numeric state, when available.
1439
+
1440
+ Overview:
1441
+ - Use this for lightweight checkpointing when full lifecycle snapshots are unnecessary.
1442
+ - The value can be persisted and later reapplied through `setRNGState`.
1443
+ - This is commonly used by tests that assert deterministic continuity across operations.
1317
1444
 
1318
1445
  Parameters:
1319
- - `parentNetwork1` - - First parent (ties resolved in its favor when scores equal and equal=false for some cases).
1320
- - `parentNetwork2` - - Second parent.
1321
- - `equal` - - Force symmetric treatment regardless of fitness (true => node count random between sizes and both parents equally contribute disjoint genes).
1446
+ - `this` - - Bound network instance queried for deterministic RNG numeric state.
1322
1447
 
1323
- Returns: Offspring network instance.
1448
+ Returns: Numeric RNG state value, or `undefined` when no deterministic state exists yet.
1324
1449
 
1325
1450
  Example:
1326
1451
 
1327
1452
  ```ts
1328
- const offspring = crossOver(parentA, parentB);
1329
- offspring.mutate();
1453
+ const state = network.getRNGState();
1330
1454
  ```
1331
1455
 
1332
- ### addNodeBetweenImpl
1456
+ ### getSlabAllocationStats
1333
1457
 
1334
1458
  ```ts
1335
- addNodeBetweenImpl(): void
1459
+ getSlabAllocationStats(): { pool: { [x: string]: PoolKeyMetrics; }; fresh: number; pooled: number; }
1336
1460
  ```
1337
1461
 
1338
- Split one randomly selected connection by inserting a hidden node.
1462
+ Allocation statistics snapshot for slab typed arrays.
1339
1463
 
1340
- This preserves the long-standing public `addNodeBetween()` behavior:
1341
- - it does not opt into `ADD_NODE` deterministic-chain policy,
1342
- - it preserves the original source-edge weight on the first new connection,
1343
- - it uses `1` for the hidden-to-target edge to keep the split easy to reason about.
1464
+ Includes:
1465
+ - fresh: number of newly constructed typed arrays since process start / metrics reset.
1466
+ - pooled: number of arrays served from the pool.
1467
+ - pool: per‑key metrics (created, reused, maxRetained) for educational inspection.
1344
1468
 
1345
- Parameters:
1346
- - `this` - Target network instance.
1469
+ NOTE: Stats are cumulative (not auto‑reset); callers may diff successive snapshots.
1347
1470
 
1348
- Returns: Nothing.
1471
+ Returns: Plain object copy (safe to serialize) of current allocator counters.
1472
+
1473
+ ### hasPath
1474
+
1475
+ ```ts
1476
+ hasPath(
1477
+ from: default,
1478
+ to: default,
1479
+ ): boolean
1480
+ ```
1481
+
1482
+ Depth-first reachability test (avoids infinite loops via visited set).
1483
+
1484
+ ### maybePrune
1485
+
1486
+ ```ts
1487
+ maybePrune(
1488
+ iteration: number,
1489
+ ): void
1490
+ ```
1491
+
1492
+ Perform scheduled pruning at a given training iteration if conditions are met.
1493
+
1494
+ Scheduling fields (cfg): start, end, frequency, targetSparsity, method ('magnitude' | 'snip'), regrowFraction.
1495
+ The target sparsity ramps linearly from 0 at start to cfg.targetSparsity at end.
1496
+
1497
+ Parameters:
1498
+ - `iteration` - Current (0-based or 1-based) training iteration counter used for scheduling.
1349
1499
 
1350
1500
  ### mutateImpl
1351
1501
 
@@ -1380,21 +1530,75 @@ network.mutate('ADD_NODE');
1380
1530
  network.mutate({ name: 'MOD_WEIGHT', min: -0.1, max: 0.1 });
1381
1531
  ```
1382
1532
 
1383
- ### maybePrune
1533
+ ### noTraceActivate
1384
1534
 
1385
1535
  ```ts
1386
- maybePrune(
1387
- iteration: number,
1388
- ): void
1536
+ noTraceActivate(
1537
+ input: number[],
1538
+ ): number[]
1389
1539
  ```
1390
1540
 
1391
- Perform scheduled pruning at a given training iteration if conditions are met.
1541
+ Perform a forward pass without creating or updating training / gradient traces.
1392
1542
 
1393
- Scheduling fields (cfg): start, end, frequency, targetSparsity, method ('magnitude' | 'snip'), regrowFraction.
1394
- The target sparsity ramps linearly from 0 at start to cfg.targetSparsity at end.
1543
+ This is the most allocation‑sensitive activation path. Internally it will attempt
1544
+ to leverage a compact "fast slab" routine (an optimized, vectorized broadcast over
1545
+ contiguous activation buffers) when the Network instance indicates that such a path
1546
+ is currently valid. If that attempt fails (for instance because the slab is stale
1547
+ after a structural mutation) execution gracefully falls back to a node‑by‑node loop.
1548
+
1549
+ Algorithm outline:
1550
+ 1. (Optional) Refresh cached topological order if the network enforces acyclicity
1551
+ and a structural change marked the order as dirty.
1552
+ 2. Validate the input dimensionality.
1553
+ 3. Try the fast slab path; if it throws, continue with the standard path.
1554
+ 4. Acquire a pooled output buffer sized to the number of output neurons.
1555
+ 5. Iterate all nodes in their internal order:
1556
+ - Input nodes: directly assign provided input values.
1557
+ - Hidden nodes: compute activation via Node.noTraceActivate (no bookkeeping).
1558
+ - Output nodes: compute activation and store it (in sequence) inside the
1559
+ pooled output buffer.
1560
+ 6. Copy the pooled buffer into a fresh array (detaches user from the pool) and
1561
+ release the pooled buffer back to the pool.
1562
+
1563
+ Complexity considerations:
1564
+ - Time: O(N + E) where N = number of nodes, E = number of inbound edges processed
1565
+ inside each Node.noTraceActivate call (not explicit here but inside the node).
1566
+ - Space: O(O) transient (O = number of outputs) due to the pooled output buffer.
1395
1567
 
1396
1568
  Parameters:
1397
- - `iteration` - Current (0-based or 1-based) training iteration counter used for scheduling.
1569
+ - `this` - - Bound Network instance.
1570
+ - `input` - - Flat numeric vector whose length must equal network.input.
1571
+
1572
+ Returns: Array of output neuron activations (length == network.output).
1573
+
1574
+ Example:
1575
+
1576
+ const out = net.noTraceActivate([0.1, 0.2, 0.3]);
1577
+ console.log(out); // => e.g. [0.5123, 0.0441]
1578
+
1579
+ ### propagate
1580
+
1581
+ ```ts
1582
+ propagate(
1583
+ rate: number,
1584
+ momentum: number,
1585
+ update: boolean,
1586
+ target: number[],
1587
+ regularization: number,
1588
+ costDerivative: CostDerivative | undefined,
1589
+ ): void
1590
+ ```
1591
+
1592
+ Propagate output and hidden errors backward through the network.
1593
+
1594
+ Parameters:
1595
+ - `this` - Bound network instance.
1596
+ - `rate` - Learning rate.
1597
+ - `momentum` - Momentum factor.
1598
+ - `update` - Whether to apply updates immediately.
1599
+ - `target` - Output target values.
1600
+ - `regularization` - L2 regularization factor.
1601
+ - `costDerivative` - Optional output-node derivative override.
1398
1602
 
1399
1603
  ### pruneToSparsity
1400
1604
 
@@ -1415,496 +1619,309 @@ Parameters:
1415
1619
 
1416
1620
  Returns: Nothing.
1417
1621
 
1418
- ### getCurrentSparsity
1622
+ ### rebuildConnections
1419
1623
 
1420
1624
  ```ts
1421
- getCurrentSparsity(): number
1625
+ rebuildConnections(
1626
+ networkInstance: default,
1627
+ ): void
1422
1628
  ```
1423
1629
 
1424
- Current sparsity fraction relative to the training-time pruning baseline.
1630
+ Rebuild the canonical connection array from per-node outgoing lists.
1425
1631
 
1426
- Returns: Current sparsity in the [0,1] range when baseline is available.
1632
+ Parameters:
1633
+ - `networkInstance` - Target network.
1427
1634
 
1428
- ### removeNode
1635
+ ### rebuildConnectionSlab
1429
1636
 
1430
1637
  ```ts
1431
- removeNode(
1432
- node: default,
1638
+ rebuildConnectionSlab(
1639
+ force: boolean,
1433
1640
  ): void
1434
1641
  ```
1435
1642
 
1436
- Remove a hidden node from the network while minimally repairing connectivity.
1643
+ Build (or refresh) the packed connection slabs for the network synchronously.
1644
+
1645
+ ACTIONS
1646
+ -------
1647
+ 1. Optionally reindex nodes if structural mutations invalidated indices.
1648
+ 2. Grow (geometric) or reuse existing typed arrays to ensure capacity >= active connections.
1649
+ 3. Populate the logical slice [0, connectionCount) with weight/from/to/flag data.
1650
+ 4. Lazily allocate gain & plastic slabs only on first non‑neutral / plastic encounter; omit otherwise.
1651
+ 5. Release previously allocated optional slabs when they revert to neutral / unused (omission optimization).
1652
+ 6. Update internal bookkeeping: logical count, dirty flags, version counter.
1653
+
1654
+ PERFORMANCE
1655
+ -----------
1656
+ O(C) over active connections with amortized allocation cost due to geometric growth.
1437
1657
 
1438
1658
  Parameters:
1439
- - `this` - Network instance (bound implicitly via method-style call).
1440
- - `node` - The node object to remove (must be of type 'hidden').
1659
+ - `force` - When true forces rebuild even if network not marked dirty (useful for timing tests).
1441
1660
 
1442
- ### serialize
1661
+ ### rebuildConnectionSlabAsync
1443
1662
 
1444
1663
  ```ts
1445
- serialize(): CompactSerializedNetworkTuple
1664
+ rebuildConnectionSlabAsync(
1665
+ chunkSize: number,
1666
+ ): Promise<void>
1446
1667
  ```
1447
1668
 
1448
- Serializes a network instance into the compact tuple format.
1669
+ Cooperative asynchronous slab rebuild (Browser only).
1449
1670
 
1450
- Use this format when payload size and serialization speed matter more than readability.
1451
- The tuple layout is positional and optimized for transport/storage efficiency.
1671
+ Strategy:
1672
+ - Perform capacity decision + allocation up front (mirrors sync path).
1673
+ - Populate connection data in microtask slices (yield via resolved Promise) to avoid long main‑thread stalls.
1674
+ - Adaptive slice sizing for very large graphs if `config.browserSlabChunkTargetMs` set.
1675
+
1676
+ Metrics: Increments `_slabAsyncBuilds` for observability.
1677
+ Fallback: On Node (no `window`) defers to synchronous rebuild for simplicity.
1452
1678
 
1453
1679
  Parameters:
1454
- - `this` - - Bound network instance.
1680
+ - `chunkSize` - Initial maximum connections per slice (may be reduced adaptively for huge graphs).
1455
1681
 
1456
- Returns: Compact tuple payload containing activations, states, squash keys, connections, and input/output sizes.
1682
+ Returns: Promise resolving once rebuild completes.
1457
1683
 
1458
- Example:
1684
+ ### removeNode
1459
1685
 
1460
1686
  ```ts
1461
- import Network from '../../network';
1462
- import { deserialize, serialize } from './network.serialize.utils';
1463
-
1464
- const sourceNetwork = new Network(2, 1);
1465
- const compactTuple = serialize.call(sourceNetwork);
1466
- const rebuiltNetwork = deserialize(compactTuple);
1687
+ removeNode(
1688
+ node: default,
1689
+ ): void
1467
1690
  ```
1468
1691
 
1469
- ### deserialize
1692
+ Remove a hidden node from the network while minimally repairing connectivity.
1470
1693
 
1471
- ```ts
1472
- deserialize(
1473
- data: CompactSerializedNetworkTuple,
1474
- inputSize: number | undefined,
1475
- outputSize: number | undefined,
1476
- ): default
1694
+ Parameters:
1695
+ - `this` - Network instance (bound implicitly via method-style call).
1696
+ - `node` - The node object to remove (must be of type 'hidden').
1697
+
1698
+ ### resolveArchitectureDescriptor
1699
+
1700
+ ```ts
1701
+ resolveArchitectureDescriptor(
1702
+ network: default,
1703
+ ): NetworkArchitectureDescriptor
1477
1704
  ```
1478
1705
 
1479
- Rebuilds a network instance from compact tuple form.
1706
+ Resolve the public architecture descriptor, preferring live graph facts and
1707
+ falling back to hydrated serialization metadata only when the live result is
1708
+ still purely inferred.
1480
1709
 
1481
- Use this importer for compact payloads produced by `serialize`.
1482
- Optional `inputSize` and `outputSize` let callers enforce shape overrides at import time.
1710
+ This helper keeps the descriptor ownership story in one chapter: topology
1711
+ owns the live analysis while serialization can optionally hydrate a cached
1712
+ descriptor that remains safe to reuse when the runtime graph shape matches.
1483
1713
 
1484
1714
  Parameters:
1485
- - `data` - - Compact tuple payload.
1486
- - `inputSize` - - Optional input-size override that takes precedence over serialized input.
1487
- - `outputSize` - - Optional output-size override that takes precedence over serialized output.
1715
+ - `network` - Runtime network instance.
1488
1716
 
1489
- Returns: Reconstructed network instance.
1717
+ Returns: Public architecture descriptor for telemetry and UI consumers.
1490
1718
 
1491
- Example:
1719
+ ### restoreRNG
1492
1720
 
1493
1721
  ```ts
1494
- import { deserialize } from './network.serialize.utils';
1722
+ restoreRNG(
1723
+ fn: () => number,
1724
+ ): void
1725
+ ```
1495
1726
 
1496
- const rebuiltNetwork = deserialize(compactTuple, 2, 1);
1727
+ Restores deterministic RNG lifecycle behavior from a provided RNG function.
1728
+
1729
+ Overview:
1730
+ - Use this when replaying deterministic flows after custom serialization, hydration, or test setup.
1731
+ - The restored RNG function becomes the active random source used by the network lifecycle helpers.
1732
+ - This keeps deterministic plumbing explicit when external code owns RNG reconstruction.
1733
+
1734
+ Parameters:
1735
+ - `this` - - Bound network instance receiving the restored RNG lifecycle function.
1736
+ - `fn` - - Deterministic RNG function to install (expected to return values in `[0, 1)`).
1737
+
1738
+ Returns: Nothing.
1739
+
1740
+ Example:
1741
+
1742
+ ```ts
1743
+ network.restoreRNG(restoredRandomFunction);
1497
1744
  ```
1498
1745
 
1499
- ### toJSONImpl
1746
+ ### serialize
1500
1747
 
1501
1748
  ```ts
1502
- toJSONImpl(): NetworkJSON
1749
+ serialize(): CompactSerializedNetworkTuple
1503
1750
  ```
1504
1751
 
1505
- Serializes a network instance into the verbose JSON format.
1752
+ Serializes a network instance into the compact tuple format.
1506
1753
 
1507
- Use this format when you need human-readable snapshots, explicit schema versioning,
1508
- and better forward/backward compatibility handling.
1754
+ Use this format when payload size and serialization speed matter more than readability.
1755
+ The tuple layout is positional and optimized for transport/storage efficiency.
1509
1756
 
1510
1757
  Parameters:
1511
1758
  - `this` - - Bound network instance.
1512
1759
 
1513
- Returns: Versioned JSON payload with shape metadata, nodes, and connections.
1760
+ Returns: Compact tuple payload containing activations, states, squash keys, connections, and input/output sizes.
1514
1761
 
1515
1762
  Example:
1516
1763
 
1517
1764
  ```ts
1518
1765
  import Network from '../../network';
1519
- import { fromJSONImpl, toJSONImpl } from './network.serialize.utils';
1766
+ import { deserialize, serialize } from './network.serialize.utils';
1520
1767
 
1521
- const sourceNetwork = new Network(3, 1);
1522
- const snapshotJson = toJSONImpl.call(sourceNetwork);
1523
- const rebuiltNetwork = fromJSONImpl(snapshotJson);
1768
+ const sourceNetwork = new Network(2, 1);
1769
+ const compactTuple = serialize.call(sourceNetwork);
1770
+ const rebuiltNetwork = deserialize(compactTuple);
1524
1771
  ```
1525
1772
 
1526
- ### fromJSONImpl
1773
+ ### setRNGState
1527
1774
 
1528
1775
  ```ts
1529
- fromJSONImpl(
1530
- json: NetworkJSON,
1531
- ): default
1776
+ setRNGState(
1777
+ state: number,
1778
+ ): void
1532
1779
  ```
1533
1780
 
1534
- Reconstructs a network instance from the verbose JSON payload.
1781
+ Applies a deterministic RNG numeric state to continue from a known checkpoint.
1535
1782
 
1536
- This importer validates payload shape, restores dropout and topology, and then rebuilds
1537
- connections, gating relationships, and optional enabled flags.
1783
+ Overview:
1784
+ - Pair this with `getRNGState` to pause/resume deterministic sequences.
1785
+ - Useful for reproducible tests, multi-stage training workflows, and deterministic replay.
1786
+ - Delegation keeps the write path consistent with the rest of deterministic state utilities.
1538
1787
 
1539
1788
  Parameters:
1540
- - `json` - - Verbose JSON payload.
1789
+ - `this` - - Bound network instance receiving deterministic RNG state.
1790
+ - `state` - - Numeric RNG state checkpoint to install.
1541
1791
 
1542
- Returns: Reconstructed network instance.
1792
+ Returns: Nothing.
1543
1793
 
1544
1794
  Example:
1545
1795
 
1546
1796
  ```ts
1547
- import { fromJSONImpl } from './network.serialize.utils';
1548
-
1549
- const rebuiltNetwork = fromJSONImpl(snapshotJson);
1797
+ network.setRNGState(savedState);
1550
1798
  ```
1551
1799
 
1552
- ### cloneImpl
1800
+ ### setSeed
1553
1801
 
1554
1802
  ```ts
1555
- cloneImpl(): default
1803
+ setSeed(
1804
+ seed: number,
1805
+ ): void
1556
1806
  ```
1557
1807
 
1558
- Create a deep copy of one network through the verbose JSON round-trip.
1808
+ Sets deterministic randomness for a network by installing a seed-backed RNG.
1559
1809
 
1560
- This keeps cloning behavior aligned with the same versioned payload contract
1561
- used by `toJSON()` and `fromJSON()`, so clone semantics stay stable as the
1562
- serialization chapter evolves.
1810
+ Overview:
1811
+ - Use this before training, mutation, or stochastic operations when you need repeatable runs.
1812
+ - The same seed and operation order produce the same random sequence and reproducible outcomes.
1813
+ - This method delegates to setup utilities so behavior stays centralized across deterministic APIs.
1563
1814
 
1564
1815
  Parameters:
1565
- - `this` - Target network instance.
1816
+ - `this` - - Bound network instance whose RNG state is being initialized.
1817
+ - `seed` - - Seed value used to derive deterministic RNG state (low 32 bits are applied).
1566
1818
 
1567
- Returns: Deep-cloned network instance.
1819
+ Returns: Nothing.
1568
1820
 
1569
- ### rebuildConnectionSlab
1821
+ Example:
1570
1822
 
1571
1823
  ```ts
1572
- rebuildConnectionSlab(
1573
- force: boolean,
1574
- ): void
1824
+ network.setSeed(42);
1575
1825
  ```
1576
1826
 
1577
- Build (or refresh) the packed connection slabs for the network synchronously.
1578
-
1579
- ACTIONS
1580
- -------
1581
- 1. Optionally reindex nodes if structural mutations invalidated indices.
1582
- 2. Grow (geometric) or reuse existing typed arrays to ensure capacity >= active connections.
1583
- 3. Populate the logical slice [0, connectionCount) with weight/from/to/flag data.
1584
- 4. Lazily allocate gain & plastic slabs only on first non‑neutral / plastic encounter; omit otherwise.
1585
- 5. Release previously allocated optional slabs when they revert to neutral / unused (omission optimization).
1586
- 6. Update internal bookkeeping: logical count, dirty flags, version counter.
1587
-
1588
- PERFORMANCE
1589
- -----------
1590
- O(C) over active connections with amortized allocation cost due to geometric growth.
1591
-
1592
- Parameters:
1593
- - `force` - When true forces rebuild even if network not marked dirty (useful for timing tests).
1594
-
1595
- ### rebuildConnectionSlabAsync
1827
+ ### snapshotRNG
1596
1828
 
1597
1829
  ```ts
1598
- rebuildConnectionSlabAsync(
1599
- chunkSize: number,
1600
- ): Promise<void>
1830
+ snapshotRNG(): RNGSnapshot
1601
1831
  ```
1602
1832
 
1603
- Cooperative asynchronous slab rebuild (Browser only).
1604
-
1605
- Strategy:
1606
- - Perform capacity decision + allocation up front (mirrors sync path).
1607
- - Populate connection data in microtask slices (yield via resolved Promise) to avoid long main‑thread stalls.
1608
- - Adaptive slice sizing for very large graphs if `config.browserSlabChunkTargetMs` set.
1833
+ Captures the current deterministic RNG lifecycle state as a portable snapshot.
1609
1834
 
1610
- Metrics: Increments `_slabAsyncBuilds` for observability.
1611
- Fallback: On Node (no `window`) defers to synchronous rebuild for simplicity.
1835
+ Overview:
1836
+ - Use this before temporary experiments, branching simulations, or stateful debug sessions.
1837
+ - The snapshot preserves enough information to resume from the same deterministic point later.
1838
+ - This is useful when comparing alternate algorithm branches from an identical random timeline.
1612
1839
 
1613
1840
  Parameters:
1614
- - `chunkSize` - Initial maximum connections per slice (may be reduced adaptively for huge graphs).
1841
+ - `this` - - Bound network instance whose RNG lifecycle state is captured.
1615
1842
 
1616
- Returns: Promise resolving once rebuild completes.
1843
+ Returns: Snapshot containing deterministic progress metadata and RNG state payload.
1617
1844
 
1618
- ### fastSlabActivate
1845
+ Example:
1619
1846
 
1620
1847
  ```ts
1621
- fastSlabActivate(
1622
- input: number[],
1623
- ): number[]
1848
+ const snapshot = network.snapshotRNG();
1624
1849
  ```
1625
1850
 
1626
- High‑performance forward pass using packed slabs + CSR adjacency.
1851
+ ### testNetwork
1627
1852
 
1628
- Fallback Conditions (auto‑detected):
1629
- - Missing slabs / adjacency structures.
1630
- - Topology/gating/stochastic predicates fail (see `_canUseFastSlab`).
1631
- - Gating present, when applicable (explicit guard).
1853
+ ```ts
1854
+ testNetwork(
1855
+ set: TestSample[],
1856
+ cost: CostFunction | undefined,
1857
+ ): TestNetworkResult
1858
+ ```
1632
1859
 
1633
- Implementation Notes:
1634
- - Reuses internal activation/state buffers to reduce per‑step allocation churn.
1635
- - Applies gain multiplication if optional gain slab exists.
1636
- - Assumes acyclic graph; topological order recomputed on demand if marked dirty.
1860
+ Evaluate a dataset and return average error and elapsed time.
1637
1861
 
1638
1862
  Parameters:
1639
- - `input` - Input vector (length must equal `network.input`).
1863
+ - `this` - Bound network instance.
1864
+ - `set` - Evaluation samples.
1865
+ - `cost` - Optional cost function override.
1640
1866
 
1641
- Returns: Output activations (detached plain array) of length `network.output`.
1867
+ Returns: Mean error and evaluation duration.
1642
1868
 
1643
- ### canUseFastSlab
1869
+ ### toJSONImpl
1644
1870
 
1645
1871
  ```ts
1646
- canUseFastSlab(
1647
- training: boolean,
1648
- ): boolean
1872
+ toJSONImpl(): NetworkJSON
1649
1873
  ```
1650
1874
 
1651
- Public convenience wrapper exposing fast path eligibility.
1652
- Mirrors `_canUseFastSlab` internal predicate.
1875
+ Serializes a network instance into the verbose JSON format.
1876
+
1877
+ Use this format when you need human-readable snapshots, explicit schema versioning,
1878
+ and better forward/backward compatibility handling.
1653
1879
 
1654
1880
  Parameters:
1655
- - `training` - Whether caller is performing training (disables fast path if true).
1881
+ - `this` - - Bound network instance.
1656
1882
 
1657
- Returns: True when slab fast path predicates hold.
1883
+ Returns: Versioned JSON payload with shape metadata, nodes, and connections.
1658
1884
 
1659
- ### getConnectionSlab
1885
+ Example:
1660
1886
 
1661
1887
  ```ts
1662
- getConnectionSlab(): ConnectionSlabView
1663
- ```
1664
-
1665
- Obtain (and lazily rebuild if dirty) the current packed SoA view of connections.
1666
-
1667
- Gain Omission: If the internal gain slab is absent (all gains neutral) a synthetic
1668
- neutral array is created and returned (NOT retained) to keep external educational
1669
- tooling branch‑free while preserving omission memory savings internally.
1888
+ import Network from '../../network';
1889
+ import { fromJSONImpl, toJSONImpl } from './network.serialize.utils';
1670
1890
 
1671
- Returns: Read‑only style view (do not mutate) containing typed arrays + metadata.
1891
+ const sourceNetwork = new Network(3, 1);
1892
+ const snapshotJson = toJSONImpl.call(sourceNetwork);
1893
+ const rebuiltNetwork = fromJSONImpl(snapshotJson);
1894
+ ```
1672
1895
 
1673
- ### getSlabAllocationStats
1896
+ ### trainImpl
1674
1897
 
1675
1898
  ```ts
1676
- getSlabAllocationStats(): { pool: { [x: string]: PoolKeyMetrics; }; fresh: number; pooled: number; }
1899
+ trainImpl(
1900
+ net: default,
1901
+ set: TrainingSample[],
1902
+ options: TrainingOptions,
1903
+ ): { error: number; iterations: number; time: number; }
1677
1904
  ```
1678
1905
 
1679
- Allocation statistics snapshot for slab typed arrays.
1906
+ High-level training orchestration with early stopping, smoothing & callbacks.
1680
1907
 
1681
- Includes:
1682
- - fresh: number of newly constructed typed arrays since process start / metrics reset.
1683
- - pooled: number of arrays served from the pool.
1684
- - pool: per‑key metrics (created, reused, maxRetained) for educational inspection.
1908
+ This is the main entrypoint used by `Network.train(...)`-style APIs.
1685
1909
 
1686
- NOTE: Stats are cumulative (not auto‑reset); callers may diff successive snapshots.
1910
+ Parameters:
1911
+ - `net` - - Network instance to train.
1912
+ - `set` - - Training dataset.
1913
+ - `options` - - Training options (stopping conditions, optimizer, hooks, etc.).
1687
1914
 
1688
- Returns: Plain object copy (safe to serialize) of current allocator counters.
1915
+ Returns: Summary payload containing final error, iteration count, and elapsed time.
1689
1916
 
1690
- ### generateStandalone
1917
+ Example:
1691
1918
 
1692
1919
  ```ts
1693
- generateStandalone(
1694
- net: default,
1695
- ): string
1920
+ const result = net.train(set, { iterations: 500, rate: 0.3 });
1921
+ console.log(result.error);
1696
1922
  ```
1697
1923
 
1698
- Generate a standalone JavaScript source string that returns an `activate(input:number[])` function.
1699
-
1700
- Implementation Steps:
1701
- 1. Validate presence of output nodes (must produce something observable).
1702
- 2. Assign stable sequential indices to nodes (used as array offsets in generated code).
1703
- 3. Collect initial activation/state values into typed array initializers for warm starting.
1704
- 4. For each non-input node, build a line computing S[i] (pre-activation sum with bias) and A[i]
1705
- (post-activation output). Gating multiplies activation by gate activations; self-connection adds
1706
- recurrent term S[i] * weight before activation.
1707
- 5. De-duplicate activation functions: each unique squash name is emitted once; references become
1708
- indices into array F of function references for compactness.
1709
- 6. Emit an IIFE producing the activate function with internal arrays A (activations) and S (states).
1710
-
1711
- Parameters:
1712
- - `net` - Network instance to snapshot.
1713
-
1714
- Returns: Source string (ES5-compatible) – safe to eval in sandbox to obtain activate function.
1715
-
1716
- ### getRegularizationStats
1717
-
1718
- ```ts
1719
- getRegularizationStats(): Record<string, unknown> | null
1720
- ```
1721
-
1722
- Obtain the last recorded regularization / stochastic statistics snapshot.
1723
-
1724
- Returns a defensive deep copy so callers can inspect metrics without risking mutation of the
1725
- internal `_lastStats` object maintained by the training loop (e.g., during pruning, dropout, or
1726
- noise scheduling updates).
1727
-
1728
- Returns: A deep-cloned stats object or null if no stats have been recorded yet.
1729
-
1730
- ### testNetwork
1731
-
1732
- ```ts
1733
- testNetwork(
1734
- set: TestSample[],
1735
- cost: CostFunction | undefined,
1736
- ): TestNetworkResult
1737
- ```
1738
-
1739
- Evaluate a dataset and return average error and elapsed time.
1740
-
1741
- Parameters:
1742
- - `this` - Bound network instance.
1743
- - `set` - Evaluation samples.
1744
- - `cost` - Optional cost function override.
1745
-
1746
- Returns: Mean error and evaluation duration.
1747
-
1748
- ### computeTopoOrder
1749
-
1750
- ```ts
1751
- computeTopoOrder(): void
1752
- ```
1753
-
1754
- Compute a topological ordering (Kahn's algorithm) for the current directed acyclic graph.
1755
- If cycles are detected (order shorter than node count) we fall back to raw node order to avoid breaking callers.
1756
- In non-acyclic mode we simply clear cached order to signal use of sequential node array.
1757
-
1758
- ### hasPath
1759
-
1760
- ```ts
1761
- hasPath(
1762
- from: default,
1763
- to: default,
1764
- ): boolean
1765
- ```
1766
-
1767
- Depth-first reachability test (avoids infinite loops via visited set).
1768
-
1769
- ### createMLP
1770
-
1771
- ```ts
1772
- createMLP(
1773
- inputCount: number,
1774
- hiddenCounts: number[],
1775
- outputCount: number,
1776
- ): default
1777
- ```
1778
-
1779
- Build a strictly layered and fully connected MLP network.
1780
-
1781
- Parameters:
1782
- - `this` - Network constructor.
1783
- - `inputCount` - Number of input nodes.
1784
- - `hiddenCounts` - Hidden-layer node counts.
1785
- - `outputCount` - Number of output nodes.
1786
-
1787
- Returns: Newly created MLP network.
1788
-
1789
- ### rebuildConnections
1790
-
1791
- ```ts
1792
- rebuildConnections(
1793
- networkInstance: default,
1794
- ): void
1795
- ```
1796
-
1797
- Rebuild the canonical connection array from per-node outgoing lists.
1798
-
1799
- Parameters:
1800
- - `networkInstance` - Target network.
1801
-
1802
- ### describeArchitecture
1803
-
1804
- ```ts
1805
- describeArchitecture(
1806
- network: default,
1807
- ): NetworkArchitectureDescriptor
1808
- ```
1809
-
1810
- Describes network architecture for diagnostics, telemetry, and UI rendering.
1811
-
1812
- This function prefers factual sources over heuristics so downstream tooling
1813
- can rely on the descriptor while still receiving useful output for partially
1814
- specified runtime graphs.
1815
-
1816
- Resolution priority is intentionally explicit:
1817
- 1) node `layer` metadata (factual when present)
1818
- 2) graph-derived feed-forward depth layering (factual for acyclic graphs)
1819
- 3) hidden-node count fallback (heuristic inference)
1820
-
1821
- Parameters:
1822
- - `network` - - Runtime network instance.
1823
-
1824
- Returns: Stable architecture descriptor.
1825
-
1826
- Example:
1827
-
1828
- ```ts
1829
- const descriptor = describeArchitecture(network);
1830
- // descriptor.hiddenLayerSizes -> [8, 4]
1831
- // descriptor.source -> 'layer-metadata' | 'graph-topology' | 'inferred'
1832
- ```
1833
-
1834
- ### resolveArchitectureDescriptor
1835
-
1836
- ```ts
1837
- resolveArchitectureDescriptor(
1838
- network: default,
1839
- ): NetworkArchitectureDescriptor
1840
- ```
1841
-
1842
- Resolve the public architecture descriptor, preferring live graph facts and
1843
- falling back to hydrated serialization metadata only when the live result is
1844
- still purely inferred.
1845
-
1846
- This helper keeps the descriptor ownership story in one chapter: topology
1847
- owns the live analysis while serialization can optionally hydrate a cached
1848
- descriptor that remains safe to reuse when the runtime graph shape matches.
1849
-
1850
- Parameters:
1851
- - `network` - Runtime network instance.
1852
-
1853
- Returns: Public architecture descriptor for telemetry and UI consumers.
1854
-
1855
- ### applyGradientClippingImpl
1856
-
1857
- ```ts
1858
- applyGradientClippingImpl(
1859
- net: default,
1860
- cfg: GradientClipRuntimeConfig,
1861
- ): void
1862
- ```
1863
-
1864
- Apply gradient clipping to a network using a normalized runtime configuration.
1865
-
1866
- This is a small wrapper that forwards to the concrete implementation used by training.
1867
-
1868
- Parameters:
1869
- - `net` - - Network instance to update.
1870
- - `cfg` - - Normalized clipping settings.
1871
-
1872
- ### propagate
1873
-
1874
- ```ts
1875
- propagate(
1876
- rate: number,
1877
- momentum: number,
1878
- update: boolean,
1879
- target: number[],
1880
- regularization: number,
1881
- costDerivative: CostDerivative | undefined,
1882
- ): void
1883
- ```
1884
-
1885
- Propagate output and hidden errors backward through the network.
1886
-
1887
- Parameters:
1888
- - `this` - Bound network instance.
1889
- - `rate` - Learning rate.
1890
- - `momentum` - Momentum factor.
1891
- - `update` - Whether to apply updates immediately.
1892
- - `target` - Output target values.
1893
- - `regularization` - L2 regularization factor.
1894
- - `costDerivative` - Optional output-node derivative override.
1895
-
1896
- ### clearState
1897
-
1898
- ```ts
1899
- clearState(): void
1900
- ```
1901
-
1902
- Clear all node runtime traces and states.
1903
-
1904
- Parameters:
1905
- - `this` - Bound network instance.
1906
-
1907
- ### trainSetImpl
1924
+ ### trainSetImpl
1908
1925
 
1909
1926
  ```ts
1910
1927
  trainSetImpl(
@@ -1938,1010 +1955,978 @@ Parameters:
1938
1955
 
1939
1956
  Returns: Mean cost across the processed samples.
1940
1957
 
1941
- ### trainImpl
1958
+ ### ungate
1942
1959
 
1943
1960
  ```ts
1944
- trainImpl(
1945
- net: default,
1946
- set: TrainingSample[],
1947
- options: TrainingOptions,
1948
- ): { error: number; iterations: number; time: number; }
1961
+ ungate(
1962
+ connection: default,
1963
+ ): void
1949
1964
  ```
1950
1965
 
1951
- High-level training orchestration with early stopping, smoothing & callbacks.
1966
+ Remove gating from a connection, restoring its static weight contribution.
1952
1967
 
1953
- This is the main entrypoint used by `Network.train(...)`-style APIs.
1968
+ Idempotent: If the connection is not currently gated, the call performs no structural changes
1969
+ (and optionally logs a warning). After ungating, the connection's weight will be used directly
1970
+ without modulation by a gater activation.
1971
+
1972
+ Complexity: O(n) where n = number of gated connections (indexOf lookup) – typically small.
1954
1973
 
1955
1974
  Parameters:
1956
- - `net` - - Network instance to train.
1957
- - `set` - - Training dataset.
1958
- - `options` - - Training options (stopping conditions, optimizer, hooks, etc.).
1975
+ - `this` - - Bound Network instance.
1976
+ - `connection` - - Connection to ungate.
1959
1977
 
1960
- Returns: Summary payload containing final error, iteration count, and elapsed time.
1978
+ ## architecture/network/network.types.ts
1961
1979
 
1962
- Example:
1980
+ ### ActivateNetworkInternals
1981
+
1982
+ Runtime interface for activation internals.
1983
+
1984
+ ### ActivationFunction
1963
1985
 
1964
1986
  ```ts
1965
- const result = net.train(set, { iterations: 500, rate: 0.3 });
1966
- console.log(result.error);
1987
+ ActivationFunction(
1988
+ x: number,
1989
+ derivate: boolean | undefined,
1990
+ ): number
1967
1991
  ```
1968
1992
 
1969
- ### __trainingInternals
1970
-
1971
- Test-only internal helper bundle.
1993
+ Runtime activation function signature used by ONNX activation import/export paths.
1972
1994
 
1973
- This is exported so unit tests can cover edge-cases in the smoothing logic without
1974
- running full end-to-end training loops.
1995
+ Neataptic-style activations support a dual-purpose call pattern:
1996
+ - `derivate === false | undefined`: return activation output $f(x)$
1997
+ - `derivate === true`: return derivative $f'(x)$
1975
1998
 
1976
- Important: this is **not** considered stable public API. It may change between releases.
1999
+ This matches historical Neataptic semantics and keeps ONNX import/export compatible.
1977
2000
 
1978
- ## architecture/network/network.types.ts
2001
+ Example:
1979
2002
 
1980
- ### NetworkRuntimeProps
2003
+ ```ts
2004
+ const y = activation(x);
2005
+ const dy = activation(x, true);
2006
+ ```
1981
2007
 
1982
- Internal runtime properties attached to Network instances.
2008
+ ### ActivationSquashFunction
1983
2009
 
1984
- ### NetworkArchitectureSource
2010
+ ```ts
2011
+ ActivationSquashFunction(
2012
+ x: number,
2013
+ derivate: boolean | undefined,
2014
+ ): number
2015
+ ```
1985
2016
 
1986
- Provenance of hidden-layer architecture information.
2017
+ Activation function signature used by ONNX layer emission helpers.
1987
2018
 
1988
- ### NetworkArchitectureDescriptor
2019
+ ### BackwardCandidateTraversalContext
1989
2020
 
1990
- Stable architecture descriptor for UI/telemetry consumers.
2021
+ Immutable context for backward candidate traversal.
1991
2022
 
1992
- Hidden-layer sizes are ordered from input-side to output-side.
2023
+ ### BuildAdjacencyContext
1993
2024
 
1994
- ### NetworkTopologyIntent
2025
+ Shared immutable inputs used across the adjacency build pipeline.
1995
2026
 
1996
- Public topology intent exposed by the network API.
2027
+ ### CheckpointConfig
1997
2028
 
1998
- Use `feed-forward` when the caller wants the library to preserve an acyclic,
1999
- forward-only contract. Use `unconstrained` when recurrent, gated, or other
2000
- cyclic structures may be introduced.
2029
+ Checkpoint callback configuration.
2001
2030
 
2002
- ### NetworkConstructorOptions
2031
+ Training can periodically call `save(...)` with a serialized network snapshot.
2032
+ You can persist these snapshots to disk, upload them, or keep them in-memory.
2003
2033
 
2004
- Public constructor options for `Network`.
2034
+ ### CompactConnectionRebuildContext
2005
2035
 
2006
- `topologyIntent` is the semantic, DX-first contract. `enforceAcyclic`
2007
- remains available for backward compatibility and must not contradict the
2008
- declared topology intent.
2036
+ Context for compact-connection reconstruction.
2009
2037
 
2010
- ### NetworkBootstrapInternals
2038
+ Connection rows are processed independently so malformed entries can be skipped without aborting import.
2011
2039
 
2012
- Internal constructor-time surface used by bootstrap helpers.
2040
+ ### CompactNodeRebuildContext
2013
2041
 
2014
- ### ConnectionWeightNoiseProps
2042
+ Context for compact-node reconstruction.
2015
2043
 
2016
- Internal runtime properties attached to Connection instances.
2044
+ Arrays are expected to be index-aligned so each node can be hydrated deterministically.
2017
2045
 
2018
- ### ActivateNetworkInternals
2046
+ ### CompactPayloadContext
2019
2047
 
2020
- Runtime interface for activation internals.
2048
+ Context carrying compact payload fields.
2021
2049
 
2022
- ### ConnectNetworkInternals
2050
+ This named-object form replaces tuple index access in internal orchestration code.
2023
2051
 
2024
- Runtime interface for connect internals.
2052
+ ### CompactSerializedNetworkTuple
2025
2053
 
2026
- ### DeterministicNetworkInternals
2054
+ Compact tuple payload used by `serialize` output.
2027
2055
 
2028
- Runtime interface for deterministic internals.
2056
+ Tuple slots are intentionally positional to reduce payload size:
2057
+ 0) activations, 1) states, 2) squash keys, 3) connections, 4) input size, 5) output size.
2029
2058
 
2030
- ### RNGSnapshot
2059
+ Example:
2031
2060
 
2032
- Snapshot payload for RNG state restore flows.
2061
+ ```ts
2062
+ const compactTuple: CompactSerializedNetworkTuple = [
2063
+ [0.1, 0.2],
2064
+ [0, 0],
2065
+ ['identity', 'tanh'],
2066
+ [{ from: 0, to: 1, weight: 0.5, gater: null }],
2067
+ 1,
2068
+ 1,
2069
+ ];
2070
+ ```
2033
2071
 
2034
- ### NetworkRuntimeControlInternals
2072
+ ### ConnectionGene
2035
2073
 
2036
- Internal network properties accessed by runtime-control helpers.
2074
+ Crossover connection-gene descriptor.
2037
2075
 
2038
- ### NetworkRuntimeDiagnosticsInternals
2076
+ ### ConnectionGeneSelectionContext
2039
2077
 
2040
- Internal network properties accessed by runtime diagnostics helpers.
2078
+ Immutable context for selecting inherited genes.
2041
2079
 
2042
- ### GatingNetworkProps
2080
+ ### ConnectionGeneticProps
2043
2081
 
2044
- Internal network properties accessed during gating operations.
2082
+ Extended connection shape used during genetic crossover.
2045
2083
 
2046
- ### SubNodeMutationConfig
2084
+ ### ConnectionGroupReinitContext
2047
2085
 
2048
- Mutation keep-gates option surface used by sub-node removal logic.
2086
+ Context for reinitializing connection group weights.
2049
2087
 
2050
- ### StatsNetworkProps
2088
+ ### ConnectionInternals
2051
2089
 
2052
- Internal network properties used by stats operations.
2090
+ Internal Connection properties accessed during slab operations.
2053
2091
 
2054
- ### GlobalThisWithStructuredClone
2092
+ ### ConnectionInternalsWithEnabled
2055
2093
 
2056
- GlobalThis extension exposing optional structuredClone.
2094
+ Connection view with optional enabled flag.
2057
2095
 
2058
- ### TopologyNetworkProps
2096
+ Some serialized formats preserve per-edge enablement, while others treat missing values
2097
+ as implicitly enabled.
2059
2098
 
2060
- Internal topology state carrier.
2099
+ ### ConnectionSlabView
2061
2100
 
2062
- ### TopologyBuildContext
2101
+ Shape returned by getConnectionSlab describing the packed SoA view.
2063
2102
 
2064
- Mutable context used while building topological ordering.
2103
+ ### ConnectionSplitResult
2065
2104
 
2066
- ### PathSearchContext
2105
+ Result of replacing a connection with split hidden node.
2067
2106
 
2068
- Mutable context used while running iterative path search.
2107
+ ### ConnectionWeightNoiseProps
2069
2108
 
2070
- ### NetworkStandaloneProps
2109
+ Internal runtime properties attached to Connection instances.
2071
2110
 
2072
- Internal standalone generation network view.
2111
+ ### ConnectNetworkInternals
2073
2112
 
2074
- ### NodeWithIndex
2113
+ Runtime interface for connect internals.
2075
2114
 
2076
- Node with generated index for standalone-code emission.
2115
+ ### Conv2DMapping
2077
2116
 
2078
- ### StandaloneGenerationContext
2117
+ Mapping declaration for treating a fully-connected layer as a 2D convolution during export.
2079
2118
 
2080
- Shared mutable state for standalone source generation.
2119
+ This does **not** magically turn an MLP into a convolutional network at runtime.
2120
+ It annotates a particular export-layer index with a conv interpretation so that:
2121
+ - The exported graph uses conv-shaped tensors/operators, and
2122
+ - Import can re-attach pooling/flatten metadata appropriately.
2081
2123
 
2082
- ### NetworkRemoveProps
2124
+ Pitfall: mappings must match the actual layer sizes. If `inHeight * inWidth * inChannels`
2125
+ does not correspond to the prior layer width (and similarly for outputs), export or import
2126
+ may reject the model.
2083
2127
 
2084
- Internal network properties accessed during remove operations.
2128
+ ### ConvKernelConsistencyContext
2085
2129
 
2086
- ### NodeRemovalContext
2130
+ Context for kernel-coordinate consistency checks at one output position.
2087
2131
 
2088
- Immutable context for validated node-removal request.
2132
+ ### ConvLayerPairContext
2089
2133
 
2090
- ### NodeConnectionSnapshotContext
2134
+ Context for one resolved Conv mapping layer pair.
2091
2135
 
2092
- Snapshot of node adjacency prior to removal.
2136
+ ### ConvOutputCoordinate
2093
2137
 
2094
- ### ReconnectEndpointPairContext
2138
+ Coordinate for one Conv output neuron position.
2095
2139
 
2096
- Endpoint pair for reconnecting bridged paths.
2140
+ ### ConvRepresentativeKernelContext
2097
2141
 
2098
- ### PruningMethod
2142
+ Context for representative Conv kernel collection per output channel.
2099
2143
 
2100
- Pruning strategy identifiers.
2144
+ ### ConvSharingValidationContext
2101
2145
 
2102
- ### NetworkPruningProps
2146
+ Context for validating Conv sharing across all declared mappings.
2103
2147
 
2104
- Internal network properties accessed during pruning operations.
2148
+ ### ConvSharingValidationResult
2105
2149
 
2106
- ### ScheduledTargetContext
2150
+ Result of Conv sharing validation across declared mappings.
2107
2151
 
2108
- Context for scheduled-pruning target computation.
2152
+ ### CostFunction
2109
2153
 
2110
- ### ScheduledTargetResult
2154
+ ```ts
2155
+ CostFunction(
2156
+ target: number[],
2157
+ output: number[],
2158
+ ): number
2159
+ ```
2111
2160
 
2112
- Result of scheduled-pruning target computation.
2161
+ Cost / loss function used during supervised training.
2113
2162
 
2114
- ### PruneSelectionContext
2163
+ A cost function compares an expected `target` vector with the network's produced `output`
2164
+ vector, returning a scalar error where **lower is better**.
2115
2165
 
2116
- Context for selecting prune candidates.
2166
+ Design notes:
2167
+ - This is called frequently (often once per training sample), so implementations should be
2168
+ **pure** and **allocation-light**.
2169
+ - Most built-in training loops assume the returned value is non-negative.
2117
2170
 
2118
- ### PruneSelectionResult
2171
+ Example (mean squared error):
2119
2172
 
2120
- Result of prune candidate selection.
2173
+ ```ts
2174
+ export const mse: CostFunction = (target, output) => {
2175
+ const sum = target.reduce((acc, targetValue, index) => {
2176
+ const diff = targetValue - (output[index] ?? 0);
2177
+ return acc + diff * diff;
2178
+ }, 0);
2179
+ return sum / Math.max(1, target.length);
2180
+ };
2181
+ ```
2121
2182
 
2122
- ### RegrowthPlanContext
2183
+ ### CostFunctionOrObject
2123
2184
 
2124
- Context for deriving regrowth plan.
2185
+ Cost function object compatibility shape.
2125
2186
 
2126
- ### RegrowthPlan
2187
+ ### CostFunctionOrRef
2127
2188
 
2128
- Derived regrowth execution plan.
2189
+ Evolve-side serializable cost-function reference.
2129
2190
 
2130
- ### RegrowthExecutionContext
2191
+ ### CrossoverContext
2131
2192
 
2132
- Context for regrowth execution routine.
2193
+ Immutable baseline context for one crossover run.
2133
2194
 
2134
- ### EvolutionaryTargetContext
2195
+ ### CrossoverNodeBuildContext
2135
2196
 
2136
- Context for evolutionary sparsity target computation.
2197
+ Node-build context derived from crossover baseline.
2137
2198
 
2138
- ### EvolutionaryTargetResult
2199
+ ### DenseActivationContext
2139
2200
 
2140
- Result of evolutionary sparsity target computation.
2201
+ Dense activation emission context.
2141
2202
 
2142
- ### SerializeNetworkInternals
2203
+ ### DenseActivationNodePayload
2143
2204
 
2144
- Runtime interface for accessing network internals during serialization.
2205
+ Strongly typed activation node payload used by dense export helpers.
2145
2206
 
2146
- This is an internal bridge type used by serializer helpers to read and rebuild
2147
- topology without exposing private implementation details in public APIs.
2207
+ ### DenseGemmNodePayload
2148
2208
 
2149
- ### NetworkInternalsWithDropout
2209
+ Strongly typed Gemm node payload used by dense export helpers.
2150
2210
 
2151
- Serialize internals with optional dropout field.
2211
+ ### DenseGraphNames
2152
2212
 
2153
- Verbose JSON snapshots normalize this value so readers can treat dropout as numeric data.
2213
+ Dense graph tensor names.
2154
2214
 
2155
- ### SerializeNodeInternals
2215
+ ### DenseInitializerValues
2156
2216
 
2157
- Runtime node internals needed for serialization workflows.
2217
+ Dense initializer value arrays.
2158
2218
 
2159
- These fields are the minimal node state required to round-trip compact and JSON payloads.
2219
+ ### DenseLayerContext
2160
2220
 
2161
- ### ConnectionInternalsWithEnabled
2221
+ Dense layer context enriched with resolved activation function.
2162
2222
 
2163
- Connection view with optional enabled flag.
2223
+ ### DenseLayerParams
2164
2224
 
2165
- Some serialized formats preserve per-edge enablement, while others treat missing values
2166
- as implicitly enabled.
2225
+ Parameters for dense layer emission.
2167
2226
 
2168
- ### SerializedConnection
2227
+ ### DenseOrderedNodePayload
2169
2228
 
2170
- Serialized connection representation used by compact and JSON formats.
2229
+ Dense node payload union used by ordered append helpers.
2171
2230
 
2172
- Endpoints are canonical node indices, which keeps payloads deterministic and language-agnostic.
2231
+ ### DenseTensorNames
2173
2232
 
2174
- ### CompactSerializedNetworkTuple
2233
+ Dense initializer tensor names.
2175
2234
 
2176
- Compact tuple payload used by `serialize` output.
2235
+ ### DenseWeightBuildContext
2177
2236
 
2178
- Tuple slots are intentionally positional to reduce payload size:
2179
- 0) activations, 1) states, 2) squash keys, 3) connections, 4) input size, 5) output size.
2237
+ Context for building dense layer initializers from two adjacent layers.
2180
2238
 
2181
- Example:
2239
+ ### DenseWeightBuildResult
2182
2240
 
2183
- ```ts
2184
- const compactTuple: CompactSerializedNetworkTuple = [
2185
- [0.1, 0.2],
2186
- [0, 0],
2187
- ['identity', 'tanh'],
2188
- [{ from: 0, to: 1, weight: 0.5, gater: null }],
2189
- 1,
2190
- 1,
2191
- ];
2192
- ```
2241
+ Dense layer initializer fold output.
2193
2242
 
2194
- ### NetworkJSONNode
2243
+ ### DenseWeightRow
2195
2244
 
2196
- Verbose JSON node representation.
2245
+ One collected dense row before fold to flattened initializers.
2197
2246
 
2198
- Node entries are self-describing and intended for readable, versioned snapshots.
2247
+ ### DenseWeightRowCollectionContext
2199
2248
 
2200
- ### NetworkJSONConnection
2249
+ Context for collecting one dense row.
2201
2250
 
2202
- Verbose JSON connection representation.
2251
+ ### DeterministicChainMutationContext
2203
2252
 
2204
- Includes optional gater and explicit enabled state for portability.
2253
+ Context for deterministic-chain add-node mutation.
2205
2254
 
2206
- ### NetworkJSON
2255
+ ### DeterministicNetworkInternals
2207
2256
 
2208
- Verbose JSON payload representation used by `toJSONImpl` and `fromJSONImpl`.
2257
+ Runtime interface for deterministic internals.
2209
2258
 
2210
- `formatVersion` enables compatibility checks and migration handling.
2259
+ ### DiagonalRecurrentBuildContext
2211
2260
 
2212
- Example:
2261
+ Context for building a diagonal recurrent matrix from self-connections.
2213
2262
 
2214
- ```ts
2215
- const payload: NetworkJSON = {
2216
- formatVersion: 2,
2217
- input: 2,
2218
- output: 1,
2219
- dropout: 0,
2220
- nodes: [{ type: 'input', bias: 0, squash: 'identity', index: 0 }],
2221
- connections: [],
2222
- };
2223
- ```
2263
+ ### DirectionalConnectionContext
2224
2264
 
2225
- ### CompactPayloadContext
2265
+ Indexed context for directional connection metadata.
2226
2266
 
2227
- Context carrying compact payload fields.
2267
+ ### DistinctNodePair
2228
2268
 
2229
- This named-object form replaces tuple index access in internal orchestration code.
2269
+ Selected distinct node pair for swap mutation.
2230
2270
 
2231
- ### ResolvedNetworkSizeContext
2271
+ ### EvolutionaryTargetContext
2232
2272
 
2233
- Resolved input/output sizes for rebuild.
2273
+ Context for evolutionary sparsity target computation.
2234
2274
 
2235
- Values reflect override-first resolution semantics used during deserialization.
2275
+ ### EvolutionaryTargetResult
2236
2276
 
2237
- ### CompactNodeRebuildContext
2277
+ Result of evolutionary sparsity target computation.
2238
2278
 
2239
- Context for compact-node reconstruction.
2279
+ ### EvolutionConfig
2240
2280
 
2241
- Arrays are expected to be index-aligned so each node can be hydrated deterministically.
2281
+ Internal normalized evolution config.
2242
2282
 
2243
- ### CompactConnectionRebuildContext
2283
+ ### EvolutionFitnessFunction
2244
2284
 
2245
- Context for compact-connection reconstruction.
2285
+ ```ts
2286
+ EvolutionFitnessFunction(
2287
+ arg0: default & default[],
2288
+ ): number | Promise<void>
2289
+ ```
2246
2290
 
2247
- Connection rows are processed independently so malformed entries can be skipped without aborting import.
2291
+ Unified evolution fitness callback shape.
2248
2292
 
2249
- ### JsonNodeRebuildContext
2293
+ ### EvolutionLoopState
2250
2294
 
2251
- Context for JSON-node reconstruction.
2295
+ Mutable state tracked during evolution loop.
2252
2296
 
2253
- Node entries are rebuilt in order and pushed into mutable runtime internals.
2297
+ ### EvolutionSettings
2254
2298
 
2255
- ### JsonConnectionRebuildContext
2299
+ Scalar evolution settings used by orchestration.
2256
2300
 
2257
- Context for JSON-connection reconstruction.
2301
+ ### EvolutionStopConditions
2258
2302
 
2259
- Connection rows may include optional gater and enabled metadata.
2303
+ Effective evolution stopping conditions.
2260
2304
 
2261
- ### CostFunction
2305
+ ### EvolveCostFunction
2262
2306
 
2263
2307
  ```ts
2264
- CostFunction(
2308
+ EvolveCostFunction(
2265
2309
  target: number[],
2266
2310
  output: number[],
2267
2311
  ): number
2268
2312
  ```
2269
2313
 
2270
- Cost / loss function used during supervised training.
2271
-
2272
- A cost function compares an expected `target` vector with the network's produced `output`
2273
- vector, returning a scalar error where **lower is better**.
2274
-
2275
- Design notes:
2276
- - This is called frequently (often once per training sample), so implementations should be
2277
- **pure** and **allocation-light**.
2278
- - Most built-in training loops assume the returned value is non-negative.
2279
-
2280
- Example (mean squared error):
2281
-
2282
- ```ts
2283
- export const mse: CostFunction = (target, output) => {
2284
- const sum = target.reduce((acc, targetValue, index) => {
2285
- const diff = targetValue - (output[index] ?? 0);
2286
- return acc + diff * diff;
2287
- }, 0);
2288
- return sum / Math.max(1, target.length);
2289
- };
2290
- ```
2314
+ Evolve-side cost function signature.
2291
2315
 
2292
- ### GradientClipConfig
2316
+ ### EvolveOptions
2293
2317
 
2294
- Gradient clipping configuration.
2318
+ Evolve options bag.
2295
2319
 
2296
- Clipping prevents rare large gradients from causing unstable weight updates.
2297
- It is most useful for recurrent networks and noisy datasets.
2320
+ ### FanOutCollectionContext
2298
2321
 
2299
- Conceptual modes:
2300
- - `norm`: clip by a global $L_2$ norm threshold.
2301
- - `percentile`: clip using a running percentile estimate (robust to outliers).
2302
- - `layerwise*`: apply the same idea per-layer (useful when layers have very different scales).
2322
+ Context for fan-out collection: build inputs plus the output count buffer.
2303
2323
 
2304
- ### MixedPrecisionDynamicConfig
2324
+ ### FastSlabNodeRuntime
2305
2325
 
2306
- Dynamic mixed-precision configuration.
2326
+ Node shape required by fast slab activation kernels.
2307
2327
 
2308
- When enabled, training uses a loss-scaling heuristic that attempts to keep gradients
2309
- in a numerically stable range. If an overflow is detected, the scale is reduced.
2328
+ ### FitnessSetup
2310
2329
 
2311
- ### MixedPrecisionConfig
2330
+ Result of fitness-strategy setup.
2312
2331
 
2313
- Mixed-precision configuration.
2332
+ ### FlattenAfterPoolingContext
2314
2333
 
2315
- Mixed precision can improve throughput by running some math in lower precision while
2316
- keeping a stable FP32 master copy of parameters when needed.
2334
+ Flatten emission context after optional pooling.
2317
2335
 
2318
- ### OptimizerConfigBase
2336
+ ### ForwardCandidateTraversalContext
2319
2337
 
2320
- Base optimizer configuration.
2338
+ Immutable context for forward candidate traversal.
2321
2339
 
2322
- Training accepts either an optimizer name (`"adam"`, `"sgd"`, ...) or an object.
2323
- This object form is useful when you want to pin numeric hyperparameters or wrap a base
2324
- optimizer (e.g. lookahead).
2340
+ ### FusedRecurrentEmissionExecutionContext
2325
2341
 
2326
- Example:
2342
+ Shared execution context for emitting one fused recurrent layer payload.
2327
2343
 
2328
- ```ts
2329
- net.train(set, {
2330
- iterations: 1_000,
2331
- rate: 0.001,
2332
- optimizer: { type: 'adamw', beta1: 0.9, beta2: 0.999, eps: 1e-8, weightDecay: 0.01 },
2333
- });
2334
- ```
2344
+ ### FusedRecurrentGraphNames
2335
2345
 
2336
- Notes:
2337
- - Exact supported `type` values are validated by training utilities.
2338
- - Unspecified fields fall back to sensible defaults per optimizer.
2346
+ Context for ONNX fused recurrent node payload names.
2339
2347
 
2340
- ### SerializedNetwork
2348
+ ### FusedRecurrentInitializerNames
2341
2349
 
2342
- Serialized network payload used in checkpoint callbacks.
2350
+ Context for ONNX fused recurrent initializer names.
2343
2351
 
2344
- This is intentionally loose: serialization formats evolve and may include nested
2345
- structures. Treat this as an opaque snapshot blob.
2352
+ ### GatingNetworkProps
2346
2353
 
2347
- ### CheckpointConfig
2354
+ Internal network properties accessed during gating operations.
2348
2355
 
2349
- Checkpoint callback configuration.
2356
+ ### GeneEndpointsContext
2350
2357
 
2351
- Training can periodically call `save(...)` with a serialized network snapshot.
2352
- You can persist these snapshots to disk, upload them, or keep them in-memory.
2358
+ Endpoints for one gene traversal step.
2353
2359
 
2354
- ### ScheduleConfig
2360
+ ### GeneticNetwork
2355
2361
 
2356
- Schedule callback configuration.
2362
+ Runtime network shape used by crossover internals.
2357
2363
 
2358
- A schedule callback is a simple "tick hook" that runs every N iterations.
2359
- Typical uses include logging, custom learning-rate schedules, or diagnostics.
2364
+ ### GeneTraversalContext
2360
2365
 
2361
- ### MetricsHook
2366
+ Traversal context for one connection gene.
2362
2367
 
2363
- ```ts
2364
- MetricsHook(
2365
- m: { iteration: number; error: number; plateauError?: number | undefined; gradNorm: number; },
2366
- ): void
2367
- ```
2368
+ ### GlobalThisWithStructuredClone
2368
2369
 
2369
- Metrics hook signature.
2370
+ GlobalThis extension exposing optional structuredClone.
2370
2371
 
2371
- If provided, this callback receives summarized metrics after each iteration.
2372
- It is designed for lightweight telemetry, not heavy data export.
2372
+ ### GradientClipConfig
2373
2373
 
2374
- ### MovingAverageType
2374
+ Gradient clipping configuration.
2375
2375
 
2376
- Moving-average strategy identifier.
2376
+ Clipping prevents rare large gradients from causing unstable weight updates.
2377
+ It is most useful for recurrent networks and noisy datasets.
2377
2378
 
2378
- These strategies are used to smooth the monitored error curve during training.
2379
- Smoothing can make early stopping and progress logging less noisy.
2379
+ Conceptual modes:
2380
+ - `norm`: clip by a global $L_2$ norm threshold.
2381
+ - `percentile`: clip using a running percentile estimate (robust to outliers).
2382
+ - `layerwise*`: apply the same idea per-layer (useful when layers have very different scales).
2380
2383
 
2381
- ### TrainingOptions
2384
+ ### GruEmissionContext
2382
2385
 
2383
- Public training options accepted by the high-level training orchestration.
2386
+ Context for heuristic GRU emission when a layer matches expected shape.
2384
2387
 
2385
- Training in this codebase is conceptually:
2386
- 1) forward activation
2387
- 2) backward propagation
2388
- 3) optimizer update
2389
- repeated until a stopping condition is met.
2388
+ ### HiddenLayerActivationTraversalContext
2390
2389
 
2391
- Minimal example:
2390
+ Hidden-layer traversal context for assigning imported activation functions.
2392
2391
 
2393
- ```ts
2394
- net.train(set, {
2395
- iterations: 500,
2396
- rate: 0.3,
2397
- batchSize: 16,
2398
- gradientClip: { mode: 'norm', maxNorm: 1 },
2399
- });
2400
- ```
2392
+ ### HiddenLayerHeuristicContext
2401
2393
 
2402
- Stopping conditions:
2403
- - Provide at least one of `iterations` or `error`.
2404
- - `earlyStopPatience` adds an additional "stop when no improvement" guard.
2394
+ Context for one hidden layer during heuristic recurrent emission.
2405
2395
 
2406
- ### PrimarySmoothingState
2396
+ ### IndexedMetadataAppendContext
2407
2397
 
2408
- Mutable smoothing state for monitored error.
2398
+ Append-an-index metadata context for JSON-array metadata keys.
2409
2399
 
2410
- ### PlateauSmoothingState
2400
+ ### InputOutputEndpoints
2411
2401
 
2412
- Mutable smoothing state for plateau metric.
2402
+ Required endpoint pair for input/output edge seeding.
2413
2403
 
2414
- ### MonitoredSmoothingConfig
2404
+ ### JsonConnectionRebuildContext
2415
2405
 
2416
- Config for monitored smoothing computation.
2406
+ Context for JSON-connection reconstruction.
2417
2407
 
2418
- ### PlateauSmoothingConfig
2408
+ Connection rows may include optional gater and enabled metadata.
2419
2409
 
2420
- Config for plateau smoothing computation.
2410
+ ### JsonNodeRebuildContext
2421
2411
 
2422
- ### TrainingConnectionInternals
2412
+ Context for JSON-node reconstruction.
2423
2413
 
2424
- Runtime connection view used by training internals.
2414
+ Node entries are rebuilt in order and pushed into mutable runtime internals.
2425
2415
 
2426
- ### TrainingNodeInternals
2416
+ ### LayerActivationContext
2427
2417
 
2428
- Runtime node view used by training internals.
2418
+ Activation analysis context for one layer.
2429
2419
 
2430
- ### TrainingNetworkInternals
2420
+ ### LayerActivationValidationContext
2431
2421
 
2432
- Runtime network view used by training internals.
2422
+ Activation-homogeneity decision context for one current layer.
2433
2423
 
2434
- ### RegularizationConfig
2424
+ ### LayerBuildContext
2435
2425
 
2436
- L1/L2 regularization configuration.
2426
+ Layer build context used while emitting one ONNX graph layer segment.
2437
2427
 
2438
- ### CostFunctionOrObject
2428
+ ### LayerConnectivityValidationContext
2439
2429
 
2440
- Cost function object compatibility shape.
2430
+ Connectivity decision context for one source-target node pair.
2441
2431
 
2442
- ### TrainingSample
2432
+ ### LayerOrderingNodeGroups
2443
2433
 
2444
- A single supervised training sample used in evolution scoring.
2434
+ Node partitions used by ONNX layered-ordering inference traversal.
2445
2435
 
2446
- ### EvolveCostFunction
2436
+ ### LayerOrderingResolutionContext
2447
2437
 
2448
- ```ts
2449
- EvolveCostFunction(
2450
- target: number[],
2451
- output: number[],
2452
- ): number
2453
- ```
2438
+ Mutable traversal state while resolving hidden-layer ordering.
2454
2439
 
2455
- Evolve-side cost function signature.
2440
+ ### LayerRecurrentDecisionContext
2456
2441
 
2457
- ### CostFunctionOrRef
2442
+ Context used to decide recurrent emission branch usage.
2458
2443
 
2459
- Evolve-side serializable cost-function reference.
2444
+ ### LayerTraversalContext
2460
2445
 
2461
- ### EvolutionConfig
2446
+ Layer traversal context with adjacent layers and output classification.
2462
2447
 
2463
- Internal normalized evolution config.
2448
+ ### LayerValidationTraversalContext
2464
2449
 
2465
- ### EvolutionSettings
2450
+ Layer-wise validation context for activation and connectivity checks.
2466
2451
 
2467
- Scalar evolution settings used by orchestration.
2452
+ ### LstmEmissionContext
2468
2453
 
2469
- ### EvolutionStopConditions
2454
+ Context for heuristic LSTM emission when a layer matches expected shape.
2470
2455
 
2471
- Effective evolution stopping conditions.
2456
+ ### MetricsHook
2472
2457
 
2473
- ### EvolutionLoopState
2458
+ ```ts
2459
+ MetricsHook(
2460
+ m: { iteration: number; error: number; plateauError?: number | undefined; gradNorm: number; },
2461
+ ): void
2462
+ ```
2474
2463
 
2475
- Mutable state tracked during evolution loop.
2464
+ Metrics hook signature.
2476
2465
 
2477
- ### EvolveOptions
2466
+ If provided, this callback receives summarized metrics after each iteration.
2467
+ It is designed for lightweight telemetry, not heavy data export.
2478
2468
 
2479
- Evolve options bag.
2469
+ ### MixedPrecisionConfig
2480
2470
 
2481
- ### SingleGenomeFitnessFunction
2471
+ Mixed-precision configuration.
2482
2472
 
2483
- ```ts
2484
- SingleGenomeFitnessFunction(
2485
- genome: default,
2486
- ): number
2487
- ```
2473
+ Mixed precision can improve throughput by running some math in lower precision while
2474
+ keeping a stable FP32 master copy of parameters when needed.
2488
2475
 
2489
- Fitness signature evaluating one genome.
2476
+ ### MixedPrecisionDynamicConfig
2490
2477
 
2491
- ### PopulationFitnessFunction
2478
+ Dynamic mixed-precision configuration.
2492
2479
 
2493
- ```ts
2494
- PopulationFitnessFunction(
2495
- population: default[],
2496
- ): Promise<void>
2497
- ```
2480
+ When enabled, training uses a loss-scaling heuristic that attempts to keep gradients
2481
+ in a numerically stable range. If an overflow is detected, the scale is reduced.
2498
2482
 
2499
- Fitness signature evaluating full population asynchronously.
2483
+ ### MonitoredSmoothingConfig
2500
2484
 
2501
- ### EvolutionFitnessFunction
2485
+ Config for monitored smoothing computation.
2502
2486
 
2503
- ```ts
2504
- EvolutionFitnessFunction(
2505
- arg0: default & default[],
2506
- ): number | Promise<void>
2507
- ```
2487
+ ### MovingAverageType
2508
2488
 
2509
- Unified evolution fitness callback shape.
2489
+ Moving-average strategy identifier.
2510
2490
 
2511
- ### FitnessSetup
2491
+ These strategies are used to smooth the monitored error curve during training.
2492
+ Smoothing can make early stopping and progress logging less noisy.
2512
2493
 
2513
- Result of fitness-strategy setup.
2494
+ ### MutationHandler
2514
2495
 
2515
- ### PopulationWorkerEvaluationContext
2496
+ ```ts
2497
+ MutationHandler(
2498
+ method: MutationMethod | undefined,
2499
+ ): void
2500
+ ```
2516
2501
 
2517
- Shared context for one population worker evaluation run.
2502
+ Mutation handler function contract.
2518
2503
 
2519
- ### WorkerTraversalContext
2504
+ ### MutationMethod
2520
2505
 
2521
- Worker-local traversal context.
2506
+ Mutation method descriptor shape.
2522
2507
 
2523
- ### NeatRuntime
2508
+ ### MutationMethodObject
2524
2509
 
2525
- Minimal runtime contract consumed from NEAT in evolve utilities.
2510
+ Object-only form of mutation method descriptor.
2526
2511
 
2527
- ### NetworkGeneticProps
2512
+ ### NeatRuntime
2528
2513
 
2529
- Runtime properties used during genetic operations.
2514
+ Minimal runtime contract consumed from NEAT in evolve utilities.
2530
2515
 
2531
- ### ConnectionGene
2516
+ ### NetworkActivationRuntime
2532
2517
 
2533
- Crossover connection-gene descriptor.
2518
+ Runtime activation contract used by slab-based execution paths.
2534
2519
 
2535
- ### ConnectionGeneticProps
2520
+ ### NetworkArchitectureDescriptor
2536
2521
 
2537
- Extended connection shape used during genetic crossover.
2522
+ Stable architecture descriptor for UI/telemetry consumers.
2538
2523
 
2539
- ### GeneticNetwork
2524
+ Hidden-layer sizes are ordered from input-side to output-side.
2540
2525
 
2541
- Runtime network shape used by crossover internals.
2526
+ ### NetworkArchitectureSource
2542
2527
 
2543
- ### OffspringMaterializationContext
2528
+ Provenance of hidden-layer architecture information.
2544
2529
 
2545
- Immutable context for offspring materialization.
2530
+ ### NetworkBootstrapInternals
2546
2531
 
2547
- ### GeneTraversalContext
2532
+ Internal constructor-time surface used by bootstrap helpers.
2548
2533
 
2549
- Traversal context for one connection gene.
2534
+ ### NetworkConstructor
2550
2535
 
2551
- ### GeneEndpointsContext
2536
+ Constructor signature for runtime Network import.
2552
2537
 
2553
- Endpoints for one gene traversal step.
2538
+ ### NetworkConstructorOptions
2554
2539
 
2555
- ### ConnectionGeneSelectionContext
2540
+ Public constructor options for `Network`.
2556
2541
 
2557
- Immutable context for selecting inherited genes.
2542
+ `topologyIntent` is the semantic, DX-first contract. `enforceAcyclic`
2543
+ remains available for backward compatibility and must not contradict the
2544
+ declared topology intent.
2558
2545
 
2559
- ### Parent1GeneTraversalContext
2546
+ ### NetworkGeneticProps
2560
2547
 
2561
- Traversal state for parent-1 innovation walk.
2548
+ Runtime properties used during genetic operations.
2562
2549
 
2563
- ### Parent1TraversalSelectionResult
2550
+ ### NetworkInternalsWithDropout
2564
2551
 
2565
- Fold result for parent-1 traversal selection.
2552
+ Serialize internals with optional dropout field.
2566
2553
 
2567
- ### CrossoverContext
2554
+ Verbose JSON snapshots normalize this value so readers can treat dropout as numeric data.
2568
2555
 
2569
- Immutable baseline context for one crossover run.
2556
+ ### NetworkJSON
2570
2557
 
2571
- ### CrossoverNodeBuildContext
2558
+ Verbose JSON payload representation used by `toJSONImpl` and `fromJSONImpl`.
2572
2559
 
2573
- Node-build context derived from crossover baseline.
2560
+ `formatVersion` enables compatibility checks and migration handling.
2574
2561
 
2575
- ### ParentMetrics
2562
+ Example:
2576
2563
 
2577
- Compact parent metrics summary.
2564
+ ```ts
2565
+ const payload: NetworkJSON = {
2566
+ formatVersion: 2,
2567
+ input: 2,
2568
+ output: 1,
2569
+ dropout: 0,
2570
+ nodes: [{ type: 'input', bias: 0, squash: 'identity', index: 0 }],
2571
+ connections: [],
2572
+ };
2573
+ ```
2578
2574
 
2579
- ### NetworkConstructor
2575
+ ### NetworkJSONConnection
2580
2576
 
2581
- Constructor signature for runtime Network import.
2577
+ Verbose JSON connection representation.
2582
2578
 
2583
- ### MutationMethod
2579
+ Includes optional gater and explicit enabled state for portability.
2584
2580
 
2585
- Mutation method descriptor shape.
2581
+ ### NetworkJSONNode
2586
2582
 
2587
- ### MutationMethodObject
2583
+ Verbose JSON node representation.
2588
2584
 
2589
- Object-only form of mutation method descriptor.
2585
+ Node entries are self-describing and intended for readable, versioned snapshots.
2590
2586
 
2591
2587
  ### NetworkMutationProps
2592
2588
 
2593
2589
  Internal network properties accessed during mutations.
2594
2590
 
2595
- ### MutationHandler
2591
+ ### NetworkPruningProps
2596
2592
 
2597
- ```ts
2598
- MutationHandler(
2599
- method: MutationMethod | undefined,
2600
- ): void
2601
- ```
2593
+ Internal network properties accessed during pruning operations.
2602
2594
 
2603
- Mutation handler function contract.
2595
+ ### NetworkRemoveProps
2604
2596
 
2605
- ### ForwardCandidateTraversalContext
2597
+ Internal network properties accessed during remove operations.
2606
2598
 
2607
- Immutable context for forward candidate traversal.
2599
+ ### NetworkRuntimeControlInternals
2608
2600
 
2609
- ### BackwardCandidateTraversalContext
2601
+ Internal network properties accessed by runtime-control helpers.
2610
2602
 
2611
- Immutable context for backward candidate traversal.
2603
+ ### NetworkRuntimeDiagnosticsInternals
2612
2604
 
2613
- ### DirectionalConnectionContext
2605
+ Internal network properties accessed by runtime diagnostics helpers.
2614
2606
 
2615
- Indexed context for directional connection metadata.
2607
+ ### NetworkRuntimeProps
2616
2608
 
2617
- ### InputOutputEndpoints
2609
+ Internal runtime properties attached to Network instances.
2618
2610
 
2619
- Required endpoint pair for input/output edge seeding.
2611
+ ### NetworkSlabProps
2620
2612
 
2621
- ### ConnectionSplitResult
2613
+ Internal Network properties for slab operations.
2622
2614
 
2623
- Result of replacing a connection with split hidden node.
2615
+ ### NetworkStandaloneProps
2624
2616
 
2625
- ### RecurrentLayerShape
2617
+ Internal standalone generation network view.
2626
2618
 
2627
- Minimal recurrent-layer shape used by mutation expanders.
2619
+ ### NetworkTopologyIntent
2628
2620
 
2629
- ### DeterministicChainMutationContext
2621
+ Public topology intent exposed by the network API.
2630
2622
 
2631
- Context for deterministic-chain add-node mutation.
2623
+ Use `feed-forward` when the caller wants the library to preserve an acyclic,
2624
+ forward-only contract. Use `unconstrained` when recurrent, gated, or other
2625
+ cyclic structures may be introduced.
2632
2626
 
2633
- ### DistinctNodePair
2627
+ ### NetworkTopoRuntime
2634
2628
 
2635
- Selected distinct node pair for swap mutation.
2629
+ Runtime topology contract used to lazily rebuild topological order.
2636
2630
 
2637
- ### TargetLayerPeerContext
2631
+ ### NetworkWithOnnxImportPooling
2638
2632
 
2639
- Context for target-layer peer traversal.
2633
+ Network instance augmented with optional imported ONNX pooling metadata.
2640
2634
 
2641
- ### SourcePeerConnectionCountContext
2635
+ ### NodeConnectionSnapshotContext
2642
2636
 
2643
- Context for source-to-peer connection counting.
2637
+ Snapshot of node adjacency prior to removal.
2644
2638
 
2645
- ### WeightSamplingRangeContext
2639
+ ### NodeInternals
2646
2640
 
2647
- Context for sampling one random weight value.
2641
+ Runtime interface for accessing node internal properties.
2648
2642
 
2649
- ### ConnectionGroupReinitContext
2643
+ This is intentionally "internal": it exposes mutable fields that the ONNX exporter/importer
2644
+ needs (connections, bias, squash). Regular library users should generally interact with
2645
+ the public `Node` API instead.
2650
2646
 
2651
- Context for reinitializing connection group weights.
2647
+ ### NodeInternalsWithExportIndex
2648
+
2649
+ Runtime node internals augmented with optional export index metadata.
2652
2650
 
2653
2651
  ### NodePair
2654
2652
 
2655
2653
  Canonical source-target node pair tuple.
2656
2654
 
2657
- ### Conv2DMapping
2655
+ ### NodeRemovalContext
2658
2656
 
2659
- Mapping declaration for treating a fully-connected layer as a 2D convolution during export.
2657
+ Immutable context for validated node-removal request.
2660
2658
 
2661
- This does **not** magically turn an MLP into a convolutional network at runtime.
2662
- It annotates a particular export-layer index with a conv interpretation so that:
2663
- - The exported graph uses conv-shaped tensors/operators, and
2664
- - Import can re-attach pooling/flatten metadata appropriately.
2659
+ ### NodeWithIndex
2665
2660
 
2666
- Pitfall: mappings must match the actual layer sizes. If `inHeight * inWidth * inChannels`
2667
- does not correspond to the prior layer width (and similarly for outputs), export or import
2668
- may reject the model.
2661
+ Node with generated index for standalone-code emission.
2669
2662
 
2670
- ### OnnxAttribute
2663
+ ### OffspringMaterializationContext
2671
2664
 
2672
- ONNX node attribute payload.
2665
+ Immutable context for offspring materialization.
2673
2666
 
2674
- This simplified JSON-first shape is enough for the operators emitted by the
2675
- current exporter. It intentionally avoids protobuf-level complexity while
2676
- still preserving the attribute variants needed by the importer.
2667
+ ### OnnxActivationAssignmentContext
2677
2668
 
2678
- ### OnnxDimension
2669
+ Shared activation-assignment context for hidden and output traversal.
2679
2670
 
2680
- One dimension inside an ONNX tensor shape.
2671
+ ### OnnxActivationLayerOperations
2681
2672
 
2682
- Use `dim_value` for fixed numeric widths and `dim_param` for symbolic names
2683
- such as a batch dimension.
2673
+ Layer-indexed activation operator lookup extracted from ONNX graph nodes.
2684
2674
 
2685
- ### OnnxGraph
2675
+ ### OnnxActivationOperation
2686
2676
 
2687
- Graph body of an ONNX-like model.
2677
+ Supported ONNX activation operators recognized during activation import.
2688
2678
 
2689
- The exporter writes three main collections here:
2690
- - `inputs` and `outputs` describe graph boundaries,
2691
- - `initializer` stores constant tensors such as weights and biases,
2692
- - `node` stores the ordered operator payloads that consume those tensors.
2679
+ ### OnnxActivationOperationResolutionContext
2693
2680
 
2694
- ### OnnxMetadataProperty
2681
+ Activation operation resolution context for one neuron or layer default.
2695
2682
 
2696
- Canonical metadata key-value pair used in ONNX model metadata_props.
2683
+ ### OnnxActivationParseResult
2697
2684
 
2698
- ### OnnxModel
2685
+ Parsed ONNX activation-node naming payload.
2699
2686
 
2700
- ONNX-like model container (JSON-serializable).
2687
+ ### OnnxAttribute
2701
2688
 
2702
- This is the main “wire format” object in this folder. Persist it as JSON text:
2689
+ ONNX node attribute payload.
2703
2690
 
2704
- ```ts
2705
- const jsonText = JSON.stringify(model);
2706
- const restoredModel = JSON.parse(jsonText) as OnnxModel;
2707
- ```
2691
+ This simplified JSON-first shape is enough for the operators emitted by the
2692
+ current exporter. It intentionally avoids protobuf-level complexity while
2693
+ still preserving the attribute variants needed by the importer.
2708
2694
 
2709
- Notes:
2710
- - `metadata_props` contains NeatapticTS-specific keys (layer sizes, recurrent flags,
2711
- conv/pool mappings, etc.). This is where most round-trip hints live.
2712
- - Initializers currently store floating-point weights in `float_data`.
2695
+ ### OnnxBaseModelBuildContext
2713
2696
 
2714
- Security/trust boundary:
2715
- - Treat this as untrusted input if it comes from outside your process.
2697
+ Context for constructing a base ONNX model shell.
2716
2698
 
2717
- ### OnnxNode
2699
+ ### OnnxBuildResolvedOptions
2718
2700
 
2719
- One ONNX operator invocation inside the graph.
2701
+ Resolved options used by ONNX model build orchestration.
2720
2702
 
2721
- Nodes connect named tensors rather than object references, which keeps the
2722
- exported payload easy to serialize, inspect, and diff as plain JSON.
2703
+ ### OnnxConvEmissionContext
2723
2704
 
2724
- ### OnnxShape
2705
+ Context used after resolving Conv mapping for one layer.
2725
2706
 
2726
- ONNX tensor type shape.
2707
+ ### OnnxConvEmissionParams
2727
2708
 
2728
- ### OnnxTensor
2709
+ Parameters accepted by Conv layer emission.
2729
2710
 
2730
- Serialized tensor payload stored inside graph initializers.
2711
+ ### OnnxConvKernelCoordinate
2731
2712
 
2732
- NeatapticTS currently writes floating-point parameter vectors and matrices to
2733
- `float_data`, along with the tensor name, element type, and logical shape.
2713
+ Coordinate for one Conv kernel weight lookup.
2734
2714
 
2735
- ### OnnxTensorType
2715
+ ### OnnxConvParameters
2736
2716
 
2737
- ONNX tensor type.
2717
+ Flattened Conv parameters for ONNX initializers.
2738
2718
 
2739
- ### OnnxValueInfo
2719
+ ### OnnxConvTensorNames
2740
2720
 
2741
- ONNX value info (input/output description).
2721
+ Tensor names generated for Conv parameters.
2742
2722
 
2743
- ### Pool2DMapping
2723
+ ### OnnxDimension
2744
2724
 
2745
- Mapping describing a pooling operation inserted after a given export-layer index.
2725
+ One dimension inside an ONNX tensor shape.
2746
2726
 
2747
- This is represented as metadata and optional graph nodes during export.
2748
- Import uses it to attach pooling-related runtime metadata back onto the reconstructed
2749
- network (when supported).
2727
+ Use `dim_value` for fixed numeric widths and `dim_param` for symbolic names
2728
+ such as a batch dimension.
2750
2729
 
2751
- ### ActivationSquashFunction
2730
+ ### OnnxExportOptions
2752
2731
 
2753
- ```ts
2754
- ActivationSquashFunction(
2755
- x: number,
2756
- derivate: boolean | undefined,
2757
- ): number
2758
- ```
2732
+ Options controlling ONNX-like export.
2759
2733
 
2760
- Activation function signature used by ONNX layer emission helpers.
2734
+ These options trade off strictness, portability, and fidelity:
2761
2735
 
2762
- ### ConvKernelConsistencyContext
2736
+ - **Strict (default-ish)** export tries to keep the graph easy to interpret:
2737
+ layered topology, homogeneous activations per layer, and fully-connected layers.
2763
2738
 
2764
- Context for kernel-coordinate consistency checks at one output position.
2739
+ - **Relaxed** export (`allowPartialConnectivity` / `allowMixedActivations`) can represent
2740
+ more networks, but it may generate graphs that are primarily meant for NeatapticTS’s
2741
+ importer (and may be less friendly to external ONNX tooling).
2765
2742
 
2766
- ### ConvLayerPairContext
2743
+ - **Recurrent export** (`allowRecurrent`) is intentionally conservative and currently
2744
+ focuses on a constrained single-step representation and optional fused heuristics.
2745
+
2746
+ Key fields (high-level):
2747
+ - `includeMetadata`: includes `metadata_props` with architecture hints.
2748
+ - `opset`: numeric opset version stored in the exported model metadata (default is
2749
+ resolved by the exporter; commonly 18 in this codebase).
2750
+ - `legacyNodeOrdering`: keeps older node ordering for backward compatibility.
2751
+ - `conv2dMappings` / `pool2dMappings`: encode conv/pool semantics for fully-connected
2752
+ layers via explicit mapping declarations.
2767
2753
 
2768
- Context for one resolved Conv mapping layer pair.
2754
+ ### OnnxFusedGateApplicationContext
2769
2755
 
2770
- ### ConvOutputCoordinate
2756
+ Gate-weight application context for one reconstructed fused layer.
2771
2757
 
2772
- Coordinate for one Conv output neuron position.
2758
+ ### OnnxFusedGateRowAssignmentContext
2773
2759
 
2774
- ### ConvRepresentativeKernelContext
2760
+ Context for assigning one gate-neuron row from flattened ONNX tensors.
2775
2761
 
2776
- Context for representative Conv kernel collection per output channel.
2762
+ ### OnnxFusedLayerNeighborhood
2777
2763
 
2778
- ### ConvSharingValidationContext
2764
+ Hidden-layer neighborhood slices around a reconstructed fused layer.
2779
2765
 
2780
- Context for validating Conv sharing across all declared mappings.
2766
+ ### OnnxFusedLayerReconstructionContext
2781
2767
 
2782
- ### ConvSharingValidationResult
2768
+ Execution context for one fused recurrent layer reconstruction.
2783
2769
 
2784
- Result of Conv sharing validation across declared mappings.
2770
+ ### OnnxFusedLayerRuntime
2785
2771
 
2786
- ### DenseActivationContext
2772
+ Runtime interface of a reconstructed fused recurrent layer instance.
2787
2773
 
2788
- Dense activation emission context.
2774
+ The importer only relies on a narrow runtime contract: access to the
2775
+ reconstructed nodes, an input wiring hook, and an optional output group that
2776
+ can be reconnected to the next restored layer.
2789
2777
 
2790
- ### DenseActivationNodePayload
2778
+ ### OnnxFusedRecurrentKind
2791
2779
 
2792
- Strongly typed activation node payload used by dense export helpers.
2780
+ Supported fused recurrent operator families recognized during ONNX import.
2793
2781
 
2794
- ### DenseGemmNodePayload
2782
+ ### OnnxFusedRecurrentSpec
2795
2783
 
2796
- Strongly typed Gemm node payload used by dense export helpers.
2784
+ Fused recurrent family specification used during import reconstruction.
2797
2785
 
2798
- ### DenseGraphNames
2786
+ This tells the importer how to interpret one emitted ONNX recurrent family:
2787
+ how many gates to expect, what order those gates were serialized in, and
2788
+ which gate owns the self-recurrent diagonal replay.
2799
2789
 
2800
- Dense graph tensor names.
2790
+ ### OnnxFusedTensorPayload
2801
2791
 
2802
- ### DenseInitializerValues
2792
+ Fused recurrent tensor payload read from ONNX initializers.
2803
2793
 
2804
- Dense initializer value arrays.
2794
+ The importer resolves the three recurrent tensor families up front so the
2795
+ reconstruction pass can focus on wiring and row assignment instead of
2796
+ repeatedly re-looking up initializers.
2805
2797
 
2806
- ### DenseLayerContext
2798
+ ### OnnxGraph
2807
2799
 
2808
- Dense layer context enriched with resolved activation function.
2800
+ Graph body of an ONNX-like model.
2809
2801
 
2810
- ### DenseLayerParams
2802
+ The exporter writes three main collections here:
2803
+ - `inputs` and `outputs` describe graph boundaries,
2804
+ - `initializer` stores constant tensors such as weights and biases,
2805
+ - `node` stores the ordered operator payloads that consume those tensors.
2811
2806
 
2812
- Parameters for dense layer emission.
2807
+ ### OnnxGraphDimensionBuildContext
2813
2808
 
2814
- ### DenseOrderedNodePayload
2809
+ Context for constructing input/output ONNX graph dimensions.
2815
2810
 
2816
- Dense node payload union used by ordered append helpers.
2811
+ ### OnnxGraphDimensions
2817
2812
 
2818
- ### DenseTensorNames
2813
+ Output dimensions used by ONNX graph input/output value info payloads.
2819
2814
 
2820
- Dense initializer tensor names.
2815
+ ### OnnxImportAggregatedLayerAssignmentContext
2821
2816
 
2822
- ### DenseWeightBuildContext
2817
+ Context for assigning aggregated dense tensors for one layer.
2823
2818
 
2824
- Context for building dense layer initializers from two adjacent layers.
2819
+ ### OnnxImportAggregatedNeuronAssignmentContext
2825
2820
 
2826
- ### DenseWeightBuildResult
2821
+ Context for assigning one aggregated dense target neuron row.
2827
2822
 
2828
- Dense layer initializer fold output.
2823
+ ### OnnxImportArchitectureContext
2829
2824
 
2830
- ### DenseWeightRow
2825
+ Shared architecture extraction context with resolved graph dimensions.
2831
2826
 
2832
- One collected dense row before fold to flattened initializers.
2827
+ ### OnnxImportArchitectureResult
2833
2828
 
2834
- ### DenseWeightRowCollectionContext
2829
+ Parsed architecture dimensions extracted from ONNX import graph payloads.
2835
2830
 
2836
- Context for collecting one dense row.
2831
+ ### OnnxImportConvCoordinateAssignmentContext
2837
2832
 
2838
- ### DiagonalRecurrentBuildContext
2833
+ Context for applying Conv weights and bias at one output coordinate.
2839
2834
 
2840
- Context for building a diagonal recurrent matrix from self-connections.
2835
+ ### OnnxImportConvKernelAssignmentContext
2841
2836
 
2842
- ### FlattenAfterPoolingContext
2837
+ Context for assigning one concrete Conv kernel connection weight.
2843
2838
 
2844
- Flatten emission context after optional pooling.
2839
+ ### OnnxImportConvLayerContext
2845
2840
 
2846
- ### FusedRecurrentEmissionExecutionContext
2841
+ Context for reconstructing one Conv layer's imported connectivity.
2847
2842
 
2848
- Shared execution context for emitting one fused recurrent layer payload.
2843
+ ### OnnxImportConvLayerContextBuildParams
2849
2844
 
2850
- ### FusedRecurrentGraphNames
2845
+ Build params for creating one Conv reconstruction layer context.
2851
2846
 
2852
- Context for ONNX fused recurrent node payload names.
2847
+ ### OnnxImportConvMetadata
2853
2848
 
2854
- ### FusedRecurrentInitializerNames
2849
+ Parsed Conv metadata payload used for optional reconstruction pass.
2855
2850
 
2856
- Context for ONNX fused recurrent initializer names.
2851
+ ### OnnxImportConvNodeSlices
2857
2852
 
2858
- ### GruEmissionContext
2853
+ Layer node slices used while applying Conv reconstruction assignments.
2859
2854
 
2860
- Context for heuristic GRU emission when a layer matches expected shape.
2855
+ ### OnnxImportConvOutputCoordinate
2861
2856
 
2862
- ### HiddenLayerHeuristicContext
2857
+ Coordinate for one Conv output neuron traversal position.
2863
2858
 
2864
- Context for one hidden layer during heuristic recurrent emission.
2859
+ ### OnnxImportConvTensorContext
2865
2860
 
2866
- ### IndexedMetadataAppendContext
2861
+ Resolved Conv initializer tensors and dimensions for one layer.
2867
2862
 
2868
- Append-an-index metadata context for JSON-array metadata keys.
2863
+ ### OnnxImportDimensionRecord
2869
2864
 
2870
- ### LayerActivationContext
2865
+ Loose ONNX shape-dimension record used by legacy import payload access.
2871
2866
 
2872
- Activation analysis context for one layer.
2867
+ ### OnnxImportHiddenLayerSpan
2873
2868
 
2874
- ### LayerBuildContext
2869
+ Hidden-layer span payload with one-based layer numbering and global offset.
2875
2870
 
2876
- Layer build context used while emitting one ONNX graph layer segment.
2871
+ ### OnnxImportHiddenSizeDerivationContext
2877
2872
 
2878
- ### LayerRecurrentDecisionContext
2873
+ Context for deriving hidden layer sizes from initializer tensors and metadata.
2879
2874
 
2880
- Context used to decide recurrent emission branch usage.
2875
+ ### OnnxImportInboundConnectionMap
2881
2876
 
2882
- ### LayerTraversalContext
2877
+ Inbound connection lookup map keyed by source node for one target neuron.
2883
2878
 
2884
- Layer traversal context with adjacent layers and output classification.
2879
+ ### OnnxImportLayerConnectionContext
2885
2880
 
2886
- ### LstmEmissionContext
2881
+ Execution context for assigning one hidden-layer recurrent diagonal tensor.
2887
2882
 
2888
- Context for heuristic LSTM emission when a layer matches expected shape.
2883
+ ### OnnxImportLayerNodePair
2889
2884
 
2890
- ### OnnxBaseModelBuildContext
2885
+ Node slices for one sequential imported layer assignment pass.
2891
2886
 
2892
- Context for constructing a base ONNX model shell.
2887
+ ### OnnxImportLayerNodePairBuildParams
2893
2888
 
2894
- ### OnnxBuildResolvedOptions
2889
+ Build params for one sequential layer node-pair slice operation.
2895
2890
 
2896
- Resolved options used by ONNX model build orchestration.
2891
+ ### OnnxImportLayerTensorNames
2897
2892
 
2898
- ### OnnxConvEmissionContext
2893
+ Weight tensor names for one imported layer index.
2899
2894
 
2900
- Context used after resolving Conv mapping for one layer.
2895
+ ### OnnxImportLayerWeightBucket
2901
2896
 
2902
- ### OnnxConvEmissionParams
2897
+ Bucketed ONNX dense/per-neuron tensors for one exported layer index.
2903
2898
 
2904
- Parameters accepted by Conv layer emission.
2899
+ ### OnnxImportPerNeuronAssignmentContext
2905
2900
 
2906
- ### OnnxConvParameters
2901
+ Context for assigning one per-neuron imported target node.
2907
2902
 
2908
- Flattened Conv parameters for ONNX initializers.
2903
+ ### OnnxImportPerNeuronLayerAssignmentContext
2909
2904
 
2910
- ### OnnxConvTensorNames
2905
+ Context for assigning per-neuron tensors for one layer.
2911
2906
 
2912
- Tensor names generated for Conv parameters.
2907
+ ### OnnxImportPoolingMetadata
2913
2908
 
2914
- ### OnnxExportOptions
2909
+ Parsed pooling metadata payload attached to imported network instances.
2915
2910
 
2916
- Options controlling ONNX-like export.
2911
+ ### OnnxImportRecurrentRestorationContext
2917
2912
 
2918
- These options trade off strictness, portability, and fidelity:
2913
+ Context for recurrent self-connection restoration from ONNX metadata and tensors.
2919
2914
 
2920
- - **Strict (default-ish)** export tries to keep the graph easy to interpret:
2921
- layered topology, homogeneous activations per layer, and fully-connected layers.
2915
+ ### OnnxImportSelfConnectionUpsertContext
2922
2916
 
2923
- - **Relaxed** export (`allowPartialConnectivity` / `allowMixedActivations`) can represent
2924
- more networks, but it may generate graphs that are primarily meant for NeatapticTS’s
2925
- importer (and may be less friendly to external ONNX tooling).
2917
+ Context for upserting one hidden node self-connection from recurrent weight.
2926
2918
 
2927
- - **Recurrent export** (`allowRecurrent`) is intentionally conservative and currently
2928
- focuses on a constrained single-step representation and optional fused heuristics.
2919
+ ### OnnxImportWeightAssignmentBuildParams
2929
2920
 
2930
- Key fields (high-level):
2931
- - `includeMetadata`: includes `metadata_props` with architecture hints.
2932
- - `opset`: numeric opset version stored in the exported model metadata (default is
2933
- resolved by the exporter; commonly 18 in this codebase).
2934
- - `legacyNodeOrdering`: keeps older node ordering for backward compatibility.
2935
- - `conv2dMappings` / `pool2dMappings`: encode conv/pool semantics for fully-connected
2936
- layers via explicit mapping declarations.
2921
+ Build params for creating shared ONNX import weight-assignment context.
2937
2922
 
2938
- ### OnnxGraphDimensionBuildContext
2923
+ ### OnnxImportWeightAssignmentContext
2939
2924
 
2940
- Context for constructing input/output ONNX graph dimensions.
2925
+ Shared weight-assignment context built once per ONNX import.
2941
2926
 
2942
- ### OnnxGraphDimensions
2927
+ ### OnnxIncomingWeightAssignmentContext
2943
2928
 
2944
- Output dimensions used by ONNX graph input/output value info payloads.
2929
+ Context for assigning dense incoming weights for one gate-neuron row.
2945
2930
 
2946
2931
  ### OnnxLayerEmissionContext
2947
2932
 
@@ -2951,526 +2936,541 @@ Context for emitting non-input layers during model build.
2951
2936
 
2952
2937
  Result of emitting non-input export layers.
2953
2938
 
2954
- ### OnnxModelMetadataContext
2955
-
2956
- Context for applying optional ONNX model metadata.
2957
-
2958
- ### OnnxPostProcessingContext
2959
-
2960
- Context for post-processing and export metadata finalization.
2961
-
2962
- ### OnnxRecurrentCollectionContext
2963
-
2964
- Context for collecting recurrent layer indices during model build.
2965
-
2966
- ### OnnxRecurrentInputValueInfoContext
2939
+ ### OnnxLayerFactory
2967
2940
 
2968
- Context for constructing one recurrent previous-state graph input payload.
2941
+ Runtime factory map used to construct dynamic recurrent layer modules.
2969
2942
 
2970
- ### OnnxRecurrentLayerProcessingContext
2943
+ ### OnnxMetadataProperty
2971
2944
 
2972
- Execution context for processing one hidden recurrent layer.
2945
+ Canonical metadata key-value pair used in ONNX model metadata_props.
2973
2946
 
2974
- ### OnnxRecurrentLayerTraversalContext
2947
+ ### OnnxModel
2975
2948
 
2976
- Traversal context for one hidden layer during recurrent-input collection.
2949
+ ONNX-like model container (JSON-serializable).
2977
2950
 
2978
- ### OptionalLayerOutputParams
2951
+ This is the main “wire format” object in this folder. Persist it as JSON text:
2979
2952
 
2980
- Shared parameters for optional pooling/flatten output emission.
2953
+ ```ts
2954
+ const jsonText = JSON.stringify(model);
2955
+ const restoredModel = JSON.parse(jsonText) as OnnxModel;
2956
+ ```
2981
2957
 
2982
- ### OptionalPoolingAndFlattenParams
2958
+ Notes:
2959
+ - `metadata_props` contains NeatapticTS-specific keys (layer sizes, recurrent flags,
2960
+ conv/pool mappings, etc.). This is where most round-trip hints live.
2961
+ - Initializers currently store floating-point weights in `float_data`.
2983
2962
 
2984
- Parameters for optional pooling + flatten emission after a layer output.
2963
+ Security/trust boundary:
2964
+ - Treat this as untrusted input if it comes from outside your process.
2985
2965
 
2986
- ### PerNeuronConcatNodePayload
2966
+ ### OnnxModelMetadataContext
2987
2967
 
2988
- Per-neuron concat node payload.
2968
+ Context for applying optional ONNX model metadata.
2989
2969
 
2990
- ### PerNeuronGraphNames
2970
+ ### OnnxNode
2991
2971
 
2992
- Per-neuron graph tensor names.
2972
+ One ONNX operator invocation inside the graph.
2993
2973
 
2994
- ### PerNeuronLayerContext
2974
+ Nodes connect named tensors rather than object references, which keeps the
2975
+ exported payload easy to serialize, inspect, and diff as plain JSON.
2995
2976
 
2996
- Per-neuron layer context alias.
2977
+ ### OnnxPerceptronBuildContext
2997
2978
 
2998
- ### PerNeuronLayerParams
2979
+ Build context for mapping ONNX layer sizes into a Neataptic MLP factory call.
2999
2980
 
3000
- Parameters for per-neuron layer emission.
2981
+ ### OnnxPerceptronSizeValidationContext
3001
2982
 
3002
- ### PerNeuronNodeContext
2983
+ Validation context for perceptron size-list checks during ONNX import.
3003
2984
 
3004
- Per-neuron normalized node context.
2985
+ ### OnnxPostProcessingContext
3005
2986
 
3006
- ### PerNeuronSubgraphContext
2987
+ Context for post-processing and export metadata finalization.
3007
2988
 
3008
- Per-neuron subgraph emission context.
2989
+ ### OnnxRecurrentCollectionContext
3009
2990
 
3010
- ### PerNeuronTensorNames
2991
+ Context for collecting recurrent layer indices during model build.
3011
2992
 
3012
- Per-neuron initializer tensor names.
2993
+ ### OnnxRecurrentInputValueInfoContext
3013
2994
 
3014
- ### PoolingAttributes
2995
+ Context for constructing one recurrent previous-state graph input payload.
3015
2996
 
3016
- Pooling tensor attributes for ONNX node payloads.
2997
+ ### OnnxRecurrentLayerProcessingContext
3017
2998
 
3018
- ### PoolingEmissionContext
2999
+ Execution context for processing one hidden recurrent layer.
3019
3000
 
3020
- Pooling emission context resolved for one layer output.
3001
+ ### OnnxRecurrentLayerTraversalContext
3021
3002
 
3022
- ### RecurrentActivationEmissionContext
3003
+ Traversal context for one hidden layer during recurrent-input collection.
3023
3004
 
3024
- Context for selecting and emitting recurrent activation node payload.
3005
+ ### OnnxRuntimeFactories
3025
3006
 
3026
- ### RecurrentGateBlockCollectionContext
3007
+ Runtime factories consumed during ONNX import network reconstruction.
3027
3008
 
3028
- Context for collecting one gate parameter block.
3009
+ ### OnnxRuntimeLayerFactory
3029
3010
 
3030
- ### RecurrentGateParameterCollectionResult
3011
+ ```ts
3012
+ OnnxRuntimeLayerFactory(
3013
+ size: number,
3014
+ ): default
3015
+ ```
3031
3016
 
3032
- Flattened recurrent gate parameter vectors for one fused operator.
3017
+ Runtime layer-constructor signature used for recurrent layer reconstruction.
3033
3018
 
3034
- ### RecurrentGateRow
3019
+ ### OnnxRuntimeLayerFactoryMap
3035
3020
 
3036
- One recurrent gate row payload before flatten fold.
3021
+ Runtime layer module shape widened for fused-recurrent reconstruction wiring.
3037
3022
 
3038
- ### RecurrentGateRowCollectionContext
3023
+ ### OnnxRuntimeLayerModule
3039
3024
 
3040
- Context for collecting one recurrent gate row (one neuron).
3025
+ Runtime layer module shape consumed by ONNX import orchestration.
3041
3026
 
3042
- ### RecurrentGemmEmissionContext
3027
+ ### OnnxRuntimePerceptronFactory
3043
3028
 
3044
- Context for emitting one Gemm node for recurrent single-step export.
3029
+ ```ts
3030
+ OnnxRuntimePerceptronFactory(
3031
+ sizes: number[],
3032
+ ): default
3033
+ ```
3045
3034
 
3046
- ### RecurrentGraphNames
3035
+ Runtime perceptron factory signature used by ONNX import orchestration.
3047
3036
 
3048
- Derived graph names for one recurrent single-step layer payload.
3037
+ ### OnnxShape
3049
3038
 
3050
- ### RecurrentHeuristicEmissionContext
3039
+ ONNX tensor type shape.
3051
3040
 
3052
- Context for heuristic recurrent operator emission traversal.
3041
+ ### OnnxTensor
3053
3042
 
3054
- ### RecurrentInitializerEmissionContext
3043
+ Serialized tensor payload stored inside graph initializers.
3055
3044
 
3056
- Context for pushing recurrent initializers into ONNX graph state.
3045
+ NeatapticTS currently writes floating-point parameter vectors and matrices to
3046
+ `float_data`, along with the tensor name, element type, and logical shape.
3057
3047
 
3058
- ### RecurrentInitializerNames
3048
+ ### OnnxTensorType
3059
3049
 
3060
- Initializer tensor names for one single-step recurrent layer.
3050
+ ONNX tensor type.
3061
3051
 
3062
- ### RecurrentInitializerValues
3052
+ ### OnnxValueInfo
3063
3053
 
3064
- Collected initializer vectors for one single-step recurrent layer.
3054
+ ONNX value info (input/output description).
3065
3055
 
3066
- ### RecurrentLayerEmissionContext
3056
+ ### OptimizerConfigBase
3067
3057
 
3068
- Derived execution context for single-step recurrent layer emission.
3058
+ Base optimizer configuration.
3069
3059
 
3070
- ### RecurrentLayerEmissionParams
3060
+ Training accepts either an optimizer name (`"adam"`, `"sgd"`, ...) or an object.
3061
+ This object form is useful when you want to pin numeric hyperparameters or wrap a base
3062
+ optimizer (e.g. lookahead).
3071
3063
 
3072
- Parameters for single-step recurrent layer emission.
3064
+ Example:
3073
3065
 
3074
- ### RecurrentRowCollectionContext
3066
+ ```ts
3067
+ net.train(set, {
3068
+ iterations: 1_000,
3069
+ rate: 0.001,
3070
+ optimizer: { type: 'adamw', beta1: 0.9, beta2: 0.999, eps: 1e-8, weightDecay: 0.01 },
3071
+ });
3072
+ ```
3075
3073
 
3076
- Context for collecting one recurrent matrix row.
3074
+ Notes:
3075
+ - Exact supported `type` values are validated by training utilities.
3076
+ - Unspecified fields fall back to sensible defaults per optimizer.
3077
3077
 
3078
- ### SharedActivationNodeBuildParams
3078
+ ### OptionalLayerOutputParams
3079
3079
 
3080
- Shared parameters for constructing an activation node payload.
3080
+ Shared parameters for optional pooling/flatten output emission.
3081
3081
 
3082
- ### SharedGemmNodeBuildParams
3082
+ ### OptionalPoolingAndFlattenParams
3083
3083
 
3084
- Shared parameters for constructing a Gemm node payload.
3084
+ Parameters for optional pooling + flatten emission after a layer output.
3085
3085
 
3086
- ### SpecMetadataAppendContext
3086
+ ### OutgoingOrderBuildContext
3087
3087
 
3088
- Append-a-spec metadata context for JSON-array metadata keys.
3088
+ Context for constructing source-grouped outgoing connection order.
3089
3089
 
3090
- ### WeightToleranceComparisonContext
3090
+ ### OutputLayerActivationContext
3091
3091
 
3092
- Context for comparing two scalar weights with numeric tolerance.
3092
+ Output-layer activation assignment context.
3093
3093
 
3094
- ### NetworkWithOnnxImportPooling
3094
+ ### Parent1GeneTraversalContext
3095
3095
 
3096
- Network instance augmented with optional imported ONNX pooling metadata.
3096
+ Traversal state for parent-1 innovation walk.
3097
3097
 
3098
- ### OnnxImportArchitectureContext
3098
+ ### Parent1TraversalSelectionResult
3099
3099
 
3100
- Shared architecture extraction context with resolved graph dimensions.
3100
+ Fold result for parent-1 traversal selection.
3101
3101
 
3102
- ### OnnxImportArchitectureResult
3102
+ ### ParentMetrics
3103
3103
 
3104
- Parsed architecture dimensions extracted from ONNX import graph payloads.
3104
+ Compact parent metrics summary.
3105
3105
 
3106
- ### OnnxImportDimensionRecord
3106
+ ### PathSearchContext
3107
3107
 
3108
- Loose ONNX shape-dimension record used by legacy import payload access.
3108
+ Mutable context used while running iterative path search.
3109
3109
 
3110
- ### OnnxImportHiddenLayerSpan
3110
+ ### PerNeuronConcatNodePayload
3111
3111
 
3112
- Hidden-layer span payload with one-based layer numbering and global offset.
3112
+ Per-neuron concat node payload.
3113
3113
 
3114
- ### OnnxImportLayerConnectionContext
3114
+ ### PerNeuronGraphNames
3115
3115
 
3116
- Execution context for assigning one hidden-layer recurrent diagonal tensor.
3116
+ Per-neuron graph tensor names.
3117
3117
 
3118
- ### OnnxImportPoolingMetadata
3118
+ ### PerNeuronLayerContext
3119
3119
 
3120
- Parsed pooling metadata payload attached to imported network instances.
3120
+ Per-neuron layer context alias.
3121
3121
 
3122
- ### OnnxImportRecurrentRestorationContext
3122
+ ### PerNeuronLayerParams
3123
3123
 
3124
- Context for recurrent self-connection restoration from ONNX metadata and tensors.
3124
+ Parameters for per-neuron layer emission.
3125
3125
 
3126
- ### OnnxImportSelfConnectionUpsertContext
3126
+ ### PerNeuronNodeContext
3127
3127
 
3128
- Context for upserting one hidden node self-connection from recurrent weight.
3128
+ Per-neuron normalized node context.
3129
3129
 
3130
- ### OnnxImportAggregatedLayerAssignmentContext
3130
+ ### PerNeuronSubgraphContext
3131
3131
 
3132
- Context for assigning aggregated dense tensors for one layer.
3132
+ Per-neuron subgraph emission context.
3133
3133
 
3134
- ### OnnxImportAggregatedNeuronAssignmentContext
3134
+ ### PerNeuronTensorNames
3135
3135
 
3136
- Context for assigning one aggregated dense target neuron row.
3136
+ Per-neuron initializer tensor names.
3137
3137
 
3138
- ### OnnxImportConvCoordinateAssignmentContext
3138
+ ### PlateauSmoothingConfig
3139
3139
 
3140
- Context for applying Conv weights and bias at one output coordinate.
3140
+ Config for plateau smoothing computation.
3141
3141
 
3142
- ### OnnxImportConvKernelAssignmentContext
3142
+ ### PlateauSmoothingState
3143
3143
 
3144
- Context for assigning one concrete Conv kernel connection weight.
3144
+ Mutable smoothing state for plateau metric.
3145
3145
 
3146
- ### OnnxImportConvLayerContext
3146
+ ### Pool2DMapping
3147
3147
 
3148
- Context for reconstructing one Conv layer's imported connectivity.
3148
+ Mapping describing a pooling operation inserted after a given export-layer index.
3149
3149
 
3150
- ### OnnxImportConvLayerContextBuildParams
3150
+ This is represented as metadata and optional graph nodes during export.
3151
+ Import uses it to attach pooling-related runtime metadata back onto the reconstructed
3152
+ network (when supported).
3151
3153
 
3152
- Build params for creating one Conv reconstruction layer context.
3154
+ ### PoolingAttributes
3153
3155
 
3154
- ### OnnxImportConvMetadata
3156
+ Pooling tensor attributes for ONNX node payloads.
3155
3157
 
3156
- Parsed Conv metadata payload used for optional reconstruction pass.
3158
+ ### PoolingEmissionContext
3157
3159
 
3158
- ### OnnxImportConvNodeSlices
3160
+ Pooling emission context resolved for one layer output.
3159
3161
 
3160
- Layer node slices used while applying Conv reconstruction assignments.
3162
+ ### PoolKeyMetrics
3161
3163
 
3162
- ### OnnxImportConvOutputCoordinate
3164
+ Per-pool-key allocation & reuse counters (educational / diagnostics).
3163
3165
 
3164
- Coordinate for one Conv output neuron traversal position.
3166
+ ### PopulationFitnessFunction
3165
3167
 
3166
- ### OnnxImportConvTensorContext
3168
+ ```ts
3169
+ PopulationFitnessFunction(
3170
+ population: default[],
3171
+ ): Promise<void>
3172
+ ```
3167
3173
 
3168
- Resolved Conv initializer tensors and dimensions for one layer.
3174
+ Fitness signature evaluating full population asynchronously.
3169
3175
 
3170
- ### OnnxImportHiddenSizeDerivationContext
3176
+ ### PopulationWorkerEvaluationContext
3171
3177
 
3172
- Context for deriving hidden layer sizes from initializer tensors and metadata.
3178
+ Shared context for one population worker evaluation run.
3173
3179
 
3174
- ### OnnxImportInboundConnectionMap
3180
+ ### PrimarySmoothingState
3175
3181
 
3176
- Inbound connection lookup map keyed by source node for one target neuron.
3182
+ Mutable smoothing state for monitored error.
3177
3183
 
3178
- ### OnnxImportLayerNodePair
3184
+ ### PruneSelectionContext
3179
3185
 
3180
- Node slices for one sequential imported layer assignment pass.
3186
+ Context for selecting prune candidates.
3181
3187
 
3182
- ### OnnxImportLayerNodePairBuildParams
3188
+ ### PruneSelectionResult
3183
3189
 
3184
- Build params for one sequential layer node-pair slice operation.
3190
+ Result of prune candidate selection.
3185
3191
 
3186
- ### OnnxImportLayerTensorNames
3192
+ ### PruningMethod
3187
3193
 
3188
- Weight tensor names for one imported layer index.
3194
+ Pruning strategy identifiers.
3189
3195
 
3190
- ### OnnxImportLayerWeightBucket
3196
+ ### PublishAdjacencyContext
3191
3197
 
3192
- Bucketed ONNX dense/per-neuron tensors for one exported layer index.
3198
+ Context for publishing fully built adjacency slabs to internal network state.
3193
3199
 
3194
- ### OnnxImportPerNeuronAssignmentContext
3200
+ ### ReconnectEndpointPairContext
3195
3201
 
3196
- Context for assigning one per-neuron imported target node.
3202
+ Endpoint pair for reconnecting bridged paths.
3197
3203
 
3198
- ### OnnxImportPerNeuronLayerAssignmentContext
3204
+ ### RecurrentActivationEmissionContext
3199
3205
 
3200
- Context for assigning per-neuron tensors for one layer.
3206
+ Context for selecting and emitting recurrent activation node payload.
3201
3207
 
3202
- ### OnnxImportWeightAssignmentBuildParams
3208
+ ### RecurrentGateBlockCollectionContext
3203
3209
 
3204
- Build params for creating shared ONNX import weight-assignment context.
3210
+ Context for collecting one gate parameter block.
3205
3211
 
3206
- ### OnnxImportWeightAssignmentContext
3212
+ ### RecurrentGateParameterCollectionResult
3207
3213
 
3208
- Shared weight-assignment context built once per ONNX import.
3214
+ Flattened recurrent gate parameter vectors for one fused operator.
3209
3215
 
3210
- ### OnnxFusedGateApplicationContext
3216
+ ### RecurrentGateRow
3211
3217
 
3212
- Gate-weight application context for one reconstructed fused layer.
3218
+ One recurrent gate row payload before flatten fold.
3213
3219
 
3214
- ### OnnxFusedGateRowAssignmentContext
3220
+ ### RecurrentGateRowCollectionContext
3215
3221
 
3216
- Context for assigning one gate-neuron row from flattened ONNX tensors.
3222
+ Context for collecting one recurrent gate row (one neuron).
3217
3223
 
3218
- ### OnnxFusedLayerNeighborhood
3224
+ ### RecurrentGemmEmissionContext
3219
3225
 
3220
- Hidden-layer neighborhood slices around a reconstructed fused layer.
3226
+ Context for emitting one Gemm node for recurrent single-step export.
3221
3227
 
3222
- ### OnnxFusedLayerReconstructionContext
3228
+ ### RecurrentGraphNames
3223
3229
 
3224
- Execution context for one fused recurrent layer reconstruction.
3230
+ Derived graph names for one recurrent single-step layer payload.
3225
3231
 
3226
- ### OnnxFusedLayerRuntime
3232
+ ### RecurrentHeuristicEmissionContext
3227
3233
 
3228
- Runtime interface of a reconstructed fused recurrent layer instance.
3234
+ Context for heuristic recurrent operator emission traversal.
3229
3235
 
3230
- The importer only relies on a narrow runtime contract: access to the
3231
- reconstructed nodes, an input wiring hook, and an optional output group that
3232
- can be reconnected to the next restored layer.
3236
+ ### RecurrentInitializerEmissionContext
3233
3237
 
3234
- ### OnnxFusedRecurrentKind
3238
+ Context for pushing recurrent initializers into ONNX graph state.
3235
3239
 
3236
- Supported fused recurrent operator families recognized during ONNX import.
3240
+ ### RecurrentInitializerNames
3237
3241
 
3238
- ### OnnxFusedRecurrentSpec
3242
+ Initializer tensor names for one single-step recurrent layer.
3239
3243
 
3240
- Fused recurrent family specification used during import reconstruction.
3244
+ ### RecurrentInitializerValues
3241
3245
 
3242
- This tells the importer how to interpret one emitted ONNX recurrent family:
3243
- how many gates to expect, what order those gates were serialized in, and
3244
- which gate owns the self-recurrent diagonal replay.
3246
+ Collected initializer vectors for one single-step recurrent layer.
3245
3247
 
3246
- ### OnnxFusedTensorPayload
3248
+ ### RecurrentLayerEmissionContext
3247
3249
 
3248
- Fused recurrent tensor payload read from ONNX initializers.
3250
+ Derived execution context for single-step recurrent layer emission.
3249
3251
 
3250
- The importer resolves the three recurrent tensor families up front so the
3251
- reconstruction pass can focus on wiring and row assignment instead of
3252
- repeatedly re-looking up initializers.
3252
+ ### RecurrentLayerEmissionParams
3253
3253
 
3254
- ### OnnxIncomingWeightAssignmentContext
3254
+ Parameters for single-step recurrent layer emission.
3255
3255
 
3256
- Context for assigning dense incoming weights for one gate-neuron row.
3256
+ ### RecurrentLayerShape
3257
3257
 
3258
- ### OnnxPerceptronBuildContext
3258
+ Minimal recurrent-layer shape used by mutation expanders.
3259
3259
 
3260
- Build context for mapping ONNX layer sizes into a Neataptic MLP factory call.
3260
+ ### RecurrentRowCollectionContext
3261
3261
 
3262
- ### OnnxPerceptronSizeValidationContext
3262
+ Context for collecting one recurrent matrix row.
3263
3263
 
3264
- Validation context for perceptron size-list checks during ONNX import.
3264
+ ### RegrowthExecutionContext
3265
3265
 
3266
- ### OnnxRuntimeFactories
3266
+ Context for regrowth execution routine.
3267
3267
 
3268
- Runtime factories consumed during ONNX import network reconstruction.
3268
+ ### RegrowthPlan
3269
3269
 
3270
- ### OnnxRuntimeLayerFactory
3270
+ Derived regrowth execution plan.
3271
3271
 
3272
- ```ts
3273
- OnnxRuntimeLayerFactory(
3274
- size: number,
3275
- ): default
3276
- ```
3272
+ ### RegrowthPlanContext
3277
3273
 
3278
- Runtime layer-constructor signature used for recurrent layer reconstruction.
3274
+ Context for deriving regrowth plan.
3279
3275
 
3280
- ### OnnxRuntimeLayerModule
3276
+ ### RegularizationConfig
3281
3277
 
3282
- Runtime layer module shape consumed by ONNX import orchestration.
3278
+ L1/L2 regularization configuration.
3283
3279
 
3284
- ### OnnxRuntimePerceptronFactory
3280
+ ### ResolvedNetworkSizeContext
3285
3281
 
3286
- ```ts
3287
- OnnxRuntimePerceptronFactory(
3288
- sizes: number[],
3289
- ): default
3290
- ```
3282
+ Resolved input/output sizes for rebuild.
3291
3283
 
3292
- Runtime perceptron factory signature used by ONNX import orchestration.
3284
+ Values reflect override-first resolution semantics used during deserialization.
3293
3285
 
3294
- ### NodeInternals
3286
+ ### RNGSnapshot
3295
3287
 
3296
- Runtime interface for accessing node internal properties.
3288
+ Snapshot payload for RNG state restore flows.
3297
3289
 
3298
- This is intentionally "internal": it exposes mutable fields that the ONNX exporter/importer
3299
- needs (connections, bias, squash). Regular library users should generally interact with
3300
- the public `Node` API instead.
3290
+ ### ScheduleConfig
3301
3291
 
3302
- ### NodeInternalsWithExportIndex
3292
+ Schedule callback configuration.
3303
3293
 
3304
- Runtime node internals augmented with optional export index metadata.
3294
+ A schedule callback is a simple "tick hook" that runs every N iterations.
3295
+ Typical uses include logging, custom learning-rate schedules, or diagnostics.
3305
3296
 
3306
- ### ActivationFunction
3297
+ ### ScheduledTargetContext
3307
3298
 
3308
- ```ts
3309
- ActivationFunction(
3310
- x: number,
3311
- derivate: boolean | undefined,
3312
- ): number
3313
- ```
3299
+ Context for scheduled-pruning target computation.
3314
3300
 
3315
- Runtime activation function signature used by ONNX activation import/export paths.
3301
+ ### ScheduledTargetResult
3316
3302
 
3317
- Neataptic-style activations support a dual-purpose call pattern:
3318
- - `derivate === false | undefined`: return activation output $f(x)$
3319
- - `derivate === true`: return derivative $f'(x)$
3303
+ Result of scheduled-pruning target computation.
3320
3304
 
3321
- This matches historical Neataptic semantics and keeps ONNX import/export compatible.
3305
+ ### SerializedConnection
3322
3306
 
3323
- Example:
3307
+ Serialized connection representation used by compact and JSON formats.
3324
3308
 
3325
- ```ts
3326
- const y = activation(x);
3327
- const dy = activation(x, true);
3328
- ```
3309
+ Endpoints are canonical node indices, which keeps payloads deterministic and language-agnostic.
3329
3310
 
3330
- ### LayerOrderingNodeGroups
3311
+ ### SerializedNetwork
3331
3312
 
3332
- Node partitions used by ONNX layered-ordering inference traversal.
3313
+ Serialized network payload used in checkpoint callbacks.
3333
3314
 
3334
- ### LayerOrderingResolutionContext
3315
+ This is intentionally loose: serialization formats evolve and may include nested
3316
+ structures. Treat this as an opaque snapshot blob.
3335
3317
 
3336
- Mutable traversal state while resolving hidden-layer ordering.
3318
+ ### SerializeNetworkInternals
3337
3319
 
3338
- ### LayerValidationTraversalContext
3320
+ Runtime interface for accessing network internals during serialization.
3339
3321
 
3340
- Layer-wise validation context for activation and connectivity checks.
3322
+ This is an internal bridge type used by serializer helpers to read and rebuild
3323
+ topology without exposing private implementation details in public APIs.
3341
3324
 
3342
- ### LayerActivationValidationContext
3325
+ ### SerializeNodeInternals
3343
3326
 
3344
- Activation-homogeneity decision context for one current layer.
3327
+ Runtime node internals needed for serialization workflows.
3345
3328
 
3346
- ### LayerConnectivityValidationContext
3329
+ These fields are the minimal node state required to round-trip compact and JSON payloads.
3347
3330
 
3348
- Connectivity decision context for one source-target node pair.
3331
+ ### SharedActivationNodeBuildParams
3349
3332
 
3350
- ### OnnxActivationOperation
3333
+ Shared parameters for constructing an activation node payload.
3351
3334
 
3352
- Supported ONNX activation operators recognized during activation import.
3335
+ ### SharedGemmNodeBuildParams
3353
3336
 
3354
- ### OnnxActivationLayerOperations
3337
+ Shared parameters for constructing a Gemm node payload.
3355
3338
 
3356
- Layer-indexed activation operator lookup extracted from ONNX graph nodes.
3339
+ ### SingleGenomeFitnessFunction
3357
3340
 
3358
- ### OnnxActivationParseResult
3341
+ ```ts
3342
+ SingleGenomeFitnessFunction(
3343
+ genome: default,
3344
+ ): number
3345
+ ```
3359
3346
 
3360
- Parsed ONNX activation-node naming payload.
3347
+ Fitness signature evaluating one genome.
3361
3348
 
3362
- ### OnnxActivationAssignmentContext
3349
+ ### SLAB_DEFAULT_ASYNC_CHUNK_SIZE
3363
3350
 
3364
- Shared activation-assignment context for hidden and output traversal.
3351
+ Default async slab rebuild chunk size when no override is provided.
3365
3352
 
3366
- ### HiddenLayerActivationTraversalContext
3353
+ ### SLAB_GROWTH_FACTOR_BROWSER
3367
3354
 
3368
- Hidden-layer traversal context for assigning imported activation functions.
3355
+ Capacity growth factor for browser slab allocations.
3369
3356
 
3370
- ### OutputLayerActivationContext
3357
+ ### SLAB_GROWTH_FACTOR_NODE
3371
3358
 
3372
- Output-layer activation assignment context.
3359
+ Capacity growth factor for Node.js slab allocations.
3373
3360
 
3374
- ### OnnxActivationOperationResolutionContext
3361
+ ### SLAB_ONE
3375
3362
 
3376
- Activation operation resolution context for one neuron or layer default.
3363
+ Numeric one sentinel used for neutral gain defaults and index math.
3377
3364
 
3378
- ### OnnxConvKernelCoordinate
3365
+ ### SLAB_ZERO
3379
3366
 
3380
- Coordinate for one Conv kernel weight lookup.
3367
+ Numeric zero sentinel used across slab orchestration and helper pipelines.
3381
3368
 
3382
- ### OnnxLayerFactory
3369
+ ### SlabBuildContext
3383
3370
 
3384
- Runtime factory map used to construct dynamic recurrent layer modules.
3371
+ Immutable inputs required to build or grow connection slab buffers.
3385
3372
 
3386
- ### OnnxRuntimeLayerFactoryMap
3373
+ ### SlabPopulateResult
3387
3374
 
3388
- Runtime layer module shape widened for fused-recurrent reconstruction wiring.
3375
+ Result of scanning and populating optional gain/plastic slab arrays.
3389
3376
 
3390
- ### SLAB_ZERO
3377
+ ### SlabWriteArrays
3391
3378
 
3392
- Numeric zero sentinel used across slab orchestration and helper pipelines.
3379
+ Writable slab arrays targeted during connection serialization.
3393
3380
 
3394
- ### SLAB_ONE
3381
+ ### SourcePeerConnectionCountContext
3395
3382
 
3396
- Numeric one sentinel used for neutral gain defaults and index math.
3383
+ Context for source-to-peer connection counting.
3397
3384
 
3398
- ### SLAB_GROWTH_FACTOR_NODE
3385
+ ### SpecMetadataAppendContext
3399
3386
 
3400
- Capacity growth factor for Node.js slab allocations.
3387
+ Append-a-spec metadata context for JSON-array metadata keys.
3401
3388
 
3402
- ### SLAB_GROWTH_FACTOR_BROWSER
3389
+ ### StandaloneGenerationContext
3403
3390
 
3404
- Capacity growth factor for browser slab allocations.
3391
+ Shared mutable state for standalone source generation.
3405
3392
 
3406
- ### SLAB_DEFAULT_ASYNC_CHUNK_SIZE
3393
+ ### StartIndicesBuildContext
3407
3394
 
3408
- Default async slab rebuild chunk size when no override is provided.
3395
+ Context for constructing CSR start offsets from precomputed fan-out counts.
3409
3396
 
3410
- ### ConnectionInternals
3397
+ ### StatsNetworkProps
3411
3398
 
3412
- Internal Connection properties accessed during slab operations.
3399
+ Internal network properties used by stats operations.
3413
3400
 
3414
- ### NetworkSlabProps
3401
+ ### SubNodeMutationConfig
3415
3402
 
3416
- Internal Network properties for slab operations.
3403
+ Mutation keep-gates option surface used by sub-node removal logic.
3417
3404
 
3418
- ### PoolKeyMetrics
3405
+ ### TargetLayerPeerContext
3419
3406
 
3420
- Per-pool-key allocation & reuse counters (educational / diagnostics).
3407
+ Context for target-layer peer traversal.
3421
3408
 
3422
- ### TypedArray
3409
+ ### TopologyBuildContext
3423
3410
 
3424
- Union of slab typed array element container types.
3411
+ Mutable context used while building topological ordering.
3425
3412
 
3426
- ### TypedArrayConstructor
3413
+ ### TopologyNetworkProps
3427
3414
 
3428
- Constructor type for typed arrays used in slabs.
3415
+ Internal topology state carrier.
3429
3416
 
3430
- ### NetworkActivationRuntime
3417
+ ### TrainingConnectionInternals
3431
3418
 
3432
- Runtime activation contract used by slab-based execution paths.
3419
+ Runtime connection view used by training internals.
3433
3420
 
3434
- ### NetworkTopoRuntime
3421
+ ### TrainingNetworkInternals
3435
3422
 
3436
- Runtime topology contract used to lazily rebuild topological order.
3423
+ Runtime network view used by training internals.
3437
3424
 
3438
- ### FastSlabNodeRuntime
3425
+ ### TrainingNodeInternals
3439
3426
 
3440
- Node shape required by fast slab activation kernels.
3427
+ Runtime node view used by training internals.
3441
3428
 
3442
- ### SlabBuildContext
3429
+ ### TrainingOptions
3443
3430
 
3444
- Immutable inputs required to build or grow connection slab buffers.
3431
+ Public training options accepted by the high-level training orchestration.
3445
3432
 
3446
- ### SlabPopulateResult
3433
+ Training in this codebase is conceptually:
3434
+ 1) forward activation
3435
+ 2) backward propagation
3436
+ 3) optimizer update
3437
+ repeated until a stopping condition is met.
3447
3438
 
3448
- Result of scanning and populating optional gain/plastic slab arrays.
3439
+ Minimal example:
3449
3440
 
3450
- ### SlabWriteArrays
3441
+ ```ts
3442
+ net.train(set, {
3443
+ iterations: 500,
3444
+ rate: 0.3,
3445
+ batchSize: 16,
3446
+ gradientClip: { mode: 'norm', maxNorm: 1 },
3447
+ });
3448
+ ```
3451
3449
 
3452
- Writable slab arrays targeted during connection serialization.
3450
+ Stopping conditions:
3451
+ - Provide at least one of `iterations` or `error`.
3452
+ - `earlyStopPatience` adds an additional "stop when no improvement" guard.
3453
3453
 
3454
- ### ConnectionSlabView
3454
+ ### TrainingSample
3455
3455
 
3456
- Shape returned by getConnectionSlab describing the packed SoA view.
3456
+ A single supervised training sample used in evolution scoring.
3457
3457
 
3458
- ### BuildAdjacencyContext
3458
+ ### TypedArray
3459
3459
 
3460
- Shared immutable inputs used across the adjacency build pipeline.
3460
+ Union of slab typed array element container types.
3461
3461
 
3462
- ### FanOutCollectionContext
3462
+ ### TypedArrayConstructor
3463
3463
 
3464
- Context for fan-out collection: build inputs plus the output count buffer.
3464
+ Constructor type for typed arrays used in slabs.
3465
3465
 
3466
- ### StartIndicesBuildContext
3466
+ ### WeightSamplingRangeContext
3467
3467
 
3468
- Context for constructing CSR start offsets from precomputed fan-out counts.
3468
+ Context for sampling one random weight value.
3469
3469
 
3470
- ### OutgoingOrderBuildContext
3470
+ ### WeightToleranceComparisonContext
3471
3471
 
3472
- Context for constructing source-grouped outgoing connection order.
3472
+ Context for comparing two scalar weights with numeric tolerance.
3473
3473
 
3474
- ### PublishAdjacencyContext
3474
+ ### WorkerTraversalContext
3475
3475
 
3476
- Context for publishing fully built adjacency slabs to internal network state.
3476
+ Worker-local traversal context.