@reicek/neataptic-ts 0.1.24 → 0.1.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (215) 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/.github/workflows/ci.yml +3 -3
  8. package/.github/workflows/deploy-pages.yml +6 -6
  9. package/.github/workflows/manual_release_pipeline.yml +3 -3
  10. package/.github/workflows/publish.yml +18 -19
  11. package/.github/workflows/release_dispatch.yml +3 -3
  12. package/package.json +26 -20
  13. package/plans/Flappy_Bird_Folder_Documentation_Pass.md +4 -4
  14. package/plans/README.md +24 -0
  15. package/plans/Roadmap.md +62 -40
  16. package/plans/analyze-trace-solid-split.plans.md +66 -0
  17. package/plans/architecture-solid-split.plans.md +9 -15
  18. package/plans/asciiMaze-typescript-repair.plans.md +1 -1
  19. package/plans/generate-docs-solid-split.plans.md +87 -0
  20. package/plans/methods-docs.plans.md +25 -1
  21. package/plans/methods-solid-split.plans.md +14 -14
  22. package/plans/neat-docs.plans.md +9 -1
  23. package/plans/neat-test-surface-repair.plans.md +1 -1
  24. package/plans/render-docs-html-solid-split.plans.md +68 -0
  25. package/plans/src-no-explicit-any-cleanup.plans.md +1 -1
  26. package/plans/utils-docs.plans.md +6 -1
  27. package/scripts/analyze-trace/analyze-trace.analysis.ts +479 -0
  28. package/scripts/analyze-trace/analyze-trace.constants.ts +35 -0
  29. package/scripts/analyze-trace/analyze-trace.io.ts +69 -0
  30. package/scripts/analyze-trace/analyze-trace.report.ts +100 -0
  31. package/scripts/analyze-trace/analyze-trace.shared.ts +116 -0
  32. package/scripts/analyze-trace/analyze-trace.ts +45 -0
  33. package/scripts/analyze-trace/analyze-trace.types.ts +72 -0
  34. package/scripts/assets/theme.css +80 -23
  35. package/scripts/copy-examples.ts +239 -0
  36. package/scripts/export-onnx.ts +223 -0
  37. package/scripts/generate-bench-tables.ts +378 -37
  38. package/scripts/generate-docs/generate-docs.constants.ts +107 -0
  39. package/scripts/generate-docs/generate-docs.order.ts +355 -0
  40. package/scripts/generate-docs/generate-docs.state.ts +31 -0
  41. package/scripts/generate-docs/generate-docs.targets.ts +165 -0
  42. package/scripts/generate-docs/generate-docs.ts +63 -0
  43. package/scripts/generate-docs/generate-docs.types.ts +112 -0
  44. package/scripts/generate-docs/output/generate-docs.output.folder-index.utils.ts +167 -0
  45. package/scripts/generate-docs/output/generate-docs.output.ordering.utils.ts +353 -0
  46. package/scripts/generate-docs/output/generate-docs.output.readme.utils.ts +420 -0
  47. package/scripts/generate-docs/output/generate-docs.output.ts +123 -0
  48. package/scripts/generate-docs/output/generate-docs.output.warnings.utils.ts +219 -0
  49. package/scripts/generate-docs/symbols/generate-docs.symbols.collection.utils.ts +365 -0
  50. package/scripts/generate-docs/symbols/generate-docs.symbols.jsdoc.utils.ts +373 -0
  51. package/scripts/generate-docs/symbols/generate-docs.symbols.normalize.utils.ts +155 -0
  52. package/scripts/generate-docs/symbols/generate-docs.symbols.render.utils.ts +149 -0
  53. package/scripts/generate-docs/symbols/generate-docs.symbols.signature.utils.ts +289 -0
  54. package/scripts/generate-docs/symbols/generate-docs.symbols.ts +11 -0
  55. package/scripts/mermaid-cli.mjs +102 -22
  56. package/scripts/mermaid-cli.ts +736 -0
  57. package/scripts/render-docs-html/render-docs-html.assets.ts +54 -0
  58. package/scripts/render-docs-html/render-docs-html.mermaid.ts +245 -0
  59. package/scripts/{render-docs-html.sidebar.ts → render-docs-html/render-docs-html.navigation.ts} +141 -144
  60. package/scripts/render-docs-html/render-docs-html.pages.ts +333 -0
  61. package/scripts/render-docs-html/render-docs-html.shared.ts +333 -0
  62. package/scripts/render-docs-html/render-docs-html.types.ts +42 -0
  63. package/scripts/render-docs-html.ts +23 -587
  64. package/scripts/run-docs.ts +238 -0
  65. package/scripts/write-dist-docs-pkg.ts +40 -0
  66. package/src/README.md +75 -75
  67. package/src/architecture/connection/README.md +5 -5
  68. package/src/architecture/layer/README.md +508 -508
  69. package/src/architecture/network/README.md +1458 -1458
  70. package/src/architecture/network/activate/README.md +694 -694
  71. package/src/architecture/network/bootstrap/README.md +77 -77
  72. package/src/architecture/network/connect/README.md +74 -74
  73. package/src/architecture/network/deterministic/README.md +135 -135
  74. package/src/architecture/network/evolve/README.md +364 -364
  75. package/src/architecture/network/gating/README.md +130 -130
  76. package/src/architecture/network/genetic/README.md +399 -399
  77. package/src/architecture/network/mutate/README.md +897 -897
  78. package/src/architecture/network/onnx/README.md +720 -720
  79. package/src/architecture/network/onnx/export/README.md +728 -728
  80. package/src/architecture/network/onnx/export/layers/README.md +450 -450
  81. package/src/architecture/network/onnx/import/README.md +618 -618
  82. package/src/architecture/network/onnx/schema/README.md +32 -32
  83. package/src/architecture/network/prune/README.md +245 -245
  84. package/src/architecture/network/remove/README.md +135 -135
  85. package/src/architecture/network/runtime/README.md +106 -106
  86. package/src/architecture/network/serialize/README.md +542 -542
  87. package/src/architecture/network/slab/README.md +608 -608
  88. package/src/architecture/network/standalone/README.md +212 -212
  89. package/src/architecture/network/stats/README.md +84 -84
  90. package/src/architecture/network/topology/README.md +465 -465
  91. package/src/architecture/network/training/README.md +200 -200
  92. package/src/architecture/node/README.md +5 -5
  93. package/src/architecture/nodePool/README.md +14 -14
  94. package/src/methods/README.md +99 -99
  95. package/src/methods/activation/README.md +189 -189
  96. package/src/methods/cost/README.md +131 -131
  97. package/src/methods/rate/README.md +86 -86
  98. package/src/multithreading/README.md +77 -77
  99. package/src/multithreading/workers/browser/README.md +8 -8
  100. package/src/multithreading/workers/node/README.md +8 -8
  101. package/src/neat/README.md +148 -148
  102. package/src/neat/adaptive/README.md +120 -120
  103. package/src/neat/adaptive/acceptance/README.md +40 -40
  104. package/src/neat/adaptive/complexity/README.md +137 -137
  105. package/src/neat/adaptive/core/README.md +197 -197
  106. package/src/neat/adaptive/lineage/README.md +90 -90
  107. package/src/neat/adaptive/mutation/README.md +284 -284
  108. package/src/neat/compat/README.md +43 -43
  109. package/src/neat/compat/core/README.md +90 -90
  110. package/src/neat/diversity/README.md +35 -35
  111. package/src/neat/diversity/core/README.md +88 -88
  112. package/src/neat/evaluate/README.md +85 -85
  113. package/src/neat/evaluate/auto-distance/README.md +75 -75
  114. package/src/neat/evaluate/entropy-compat/README.md +37 -37
  115. package/src/neat/evaluate/entropy-sharing/README.md +43 -43
  116. package/src/neat/evaluate/fitness/README.md +23 -23
  117. package/src/neat/evaluate/novelty/README.md +120 -120
  118. package/src/neat/evaluate/objectives/README.md +17 -17
  119. package/src/neat/evaluate/shared/README.md +94 -94
  120. package/src/neat/evolve/README.md +96 -96
  121. package/src/neat/evolve/adaptive/README.md +60 -60
  122. package/src/neat/evolve/objectives/README.md +63 -63
  123. package/src/neat/evolve/offspring/README.md +56 -56
  124. package/src/neat/evolve/population/README.md +171 -171
  125. package/src/neat/evolve/runtime/README.md +79 -79
  126. package/src/neat/evolve/speciation/README.md +74 -74
  127. package/src/neat/evolve/warnings/README.md +10 -10
  128. package/src/neat/export/README.md +114 -114
  129. package/src/neat/helpers/README.md +50 -50
  130. package/src/neat/init/README.md +9 -9
  131. package/src/neat/lineage/core/README.md +101 -101
  132. package/src/neat/multiobjective/category/README.md +74 -74
  133. package/src/neat/multiobjective/crowding/README.md +272 -272
  134. package/src/neat/multiobjective/dominance/README.md +171 -171
  135. package/src/neat/multiobjective/fronts/README.md +68 -68
  136. package/src/neat/multiobjective/metrics/README.md +43 -43
  137. package/src/neat/multiobjective/objectives/README.md +31 -31
  138. package/src/neat/multiobjective/shared/README.md +27 -27
  139. package/src/neat/mutation/README.md +97 -97
  140. package/src/neat/mutation/add-conn/README.md +115 -115
  141. package/src/neat/mutation/add-node/README.md +126 -126
  142. package/src/neat/mutation/flow/README.md +149 -149
  143. package/src/neat/mutation/repair/README.md +185 -185
  144. package/src/neat/mutation/select/README.md +117 -117
  145. package/src/neat/mutation/shared/README.md +32 -32
  146. package/src/neat/objectives/README.md +25 -25
  147. package/src/neat/objectives/core/README.md +67 -67
  148. package/src/neat/pruning/README.md +40 -40
  149. package/src/neat/pruning/core/README.md +171 -171
  150. package/src/neat/pruning/facade/README.md +32 -32
  151. package/src/neat/rng/README.md +104 -104
  152. package/src/neat/rng/core/README.md +137 -137
  153. package/src/neat/rng/facade/README.md +50 -50
  154. package/src/neat/selection/README.md +111 -111
  155. package/src/neat/selection/core/README.md +227 -227
  156. package/src/neat/selection/facade/README.md +61 -61
  157. package/src/neat/shared/README.md +163 -163
  158. package/src/neat/speciation/README.md +31 -31
  159. package/src/neat/speciation/threshold/README.md +35 -35
  160. package/src/neat/species/README.md +25 -25
  161. package/src/neat/species/core/README.md +20 -20
  162. package/src/neat/species/core/shared/README.md +18 -18
  163. package/src/neat/species/history/context/README.md +22 -22
  164. package/src/neat/telemetry/accessors/README.md +58 -58
  165. package/src/neat/telemetry/exports/README.md +233 -233
  166. package/src/neat/telemetry/facade/README.md +252 -252
  167. package/src/neat/telemetry/facade/archive/README.md +57 -57
  168. package/src/neat/telemetry/facade/buffer/README.md +43 -43
  169. package/src/neat/telemetry/facade/lineage/README.md +12 -12
  170. package/src/neat/telemetry/facade/objectives/README.md +44 -44
  171. package/src/neat/telemetry/facade/runtime/README.md +26 -26
  172. package/src/neat/telemetry/facade/species/README.md +27 -27
  173. package/src/neat/telemetry/metrics/README.md +696 -696
  174. package/src/neat/telemetry/recorder/README.md +57 -57
  175. package/src/neat/telemetry/types/README.md +32 -32
  176. package/src/neat/topology-intent/README.md +75 -75
  177. package/src/utils/README.md +193 -193
  178. package/test/examples/asciiMaze/browser-entry/README.md +92 -92
  179. package/test/examples/asciiMaze/dashboardManager/README.md +109 -109
  180. package/test/examples/asciiMaze/dashboardManager/telemetry/README.md +28 -28
  181. package/test/examples/asciiMaze/evolutionEngine/README.md +1527 -1527
  182. package/test/examples/asciiMaze/mazeMovement/README.md +105 -105
  183. package/test/examples/asciiMaze/mazeMovement/finalization/README.md +16 -16
  184. package/test/examples/asciiMaze/mazeMovement/policy/README.md +57 -57
  185. package/test/examples/asciiMaze/mazeMovement/runtime/README.md +52 -52
  186. package/test/examples/asciiMaze/mazeMovement/shaping/README.md +46 -46
  187. package/test/examples/flappy_bird/browser-entry/README.md +508 -508
  188. package/test/examples/flappy_bird/browser-entry/host/README.md +101 -101
  189. package/test/examples/flappy_bird/browser-entry/host/resize/README.md +144 -144
  190. package/test/examples/flappy_bird/browser-entry/network-view/README.md +194 -194
  191. package/test/examples/flappy_bird/browser-entry/playback/README.md +278 -278
  192. package/test/examples/flappy_bird/browser-entry/playback/background/README.md +129 -129
  193. package/test/examples/flappy_bird/browser-entry/playback/background/ground-grid/README.md +502 -502
  194. package/test/examples/flappy_bird/browser-entry/playback/frame-render/README.md +139 -139
  195. package/test/examples/flappy_bird/browser-entry/playback/snapshot/README.md +10 -10
  196. package/test/examples/flappy_bird/browser-entry/playback/trail/README.md +43 -43
  197. package/test/examples/flappy_bird/browser-entry/playback/worker-channel/README.md +30 -30
  198. package/test/examples/flappy_bird/browser-entry/runtime/README.md +59 -59
  199. package/test/examples/flappy_bird/browser-entry/visualization/README.md +276 -276
  200. package/test/examples/flappy_bird/browser-entry/worker-channel/README.md +16 -16
  201. package/test/examples/flappy_bird/constants/README.md +1070 -1070
  202. package/test/examples/flappy_bird/environment/README.md +22 -22
  203. package/test/examples/flappy_bird/evaluation/README.md +32 -32
  204. package/test/examples/flappy_bird/evaluation/rollout/README.md +141 -141
  205. package/test/examples/flappy_bird/flappy-evolution-worker/README.md +425 -425
  206. package/test/examples/flappy_bird/simulation-shared/README.md +170 -170
  207. package/test/examples/flappy_bird/simulation-shared/observation/README.md +109 -109
  208. package/test/examples/flappy_bird/trainer/README.md +325 -325
  209. package/test/examples/flappy_bird/trainer/evaluation/README.md +74 -74
  210. package/scripts/analyze-trace.ts +0 -590
  211. package/scripts/copy-examples.mjs +0 -114
  212. package/scripts/export-onnx.mjs +0 -86
  213. package/scripts/generate-bench-tables.mjs +0 -182
  214. package/scripts/generate-docs.ts +0 -2900
  215. package/scripts/write-dist-docs-pkg.mjs +0 -16
@@ -46,6 +46,19 @@ const restored = importFromONNX(modelRoundTrip);
46
46
 
47
47
  ## architecture/network/onnx/network.onnx.ts
48
48
 
49
+ ### Conv2DMapping
50
+
51
+ Mapping declaration for treating a fully-connected layer as a 2D convolution during export.
52
+
53
+ This does **not** magically turn an MLP into a convolutional network at runtime.
54
+ It annotates a particular export-layer index with a conv interpretation so that:
55
+ - The exported graph uses conv-shaped tensors/operators, and
56
+ - Import can re-attach pooling/flatten metadata appropriately.
57
+
58
+ Pitfall: mappings must match the actual layer sizes. If `inHeight * inWidth * inChannels`
59
+ does not correspond to the prior layer width (and similarly for outputs), export or import
60
+ may reject the model.
61
+
49
62
  ### exportToONNX
50
63
 
51
64
  ```ts
@@ -124,19 +137,6 @@ Parameters:
124
137
 
125
138
  Returns: Reconstructed network ready for inference/evolution workflows.
126
139
 
127
- ### Conv2DMapping
128
-
129
- Mapping declaration for treating a fully-connected layer as a 2D convolution during export.
130
-
131
- This does **not** magically turn an MLP into a convolutional network at runtime.
132
- It annotates a particular export-layer index with a conv interpretation so that:
133
- - The exported graph uses conv-shaped tensors/operators, and
134
- - Import can re-attach pooling/flatten metadata appropriately.
135
-
136
- Pitfall: mappings must match the actual layer sizes. If `inHeight * inWidth * inChannels`
137
- does not correspond to the prior layer width (and similarly for outputs), export or import
138
- may reject the model.
139
-
140
140
  ### OnnxExportOptions
141
141
 
142
142
  Options controlling ONNX-like export.
@@ -253,160 +253,21 @@ Limitations / TODO (tracked for later phases):
253
253
  NOTE: Import is only guaranteed to work for models produced by `exportToONNX()`; arbitrary ONNX graphs are
254
254
  NOT supported. Experimental fused recurrent nodes are best-effort and may silently degrade if shapes mismatch.
255
255
 
256
- ### buildOnnxModel
257
-
258
- ```ts
259
- buildOnnxModel(
260
- network: default,
261
- layers: default[][],
262
- options: OnnxExportOptions,
263
- ): OnnxModel
264
- ```
265
-
266
- Build an ONNX-like model from a validated layered network view.
267
-
268
- Role in the ONNX pipeline:
269
- - This function is a thin, stable orchestration boundary used by higher-level exporters.
270
- - It forwards to the implementation module while preserving a predictable public API
271
- for callers that import from this compatibility barrel.
272
- - Keeping this wrapper explicit helps isolate call sites from internal file splits
273
- and phased refactors in export internals.
274
-
275
- Expected preconditions:
276
- - `layers` has already been inferred from the same `network` instance.
277
- - Structural validation (layer homogeneity/connectivity and option gates) is complete.
278
- - Export options are normalized by the caller according to project defaults.
279
-
280
- High-level behavior:
281
- 1. Receive network, ordered layer matrix, and export options.
282
- 2. Delegate model construction to the concrete builder implementation.
283
- 3. Return the resulting ONNX-like JSON graph container unchanged.
284
-
285
- Parameters:
286
- - `network` - - Source network to serialize.
287
- - `layers` - - Ordered layer matrix produced by layer inference utilities.
288
- - `options` - - Export options controlling metadata/recurrent/partial-connectivity behavior.
289
-
290
- Returns: ONNX-like model object representing graph nodes, tensors, and metadata.
291
-
292
- Example:
293
-
294
- ```ts
295
- const layers = inferLayerOrdering(network);
296
- const model = buildOnnxModel(network, layers, { includeMetadata: true });
297
- ```
298
-
299
- ### OnnxModel
300
-
301
- ONNX-like model container (JSON-serializable).
302
-
303
- This is the main “wire format” object in this folder. Persist it as JSON text:
304
-
305
- ```ts
306
- const jsonText = JSON.stringify(model);
307
- const restoredModel = JSON.parse(jsonText) as OnnxModel;
308
- ```
309
-
310
- Notes:
311
- - `metadata_props` contains NeatapticTS-specific keys (layer sizes, recurrent flags,
312
- conv/pool mappings, etc.). This is where most round-trip hints live.
313
- - Initializers currently store floating-point weights in `float_data`.
314
-
315
- Security/trust boundary:
316
- - Treat this as untrusted input if it comes from outside your process.
317
-
318
- ### inferLayerOrdering
319
-
320
- ```ts
321
- inferLayerOrdering(
322
- network: default,
323
- ): default[][]
324
- ```
325
-
326
- Infer strictly layered ordering from a network.
327
-
328
- Parameters:
329
- - `network` - Source network.
330
-
331
- Returns: Ordered layers: input, hidden..., output.
332
-
333
- ### rebuildConnectionsLocal
334
-
335
- ```ts
336
- rebuildConnectionsLocal(
337
- networkLike: default,
338
- ): void
339
- ```
340
-
341
- Rebuild the network's flat connections array from each node's outgoing list.
342
-
343
- Parameters:
344
- - `networkLike` - Network-like instance to mutate.
345
-
346
- Returns: Nothing.
347
-
348
- ### validateLayerHomogeneityAndConnectivity
256
+ ### applyModelMetadata
349
257
 
350
258
  ```ts
351
- validateLayerHomogeneityAndConnectivity(
352
- layers: default[][],
353
- network: default,
354
- options: OnnxExportOptions,
259
+ applyModelMetadata(
260
+ context: OnnxModelMetadataContext,
355
261
  ): void
356
262
  ```
357
263
 
358
- Validate connectivity and activation homogeneity constraints per layer.
264
+ Attach producer and opset metadata to a model when metadata emission is enabled.
359
265
 
360
266
  Parameters:
361
- - `layers` - Layered node arrays.
362
- - `network` - Source network (reserved for compatibility).
363
- - `options` - Export options.
267
+ - `context` - Metadata application context.
364
268
 
365
269
  Returns: Nothing.
366
270
 
367
- ### runOnnxExportFlow
368
-
369
- ```ts
370
- runOnnxExportFlow(
371
- network: default,
372
- options: OnnxExportOptions,
373
- ): OnnxModel
374
- ```
375
-
376
- Execute the complete ONNX export flow for one network instance.
377
-
378
- High-level behavior:
379
- 1. Rebuild runtime connection caches and assign stable export indices.
380
- 2. Infer layered ordering and collect recurrent-pattern stubs.
381
- 3. Validate structural constraints for the requested export options.
382
- 4. Build ONNX graph payload and append inference-oriented metadata.
383
-
384
- Parameters:
385
- - `network` - Source network to serialize.
386
- - `options` - Optional ONNX export controls.
387
-
388
- Returns: ONNX-like model payload.
389
-
390
- ### runOnnxImportFlow
391
-
392
- ```ts
393
- runOnnxImportFlow(
394
- onnx: OnnxModel,
395
- ): default
396
- ```
397
-
398
- Execute the complete ONNX import flow and reconstruct a runtime network.
399
-
400
- High-level behavior:
401
- 1. Extract architecture dimensions and build a perceptron scaffold.
402
- 2. Restore dense parameters and activation functions.
403
- 3. Reconstruct recurrent/pooling metadata and rebuild connection caches.
404
-
405
- Parameters:
406
- - `onnx` - ONNX-like model payload to reconstruct.
407
-
408
- Returns: Reconstructed network instance.
409
-
410
271
  ### assignActivationFunctions
411
272
 
412
273
  ```ts
@@ -447,37 +308,48 @@ Parameters:
447
308
 
448
309
  Returns: Nothing.
449
310
 
450
- ### deriveHiddenLayerSizes
311
+ ### buildOnnxModel
451
312
 
452
313
  ```ts
453
- deriveHiddenLayerSizes(
454
- initializers: OnnxTensor[],
455
- metadataProps: OnnxMetadataProperty[] | undefined,
456
- ): number[]
314
+ buildOnnxModel(
315
+ network: default,
316
+ layers: default[][],
317
+ options: OnnxExportOptions,
318
+ ): OnnxModel
457
319
  ```
458
320
 
459
- Extract hidden layer sizes from ONNX initializers (weight tensors).
321
+ Build an ONNX-like model from a validated layered network view.
460
322
 
461
- Parameters:
462
- - `initializers` - ONNX initializer tensors.
463
- - `metadataProps` - Optional ONNX metadata properties.
323
+ Role in the ONNX pipeline:
324
+ - This function is a thin, stable orchestration boundary used by higher-level exporters.
325
+ - It forwards to the implementation module while preserving a predictable public API
326
+ for callers that import from this compatibility barrel.
327
+ - Keeping this wrapper explicit helps isolate call sites from internal file splits
328
+ and phased refactors in export internals.
464
329
 
465
- Returns: Hidden layer sizes in order.
330
+ Expected preconditions:
331
+ - `layers` has already been inferred from the same `network` instance.
332
+ - Structural validation (layer homogeneity/connectivity and option gates) is complete.
333
+ - Export options are normalized by the caller according to project defaults.
466
334
 
467
- ### applyModelMetadata
335
+ High-level behavior:
336
+ 1. Receive network, ordered layer matrix, and export options.
337
+ 2. Delegate model construction to the concrete builder implementation.
338
+ 3. Return the resulting ONNX-like JSON graph container unchanged.
468
339
 
469
- ```ts
470
- applyModelMetadata(
471
- context: OnnxModelMetadataContext,
472
- ): void
473
- ```
340
+ Parameters:
341
+ - `network` - - Source network to serialize.
342
+ - `layers` - - Ordered layer matrix produced by layer inference utilities.
343
+ - `options` - - Export options controlling metadata/recurrent/partial-connectivity behavior.
474
344
 
475
- Attach producer and opset metadata to a model when metadata emission is enabled.
345
+ Returns: ONNX-like model object representing graph nodes, tensors, and metadata.
476
346
 
477
- Parameters:
478
- - `context` - Metadata application context.
347
+ Example:
479
348
 
480
- Returns: Nothing.
349
+ ```ts
350
+ const layers = inferLayerOrdering(network);
351
+ const model = buildOnnxModel(network, layers, { includeMetadata: true });
352
+ ```
481
353
 
482
354
  ### collectRecurrentLayerIndices
483
355
 
@@ -524,49 +396,22 @@ Parameters:
524
396
 
525
397
  Returns: Input and output dimension arrays for ONNX value info.
526
398
 
527
- ### emitLayerGraph
399
+ ### deriveHiddenLayerSizes
528
400
 
529
401
  ```ts
530
- emitLayerGraph(
531
- context: LayerBuildContext,
532
- ): string
402
+ deriveHiddenLayerSizes(
403
+ initializers: OnnxTensor[],
404
+ metadataProps: OnnxMetadataProperty[] | undefined,
405
+ ): number[]
533
406
  ```
534
407
 
535
- Emit one export layer graph segment by routing the layer through the correct
536
- ONNX emission strategy.
537
-
538
- Dispatch order matters:
539
- - explicit Conv mappings win first,
540
- - recurrent single-step export is considered only for hidden layers with
541
- self-connections,
542
- - non-recurrent layers fall back to compact dense emission or mixed-activation
543
- per-neuron decomposition.
544
-
545
- Important invariants:
546
- - recurrent mixed activations are rejected elsewhere rather than silently
547
- decomposed here,
548
- - `allowMixedActivations` only affects the dense-family fallback path,
549
- - the returned tensor name is the canonical input for the next layer.
408
+ Extract hidden layer sizes from ONNX initializers (weight tensors).
550
409
 
551
410
  Parameters:
552
- - `context` - Layer build context.
411
+ - `initializers` - ONNX initializer tensors.
412
+ - `metadataProps` - Optional ONNX metadata properties.
553
413
 
554
- Returns: Output tensor name produced by this layer.
555
-
556
- Example:
557
-
558
- ```ts
559
- const outputName = emitLayerGraph({
560
- model,
561
- layers,
562
- layerIndex: 2,
563
- previousOutputName: 'Layer_1',
564
- options: { allowMixedActivations: true },
565
- recurrentLayerIndices: [],
566
- batchDimension: false,
567
- legacyNodeOrdering: false,
568
- });
569
- ```
414
+ Returns: Hidden layer sizes in order.
570
415
 
571
416
  ### emitFusedRecurrentHeuristics
572
417
 
@@ -589,6 +434,50 @@ Parameters:
589
434
 
590
435
  Returns: Nothing.
591
436
 
437
+ ### emitLayerGraph
438
+
439
+ ```ts
440
+ emitLayerGraph(
441
+ context: LayerBuildContext,
442
+ ): string
443
+ ```
444
+
445
+ Emit one export layer graph segment by routing the layer through the correct
446
+ ONNX emission strategy.
447
+
448
+ Dispatch order matters:
449
+ - explicit Conv mappings win first,
450
+ - recurrent single-step export is considered only for hidden layers with
451
+ self-connections,
452
+ - non-recurrent layers fall back to compact dense emission or mixed-activation
453
+ per-neuron decomposition.
454
+
455
+ Important invariants:
456
+ - recurrent mixed activations are rejected elsewhere rather than silently
457
+ decomposed here,
458
+ - `allowMixedActivations` only affects the dense-family fallback path,
459
+ - the returned tensor name is the canonical input for the next layer.
460
+
461
+ Parameters:
462
+ - `context` - Layer build context.
463
+
464
+ Returns: Output tensor name produced by this layer.
465
+
466
+ Example:
467
+
468
+ ```ts
469
+ const outputName = emitLayerGraph({
470
+ model,
471
+ layers,
472
+ layerIndex: 2,
473
+ previousOutputName: 'Layer_1',
474
+ options: { allowMixedActivations: true },
475
+ recurrentLayerIndices: [],
476
+ batchDimension: false,
477
+ legacyNodeOrdering: false,
478
+ });
479
+ ```
480
+
592
481
  ### finalizeExportMetadata
593
482
 
594
483
  ```ts
@@ -614,6 +503,117 @@ Parameters:
614
503
 
615
504
  Returns: Nothing.
616
505
 
506
+ ### inferLayerOrdering
507
+
508
+ ```ts
509
+ inferLayerOrdering(
510
+ network: default,
511
+ ): default[][]
512
+ ```
513
+
514
+ Infer strictly layered ordering from a network.
515
+
516
+ Parameters:
517
+ - `network` - Source network.
518
+
519
+ Returns: Ordered layers: input, hidden..., output.
520
+
521
+ ### OnnxModel
522
+
523
+ ONNX-like model container (JSON-serializable).
524
+
525
+ This is the main “wire format” object in this folder. Persist it as JSON text:
526
+
527
+ ```ts
528
+ const jsonText = JSON.stringify(model);
529
+ const restoredModel = JSON.parse(jsonText) as OnnxModel;
530
+ ```
531
+
532
+ Notes:
533
+ - `metadata_props` contains NeatapticTS-specific keys (layer sizes, recurrent flags,
534
+ conv/pool mappings, etc.). This is where most round-trip hints live.
535
+ - Initializers currently store floating-point weights in `float_data`.
536
+
537
+ Security/trust boundary:
538
+ - Treat this as untrusted input if it comes from outside your process.
539
+
540
+ ### rebuildConnectionsLocal
541
+
542
+ ```ts
543
+ rebuildConnectionsLocal(
544
+ networkLike: default,
545
+ ): void
546
+ ```
547
+
548
+ Rebuild the network's flat connections array from each node's outgoing list.
549
+
550
+ Parameters:
551
+ - `networkLike` - Network-like instance to mutate.
552
+
553
+ Returns: Nothing.
554
+
555
+ ### runOnnxExportFlow
556
+
557
+ ```ts
558
+ runOnnxExportFlow(
559
+ network: default,
560
+ options: OnnxExportOptions,
561
+ ): OnnxModel
562
+ ```
563
+
564
+ Execute the complete ONNX export flow for one network instance.
565
+
566
+ High-level behavior:
567
+ 1. Rebuild runtime connection caches and assign stable export indices.
568
+ 2. Infer layered ordering and collect recurrent-pattern stubs.
569
+ 3. Validate structural constraints for the requested export options.
570
+ 4. Build ONNX graph payload and append inference-oriented metadata.
571
+
572
+ Parameters:
573
+ - `network` - Source network to serialize.
574
+ - `options` - Optional ONNX export controls.
575
+
576
+ Returns: ONNX-like model payload.
577
+
578
+ ### runOnnxImportFlow
579
+
580
+ ```ts
581
+ runOnnxImportFlow(
582
+ onnx: OnnxModel,
583
+ ): default
584
+ ```
585
+
586
+ Execute the complete ONNX import flow and reconstruct a runtime network.
587
+
588
+ High-level behavior:
589
+ 1. Extract architecture dimensions and build a perceptron scaffold.
590
+ 2. Restore dense parameters and activation functions.
591
+ 3. Reconstruct recurrent/pooling metadata and rebuild connection caches.
592
+
593
+ Parameters:
594
+ - `onnx` - ONNX-like model payload to reconstruct.
595
+
596
+ Returns: Reconstructed network instance.
597
+
598
+ ### validateLayerHomogeneityAndConnectivity
599
+
600
+ ```ts
601
+ validateLayerHomogeneityAndConnectivity(
602
+ layers: default[][],
603
+ network: default,
604
+ options: OnnxExportOptions,
605
+ ): void
606
+ ```
607
+
608
+ Validate connectivity and activation homogeneity constraints per layer.
609
+
610
+ Parameters:
611
+ - `layers` - Layered node arrays.
612
+ - `network` - Source network (reserved for compatibility).
613
+ - `options` - Export options.
614
+
615
+ Returns: Nothing.
616
+
617
617
  ## architecture/network/onnx/network.onnx.utils.types.ts
618
618
 
619
619
  Types for NeatapticTS’s ONNX-like JSON export/import.
@@ -654,99 +654,29 @@ Stability & compatibility expectations:
654
654
  - The schema is JSON-first and may evolve; prefer re-exporting/importing through the
655
655
  library rather than hand-editing blobs.
656
656
 
657
- ### Conv2DMapping
658
-
659
- Mapping declaration for treating a fully-connected layer as a 2D convolution during export.
660
-
661
- This does **not** magically turn an MLP into a convolutional network at runtime.
662
- It annotates a particular export-layer index with a conv interpretation so that:
663
- - The exported graph uses conv-shaped tensors/operators, and
664
- - Import can re-attach pooling/flatten metadata appropriately.
665
-
666
- Pitfall: mappings must match the actual layer sizes. If `inHeight * inWidth * inChannels`
667
- does not correspond to the prior layer width (and similarly for outputs), export or import
668
- may reject the model.
669
-
670
- ### OnnxAttribute
671
-
672
- ONNX node attribute payload.
673
-
674
- This simplified JSON-first shape is enough for the operators emitted by the
675
- current exporter. It intentionally avoids protobuf-level complexity while
676
- still preserving the attribute variants needed by the importer.
677
-
678
- ### OnnxDimension
679
-
680
- One dimension inside an ONNX tensor shape.
681
-
682
- Use `dim_value` for fixed numeric widths and `dim_param` for symbolic names
683
- such as a batch dimension.
684
-
685
- ### OnnxGraph
686
-
687
- Graph body of an ONNX-like model.
688
-
689
- The exporter writes three main collections here:
690
- - `inputs` and `outputs` describe graph boundaries,
691
- - `initializer` stores constant tensors such as weights and biases,
692
- - `node` stores the ordered operator payloads that consume those tensors.
693
-
694
- ### OnnxMetadataProperty
695
-
696
- Canonical metadata key-value pair used in ONNX model metadata_props.
697
-
698
- ### OnnxModel
699
-
700
- ONNX-like model container (JSON-serializable).
701
-
702
- This is the main “wire format” object in this folder. Persist it as JSON text:
657
+ ### ActivationFunction
703
658
 
704
659
  ```ts
705
- const jsonText = JSON.stringify(model);
706
- const restoredModel = JSON.parse(jsonText) as OnnxModel;
660
+ ActivationFunction(
661
+ x: number,
662
+ derivate: boolean | undefined,
663
+ ): number
707
664
  ```
708
665
 
709
- Notes:
710
- - `metadata_props` contains NeatapticTS-specific keys (layer sizes, recurrent flags,
711
- conv/pool mappings, etc.). This is where most round-trip hints live.
712
- - Initializers currently store floating-point weights in `float_data`.
713
-
714
- Security/trust boundary:
715
- - Treat this as untrusted input if it comes from outside your process.
716
-
717
- ### OnnxNode
718
-
719
- One ONNX operator invocation inside the graph.
720
-
721
- Nodes connect named tensors rather than object references, which keeps the
722
- exported payload easy to serialize, inspect, and diff as plain JSON.
723
-
724
- ### OnnxShape
725
-
726
- ONNX tensor type shape.
727
-
728
- ### OnnxTensor
729
-
730
- Serialized tensor payload stored inside graph initializers.
731
-
732
- NeatapticTS currently writes floating-point parameter vectors and matrices to
733
- `float_data`, along with the tensor name, element type, and logical shape.
734
-
735
- ### OnnxTensorType
736
-
737
- ONNX tensor type.
738
-
739
- ### OnnxValueInfo
666
+ Runtime activation function signature used by ONNX activation import/export paths.
740
667
 
741
- ONNX value info (input/output description).
668
+ Neataptic-style activations support a dual-purpose call pattern:
669
+ - `derivate === false | undefined`: return activation output $f(x)$
670
+ - `derivate === true`: return derivative $f'(x)$
742
671
 
743
- ### Pool2DMapping
672
+ This matches historical Neataptic semantics and keeps ONNX import/export compatible.
744
673
 
745
- Mapping describing a pooling operation inserted after a given export-layer index.
674
+ Example:
746
675
 
747
- This is represented as metadata and optional graph nodes during export.
748
- Import uses it to attach pooling-related runtime metadata back onto the reconstructed
749
- network (when supported).
676
+ ```ts
677
+ const y = activation(x);
678
+ const dy = activation(x, true);
679
+ ```
750
680
 
751
681
  ### ActivationSquashFunction
752
682
 
@@ -759,6 +689,19 @@ ActivationSquashFunction(
759
689
 
760
690
  Activation function signature used by ONNX layer emission helpers.
761
691
 
692
+ ### Conv2DMapping
693
+
694
+ Mapping declaration for treating a fully-connected layer as a 2D convolution during export.
695
+
696
+ This does **not** magically turn an MLP into a convolutional network at runtime.
697
+ It annotates a particular export-layer index with a conv interpretation so that:
698
+ - The exported graph uses conv-shaped tensors/operators, and
699
+ - Import can re-attach pooling/flatten metadata appropriately.
700
+
701
+ Pitfall: mappings must match the actual layer sizes. If `inHeight * inWidth * inChannels`
702
+ does not correspond to the prior layer width (and similarly for outputs), export or import
703
+ may reject the model.
704
+
762
705
  ### ConvKernelConsistencyContext
763
706
 
764
707
  Context for kernel-coordinate consistency checks at one output position.
@@ -859,6 +802,10 @@ Context for ONNX fused recurrent initializer names.
859
802
 
860
803
  Context for heuristic GRU emission when a layer matches expected shape.
861
804
 
805
+ ### HiddenLayerActivationTraversalContext
806
+
807
+ Hidden-layer traversal context for assigning imported activation functions.
808
+
862
809
  ### HiddenLayerHeuristicContext
863
810
 
864
811
  Context for one hidden layer during heuristic recurrent emission.
@@ -871,261 +818,205 @@ Append-an-index metadata context for JSON-array metadata keys.
871
818
 
872
819
  Activation analysis context for one layer.
873
820
 
874
- ### LayerBuildContext
875
-
876
- Layer build context used while emitting one ONNX graph layer segment.
877
-
878
- ### LayerRecurrentDecisionContext
879
-
880
- Context used to decide recurrent emission branch usage.
881
-
882
- ### LayerTraversalContext
883
-
884
- Layer traversal context with adjacent layers and output classification.
885
-
886
- ### LstmEmissionContext
887
-
888
- Context for heuristic LSTM emission when a layer matches expected shape.
889
-
890
- ### OnnxBaseModelBuildContext
891
-
892
- Context for constructing a base ONNX model shell.
893
-
894
- ### OnnxBuildResolvedOptions
895
-
896
- Resolved options used by ONNX model build orchestration.
897
-
898
- ### OnnxConvEmissionContext
899
-
900
- Context used after resolving Conv mapping for one layer.
901
-
902
- ### OnnxConvEmissionParams
903
-
904
- Parameters accepted by Conv layer emission.
905
-
906
- ### OnnxConvParameters
907
-
908
- Flattened Conv parameters for ONNX initializers.
909
-
910
- ### OnnxConvTensorNames
911
-
912
- Tensor names generated for Conv parameters.
913
-
914
- ### OnnxExportOptions
915
-
916
- Options controlling ONNX-like export.
917
-
918
- These options trade off strictness, portability, and fidelity:
919
-
920
- - **Strict (default-ish)** export tries to keep the graph easy to interpret:
921
- layered topology, homogeneous activations per layer, and fully-connected layers.
922
-
923
- - **Relaxed** export (`allowPartialConnectivity` / `allowMixedActivations`) can represent
924
- more networks, but it may generate graphs that are primarily meant for NeatapticTS’s
925
- importer (and may be less friendly to external ONNX tooling).
926
-
927
- - **Recurrent export** (`allowRecurrent`) is intentionally conservative and currently
928
- focuses on a constrained single-step representation and optional fused heuristics.
929
-
930
- Key fields (high-level):
931
- - `includeMetadata`: includes `metadata_props` with architecture hints.
932
- - `opset`: numeric opset version stored in the exported model metadata (default is
933
- resolved by the exporter; commonly 18 in this codebase).
934
- - `legacyNodeOrdering`: keeps older node ordering for backward compatibility.
935
- - `conv2dMappings` / `pool2dMappings`: encode conv/pool semantics for fully-connected
936
- layers via explicit mapping declarations.
937
-
938
- ### OnnxGraphDimensionBuildContext
939
-
940
- Context for constructing input/output ONNX graph dimensions.
941
-
942
- ### OnnxGraphDimensions
943
-
944
- Output dimensions used by ONNX graph input/output value info payloads.
945
-
946
- ### OnnxLayerEmissionContext
947
-
948
- Context for emitting non-input layers during model build.
949
-
950
- ### OnnxLayerEmissionResult
951
-
952
- Result of emitting non-input export layers.
953
-
954
- ### OnnxModelMetadataContext
821
+ ### LayerActivationValidationContext
955
822
 
956
- Context for applying optional ONNX model metadata.
823
+ Activation-homogeneity decision context for one current layer.
957
824
 
958
- ### OnnxPostProcessingContext
825
+ ### LayerBuildContext
959
826
 
960
- Context for post-processing and export metadata finalization.
827
+ Layer build context used while emitting one ONNX graph layer segment.
961
828
 
962
- ### OnnxRecurrentCollectionContext
829
+ ### LayerConnectivityValidationContext
963
830
 
964
- Context for collecting recurrent layer indices during model build.
831
+ Connectivity decision context for one source-target node pair.
965
832
 
966
- ### OnnxRecurrentInputValueInfoContext
833
+ ### LayerOrderingNodeGroups
967
834
 
968
- Context for constructing one recurrent previous-state graph input payload.
835
+ Node partitions used by ONNX layered-ordering inference traversal.
969
836
 
970
- ### OnnxRecurrentLayerProcessingContext
837
+ ### LayerOrderingResolutionContext
971
838
 
972
- Execution context for processing one hidden recurrent layer.
839
+ Mutable traversal state while resolving hidden-layer ordering.
973
840
 
974
- ### OnnxRecurrentLayerTraversalContext
841
+ ### LayerRecurrentDecisionContext
975
842
 
976
- Traversal context for one hidden layer during recurrent-input collection.
843
+ Context used to decide recurrent emission branch usage.
977
844
 
978
- ### OptionalLayerOutputParams
845
+ ### LayerTraversalContext
979
846
 
980
- Shared parameters for optional pooling/flatten output emission.
847
+ Layer traversal context with adjacent layers and output classification.
981
848
 
982
- ### OptionalPoolingAndFlattenParams
849
+ ### LayerValidationTraversalContext
983
850
 
984
- Parameters for optional pooling + flatten emission after a layer output.
851
+ Layer-wise validation context for activation and connectivity checks.
985
852
 
986
- ### PerNeuronConcatNodePayload
853
+ ### LstmEmissionContext
987
854
 
988
- Per-neuron concat node payload.
855
+ Context for heuristic LSTM emission when a layer matches expected shape.
989
856
 
990
- ### PerNeuronGraphNames
857
+ ### NetworkWithOnnxImportPooling
991
858
 
992
- Per-neuron graph tensor names.
859
+ Network instance augmented with optional imported ONNX pooling metadata.
993
860
 
994
- ### PerNeuronLayerContext
861
+ ### NodeInternals
995
862
 
996
- Per-neuron layer context alias.
863
+ Runtime interface for accessing node internal properties.
997
864
 
998
- ### PerNeuronLayerParams
865
+ This is intentionally "internal": it exposes mutable fields that the ONNX exporter/importer
866
+ needs (connections, bias, squash). Regular library users should generally interact with
867
+ the public `Node` API instead.
999
868
 
1000
- Parameters for per-neuron layer emission.
869
+ ### NodeInternalsWithExportIndex
1001
870
 
1002
- ### PerNeuronNodeContext
871
+ Runtime node internals augmented with optional export index metadata.
1003
872
 
1004
- Per-neuron normalized node context.
873
+ ### OnnxActivationAssignmentContext
1005
874
 
1006
- ### PerNeuronSubgraphContext
875
+ Shared activation-assignment context for hidden and output traversal.
1007
876
 
1008
- Per-neuron subgraph emission context.
877
+ ### OnnxActivationLayerOperations
1009
878
 
1010
- ### PerNeuronTensorNames
879
+ Layer-indexed activation operator lookup extracted from ONNX graph nodes.
1011
880
 
1012
- Per-neuron initializer tensor names.
881
+ ### OnnxActivationOperation
1013
882
 
1014
- ### PoolingAttributes
883
+ Supported ONNX activation operators recognized during activation import.
1015
884
 
1016
- Pooling tensor attributes for ONNX node payloads.
885
+ ### OnnxActivationOperationResolutionContext
1017
886
 
1018
- ### PoolingEmissionContext
887
+ Activation operation resolution context for one neuron or layer default.
1019
888
 
1020
- Pooling emission context resolved for one layer output.
889
+ ### OnnxActivationParseResult
1021
890
 
1022
- ### RecurrentActivationEmissionContext
891
+ Parsed ONNX activation-node naming payload.
1023
892
 
1024
- Context for selecting and emitting recurrent activation node payload.
893
+ ### OnnxAttribute
1025
894
 
1026
- ### RecurrentGateBlockCollectionContext
895
+ ONNX node attribute payload.
1027
896
 
1028
- Context for collecting one gate parameter block.
897
+ This simplified JSON-first shape is enough for the operators emitted by the
898
+ current exporter. It intentionally avoids protobuf-level complexity while
899
+ still preserving the attribute variants needed by the importer.
1029
900
 
1030
- ### RecurrentGateParameterCollectionResult
901
+ ### OnnxBaseModelBuildContext
1031
902
 
1032
- Flattened recurrent gate parameter vectors for one fused operator.
903
+ Context for constructing a base ONNX model shell.
1033
904
 
1034
- ### RecurrentGateRow
905
+ ### OnnxBuildResolvedOptions
1035
906
 
1036
- One recurrent gate row payload before flatten fold.
907
+ Resolved options used by ONNX model build orchestration.
1037
908
 
1038
- ### RecurrentGateRowCollectionContext
909
+ ### OnnxConvEmissionContext
1039
910
 
1040
- Context for collecting one recurrent gate row (one neuron).
911
+ Context used after resolving Conv mapping for one layer.
1041
912
 
1042
- ### RecurrentGemmEmissionContext
913
+ ### OnnxConvEmissionParams
1043
914
 
1044
- Context for emitting one Gemm node for recurrent single-step export.
915
+ Parameters accepted by Conv layer emission.
1045
916
 
1046
- ### RecurrentGraphNames
917
+ ### OnnxConvKernelCoordinate
1047
918
 
1048
- Derived graph names for one recurrent single-step layer payload.
919
+ Coordinate for one Conv kernel weight lookup.
1049
920
 
1050
- ### RecurrentHeuristicEmissionContext
921
+ ### OnnxConvParameters
1051
922
 
1052
- Context for heuristic recurrent operator emission traversal.
923
+ Flattened Conv parameters for ONNX initializers.
1053
924
 
1054
- ### RecurrentInitializerEmissionContext
925
+ ### OnnxConvTensorNames
1055
926
 
1056
- Context for pushing recurrent initializers into ONNX graph state.
927
+ Tensor names generated for Conv parameters.
1057
928
 
1058
- ### RecurrentInitializerNames
929
+ ### OnnxDimension
1059
930
 
1060
- Initializer tensor names for one single-step recurrent layer.
931
+ One dimension inside an ONNX tensor shape.
1061
932
 
1062
- ### RecurrentInitializerValues
933
+ Use `dim_value` for fixed numeric widths and `dim_param` for symbolic names
934
+ such as a batch dimension.
1063
935
 
1064
- Collected initializer vectors for one single-step recurrent layer.
936
+ ### OnnxExportOptions
1065
937
 
1066
- ### RecurrentLayerEmissionContext
938
+ Options controlling ONNX-like export.
1067
939
 
1068
- Derived execution context for single-step recurrent layer emission.
940
+ These options trade off strictness, portability, and fidelity:
1069
941
 
1070
- ### RecurrentLayerEmissionParams
942
+ - **Strict (default-ish)** export tries to keep the graph easy to interpret:
943
+ layered topology, homogeneous activations per layer, and fully-connected layers.
1071
944
 
1072
- Parameters for single-step recurrent layer emission.
945
+ - **Relaxed** export (`allowPartialConnectivity` / `allowMixedActivations`) can represent
946
+ more networks, but it may generate graphs that are primarily meant for NeatapticTS’s
947
+ importer (and may be less friendly to external ONNX tooling).
1073
948
 
1074
- ### RecurrentRowCollectionContext
949
+ - **Recurrent export** (`allowRecurrent`) is intentionally conservative and currently
950
+ focuses on a constrained single-step representation and optional fused heuristics.
1075
951
 
1076
- Context for collecting one recurrent matrix row.
952
+ Key fields (high-level):
953
+ - `includeMetadata`: includes `metadata_props` with architecture hints.
954
+ - `opset`: numeric opset version stored in the exported model metadata (default is
955
+ resolved by the exporter; commonly 18 in this codebase).
956
+ - `legacyNodeOrdering`: keeps older node ordering for backward compatibility.
957
+ - `conv2dMappings` / `pool2dMappings`: encode conv/pool semantics for fully-connected
958
+ layers via explicit mapping declarations.
1077
959
 
1078
- ### SharedActivationNodeBuildParams
960
+ ### OnnxFusedGateApplicationContext
1079
961
 
1080
- Shared parameters for constructing an activation node payload.
962
+ Gate-weight application context for one reconstructed fused layer.
1081
963
 
1082
- ### SharedGemmNodeBuildParams
964
+ ### OnnxFusedGateRowAssignmentContext
1083
965
 
1084
- Shared parameters for constructing a Gemm node payload.
966
+ Context for assigning one gate-neuron row from flattened ONNX tensors.
1085
967
 
1086
- ### SpecMetadataAppendContext
968
+ ### OnnxFusedLayerNeighborhood
1087
969
 
1088
- Append-a-spec metadata context for JSON-array metadata keys.
970
+ Hidden-layer neighborhood slices around a reconstructed fused layer.
1089
971
 
1090
- ### WeightToleranceComparisonContext
972
+ ### OnnxFusedLayerReconstructionContext
1091
973
 
1092
- Context for comparing two scalar weights with numeric tolerance.
974
+ Execution context for one fused recurrent layer reconstruction.
1093
975
 
1094
- ### NetworkWithOnnxImportPooling
976
+ ### OnnxFusedLayerRuntime
1095
977
 
1096
- Network instance augmented with optional imported ONNX pooling metadata.
978
+ Runtime interface of a reconstructed fused recurrent layer instance.
1097
979
 
1098
- ### OnnxImportArchitectureContext
980
+ The importer only relies on a narrow runtime contract: access to the
981
+ reconstructed nodes, an input wiring hook, and an optional output group that
982
+ can be reconnected to the next restored layer.
1099
983
 
1100
- Shared architecture extraction context with resolved graph dimensions.
984
+ ### OnnxFusedRecurrentKind
1101
985
 
1102
- ### OnnxImportArchitectureResult
986
+ Supported fused recurrent operator families recognized during ONNX import.
1103
987
 
1104
- Parsed architecture dimensions extracted from ONNX import graph payloads.
988
+ ### OnnxFusedRecurrentSpec
1105
989
 
1106
- ### OnnxImportDimensionRecord
990
+ Fused recurrent family specification used during import reconstruction.
1107
991
 
1108
- Loose ONNX shape-dimension record used by legacy import payload access.
992
+ This tells the importer how to interpret one emitted ONNX recurrent family:
993
+ how many gates to expect, what order those gates were serialized in, and
994
+ which gate owns the self-recurrent diagonal replay.
1109
995
 
1110
- ### OnnxImportHiddenLayerSpan
996
+ ### OnnxFusedTensorPayload
1111
997
 
1112
- Hidden-layer span payload with one-based layer numbering and global offset.
998
+ Fused recurrent tensor payload read from ONNX initializers.
1113
999
 
1114
- ### OnnxImportLayerConnectionContext
1000
+ The importer resolves the three recurrent tensor families up front so the
1001
+ reconstruction pass can focus on wiring and row assignment instead of
1002
+ repeatedly re-looking up initializers.
1115
1003
 
1116
- Execution context for assigning one hidden-layer recurrent diagonal tensor.
1004
+ ### OnnxGraph
1117
1005
 
1118
- ### OnnxImportPoolingMetadata
1006
+ Graph body of an ONNX-like model.
1119
1007
 
1120
- Parsed pooling metadata payload attached to imported network instances.
1008
+ The exporter writes three main collections here:
1009
+ - `inputs` and `outputs` describe graph boundaries,
1010
+ - `initializer` stores constant tensors such as weights and biases,
1011
+ - `node` stores the ordered operator payloads that consume those tensors.
1121
1012
 
1122
- ### OnnxImportRecurrentRestorationContext
1013
+ ### OnnxGraphDimensionBuildContext
1123
1014
 
1124
- Context for recurrent self-connection restoration from ONNX metadata and tensors.
1015
+ Context for constructing input/output ONNX graph dimensions.
1125
1016
 
1126
- ### OnnxImportSelfConnectionUpsertContext
1017
+ ### OnnxGraphDimensions
1127
1018
 
1128
- Context for upserting one hidden node self-connection from recurrent weight.
1019
+ Output dimensions used by ONNX graph input/output value info payloads.
1129
1020
 
1130
1021
  ### OnnxImportAggregatedLayerAssignmentContext
1131
1022
 
@@ -1135,6 +1026,14 @@ Context for assigning aggregated dense tensors for one layer.
1135
1026
 
1136
1027
  Context for assigning one aggregated dense target neuron row.
1137
1028
 
1029
+ ### OnnxImportArchitectureContext
1030
+
1031
+ Shared architecture extraction context with resolved graph dimensions.
1032
+
1033
+ ### OnnxImportArchitectureResult
1034
+
1035
+ Parsed architecture dimensions extracted from ONNX import graph payloads.
1036
+
1138
1037
  ### OnnxImportConvCoordinateAssignmentContext
1139
1038
 
1140
1039
  Context for applying Conv weights and bias at one output coordinate.
@@ -1167,6 +1066,14 @@ Coordinate for one Conv output neuron traversal position.
1167
1066
 
1168
1067
  Resolved Conv initializer tensors and dimensions for one layer.
1169
1068
 
1069
+ ### OnnxImportDimensionRecord
1070
+
1071
+ Loose ONNX shape-dimension record used by legacy import payload access.
1072
+
1073
+ ### OnnxImportHiddenLayerSpan
1074
+
1075
+ Hidden-layer span payload with one-based layer numbering and global offset.
1076
+
1170
1077
  ### OnnxImportHiddenSizeDerivationContext
1171
1078
 
1172
1079
  Context for deriving hidden layer sizes from initializer tensors and metadata.
@@ -1175,6 +1082,10 @@ Context for deriving hidden layer sizes from initializer tensors and metadata.
1175
1082
 
1176
1083
  Inbound connection lookup map keyed by source node for one target neuron.
1177
1084
 
1085
+ ### OnnxImportLayerConnectionContext
1086
+
1087
+ Execution context for assigning one hidden-layer recurrent diagonal tensor.
1088
+
1178
1089
  ### OnnxImportLayerNodePair
1179
1090
 
1180
1091
  Node slices for one sequential imported layer assignment pass.
@@ -1199,6 +1110,18 @@ Context for assigning one per-neuron imported target node.
1199
1110
 
1200
1111
  Context for assigning per-neuron tensors for one layer.
1201
1112
 
1113
+ ### OnnxImportPoolingMetadata
1114
+
1115
+ Parsed pooling metadata payload attached to imported network instances.
1116
+
1117
+ ### OnnxImportRecurrentRestorationContext
1118
+
1119
+ Context for recurrent self-connection restoration from ONNX metadata and tensors.
1120
+
1121
+ ### OnnxImportSelfConnectionUpsertContext
1122
+
1123
+ Context for upserting one hidden node self-connection from recurrent weight.
1124
+
1202
1125
  ### OnnxImportWeightAssignmentBuildParams
1203
1126
 
1204
1127
  Build params for creating shared ONNX import weight-assignment context.
@@ -1207,61 +1130,83 @@ Build params for creating shared ONNX import weight-assignment context.
1207
1130
 
1208
1131
  Shared weight-assignment context built once per ONNX import.
1209
1132
 
1210
- ### OnnxFusedGateApplicationContext
1133
+ ### OnnxIncomingWeightAssignmentContext
1211
1134
 
1212
- Gate-weight application context for one reconstructed fused layer.
1135
+ Context for assigning dense incoming weights for one gate-neuron row.
1213
1136
 
1214
- ### OnnxFusedGateRowAssignmentContext
1137
+ ### OnnxLayerEmissionContext
1215
1138
 
1216
- Context for assigning one gate-neuron row from flattened ONNX tensors.
1139
+ Context for emitting non-input layers during model build.
1217
1140
 
1218
- ### OnnxFusedLayerNeighborhood
1141
+ ### OnnxLayerEmissionResult
1219
1142
 
1220
- Hidden-layer neighborhood slices around a reconstructed fused layer.
1143
+ Result of emitting non-input export layers.
1221
1144
 
1222
- ### OnnxFusedLayerReconstructionContext
1145
+ ### OnnxLayerFactory
1223
1146
 
1224
- Execution context for one fused recurrent layer reconstruction.
1147
+ Runtime factory map used to construct dynamic recurrent layer modules.
1225
1148
 
1226
- ### OnnxFusedLayerRuntime
1149
+ ### OnnxMetadataProperty
1227
1150
 
1228
- Runtime interface of a reconstructed fused recurrent layer instance.
1151
+ Canonical metadata key-value pair used in ONNX model metadata_props.
1229
1152
 
1230
- The importer only relies on a narrow runtime contract: access to the
1231
- reconstructed nodes, an input wiring hook, and an optional output group that
1232
- can be reconnected to the next restored layer.
1153
+ ### OnnxModel
1233
1154
 
1234
- ### OnnxFusedRecurrentKind
1155
+ ONNX-like model container (JSON-serializable).
1235
1156
 
1236
- Supported fused recurrent operator families recognized during ONNX import.
1157
+ This is the main “wire format” object in this folder. Persist it as JSON text:
1237
1158
 
1238
- ### OnnxFusedRecurrentSpec
1159
+ ```ts
1160
+ const jsonText = JSON.stringify(model);
1161
+ const restoredModel = JSON.parse(jsonText) as OnnxModel;
1162
+ ```
1239
1163
 
1240
- Fused recurrent family specification used during import reconstruction.
1164
+ Notes:
1165
+ - `metadata_props` contains NeatapticTS-specific keys (layer sizes, recurrent flags,
1166
+ conv/pool mappings, etc.). This is where most round-trip hints live.
1167
+ - Initializers currently store floating-point weights in `float_data`.
1241
1168
 
1242
- This tells the importer how to interpret one emitted ONNX recurrent family:
1243
- how many gates to expect, what order those gates were serialized in, and
1244
- which gate owns the self-recurrent diagonal replay.
1169
+ Security/trust boundary:
1170
+ - Treat this as untrusted input if it comes from outside your process.
1245
1171
 
1246
- ### OnnxFusedTensorPayload
1172
+ ### OnnxModelMetadataContext
1247
1173
 
1248
- Fused recurrent tensor payload read from ONNX initializers.
1174
+ Context for applying optional ONNX model metadata.
1249
1175
 
1250
- The importer resolves the three recurrent tensor families up front so the
1251
- reconstruction pass can focus on wiring and row assignment instead of
1252
- repeatedly re-looking up initializers.
1176
+ ### OnnxNode
1253
1177
 
1254
- ### OnnxIncomingWeightAssignmentContext
1178
+ One ONNX operator invocation inside the graph.
1179
+
1180
+ Nodes connect named tensors rather than object references, which keeps the
1181
+ exported payload easy to serialize, inspect, and diff as plain JSON.
1182
+
1183
+ ### OnnxPerceptronBuildContext
1184
+
1185
+ Build context for mapping ONNX layer sizes into a Neataptic MLP factory call.
1186
+
1187
+ ### OnnxPerceptronSizeValidationContext
1188
+
1189
+ Validation context for perceptron size-list checks during ONNX import.
1190
+
1191
+ ### OnnxPostProcessingContext
1192
+
1193
+ Context for post-processing and export metadata finalization.
1194
+
1195
+ ### OnnxRecurrentCollectionContext
1196
+
1197
+ Context for collecting recurrent layer indices during model build.
1198
+
1199
+ ### OnnxRecurrentInputValueInfoContext
1255
1200
 
1256
- Context for assigning dense incoming weights for one gate-neuron row.
1201
+ Context for constructing one recurrent previous-state graph input payload.
1257
1202
 
1258
- ### OnnxPerceptronBuildContext
1203
+ ### OnnxRecurrentLayerProcessingContext
1259
1204
 
1260
- Build context for mapping ONNX layer sizes into a Neataptic MLP factory call.
1205
+ Execution context for processing one hidden recurrent layer.
1261
1206
 
1262
- ### OnnxPerceptronSizeValidationContext
1207
+ ### OnnxRecurrentLayerTraversalContext
1263
1208
 
1264
- Validation context for perceptron size-list checks during ONNX import.
1209
+ Traversal context for one hidden layer during recurrent-input collection.
1265
1210
 
1266
1211
  ### OnnxRuntimeFactories
1267
1212
 
@@ -1277,6 +1222,10 @@ OnnxRuntimeLayerFactory(
1277
1222
 
1278
1223
  Runtime layer-constructor signature used for recurrent layer reconstruction.
1279
1224
 
1225
+ ### OnnxRuntimeLayerFactoryMap
1226
+
1227
+ Runtime layer module shape widened for fused-recurrent reconstruction wiring.
1228
+
1280
1229
  ### OnnxRuntimeLayerModule
1281
1230
 
1282
1231
  Runtime layer module shape consumed by ONNX import orchestration.
@@ -1291,242 +1240,261 @@ OnnxRuntimePerceptronFactory(
1291
1240
 
1292
1241
  Runtime perceptron factory signature used by ONNX import orchestration.
1293
1242
 
1294
- ### NodeInternals
1243
+ ### OnnxShape
1295
1244
 
1296
- Runtime interface for accessing node internal properties.
1245
+ ONNX tensor type shape.
1297
1246
 
1298
- This is intentionally "internal": it exposes mutable fields that the ONNX exporter/importer
1299
- needs (connections, bias, squash). Regular library users should generally interact with
1300
- the public `Node` API instead.
1247
+ ### OnnxTensor
1301
1248
 
1302
- ### NodeInternalsWithExportIndex
1249
+ Serialized tensor payload stored inside graph initializers.
1303
1250
 
1304
- Runtime node internals augmented with optional export index metadata.
1251
+ NeatapticTS currently writes floating-point parameter vectors and matrices to
1252
+ `float_data`, along with the tensor name, element type, and logical shape.
1305
1253
 
1306
- ### ActivationFunction
1254
+ ### OnnxTensorType
1307
1255
 
1308
- ```ts
1309
- ActivationFunction(
1310
- x: number,
1311
- derivate: boolean | undefined,
1312
- ): number
1313
- ```
1256
+ ONNX tensor type.
1314
1257
 
1315
- Runtime activation function signature used by ONNX activation import/export paths.
1258
+ ### OnnxValueInfo
1316
1259
 
1317
- Neataptic-style activations support a dual-purpose call pattern:
1318
- - `derivate === false | undefined`: return activation output $f(x)$
1319
- - `derivate === true`: return derivative $f'(x)$
1260
+ ONNX value info (input/output description).
1320
1261
 
1321
- This matches historical Neataptic semantics and keeps ONNX import/export compatible.
1262
+ ### OptionalLayerOutputParams
1322
1263
 
1323
- Example:
1264
+ Shared parameters for optional pooling/flatten output emission.
1324
1265
 
1325
- ```ts
1326
- const y = activation(x);
1327
- const dy = activation(x, true);
1328
- ```
1266
+ ### OptionalPoolingAndFlattenParams
1329
1267
 
1330
- ### LayerOrderingNodeGroups
1268
+ Parameters for optional pooling + flatten emission after a layer output.
1331
1269
 
1332
- Node partitions used by ONNX layered-ordering inference traversal.
1270
+ ### OutputLayerActivationContext
1333
1271
 
1334
- ### LayerOrderingResolutionContext
1272
+ Output-layer activation assignment context.
1335
1273
 
1336
- Mutable traversal state while resolving hidden-layer ordering.
1274
+ ### PerNeuronConcatNodePayload
1337
1275
 
1338
- ### LayerValidationTraversalContext
1276
+ Per-neuron concat node payload.
1339
1277
 
1340
- Layer-wise validation context for activation and connectivity checks.
1278
+ ### PerNeuronGraphNames
1341
1279
 
1342
- ### LayerActivationValidationContext
1280
+ Per-neuron graph tensor names.
1343
1281
 
1344
- Activation-homogeneity decision context for one current layer.
1282
+ ### PerNeuronLayerContext
1345
1283
 
1346
- ### LayerConnectivityValidationContext
1284
+ Per-neuron layer context alias.
1347
1285
 
1348
- Connectivity decision context for one source-target node pair.
1286
+ ### PerNeuronLayerParams
1349
1287
 
1350
- ### OnnxActivationOperation
1288
+ Parameters for per-neuron layer emission.
1351
1289
 
1352
- Supported ONNX activation operators recognized during activation import.
1290
+ ### PerNeuronNodeContext
1353
1291
 
1354
- ### OnnxActivationLayerOperations
1292
+ Per-neuron normalized node context.
1355
1293
 
1356
- Layer-indexed activation operator lookup extracted from ONNX graph nodes.
1294
+ ### PerNeuronSubgraphContext
1357
1295
 
1358
- ### OnnxActivationParseResult
1296
+ Per-neuron subgraph emission context.
1359
1297
 
1360
- Parsed ONNX activation-node naming payload.
1298
+ ### PerNeuronTensorNames
1361
1299
 
1362
- ### OnnxActivationAssignmentContext
1300
+ Per-neuron initializer tensor names.
1363
1301
 
1364
- Shared activation-assignment context for hidden and output traversal.
1302
+ ### Pool2DMapping
1365
1303
 
1366
- ### HiddenLayerActivationTraversalContext
1304
+ Mapping describing a pooling operation inserted after a given export-layer index.
1367
1305
 
1368
- Hidden-layer traversal context for assigning imported activation functions.
1306
+ This is represented as metadata and optional graph nodes during export.
1307
+ Import uses it to attach pooling-related runtime metadata back onto the reconstructed
1308
+ network (when supported).
1369
1309
 
1370
- ### OutputLayerActivationContext
1310
+ ### PoolingAttributes
1371
1311
 
1372
- Output-layer activation assignment context.
1312
+ Pooling tensor attributes for ONNX node payloads.
1373
1313
 
1374
- ### OnnxActivationOperationResolutionContext
1314
+ ### PoolingEmissionContext
1375
1315
 
1376
- Activation operation resolution context for one neuron or layer default.
1316
+ Pooling emission context resolved for one layer output.
1377
1317
 
1378
- ### OnnxConvKernelCoordinate
1318
+ ### RecurrentActivationEmissionContext
1379
1319
 
1380
- Coordinate for one Conv kernel weight lookup.
1320
+ Context for selecting and emitting recurrent activation node payload.
1381
1321
 
1382
- ### OnnxLayerFactory
1322
+ ### RecurrentGateBlockCollectionContext
1383
1323
 
1384
- Runtime factory map used to construct dynamic recurrent layer modules.
1324
+ Context for collecting one gate parameter block.
1385
1325
 
1386
- ### OnnxRuntimeLayerFactoryMap
1326
+ ### RecurrentGateParameterCollectionResult
1387
1327
 
1388
- Runtime layer module shape widened for fused-recurrent reconstruction wiring.
1328
+ Flattened recurrent gate parameter vectors for one fused operator.
1389
1329
 
1390
- ## architecture/network/onnx/network.onnx.layer-analysis.utils.ts
1330
+ ### RecurrentGateRow
1391
1331
 
1392
- ### rebuildConnectionsLocal
1332
+ One recurrent gate row payload before flatten fold.
1393
1333
 
1394
- ```ts
1395
- rebuildConnectionsLocal(
1396
- networkLike: default,
1397
- ): void
1398
- ```
1334
+ ### RecurrentGateRowCollectionContext
1399
1335
 
1400
- Rebuild the network's flat connections array from each node's outgoing list.
1336
+ Context for collecting one recurrent gate row (one neuron).
1401
1337
 
1402
- Parameters:
1403
- - `networkLike` - Network-like instance to mutate.
1338
+ ### RecurrentGemmEmissionContext
1404
1339
 
1405
- Returns: Nothing.
1340
+ Context for emitting one Gemm node for recurrent single-step export.
1406
1341
 
1407
- ### mapActivationToOnnx
1342
+ ### RecurrentGraphNames
1408
1343
 
1409
- ```ts
1410
- mapActivationToOnnx(
1411
- squash: ((x: number, derivate?: boolean | undefined) => number) & { name?: string | undefined; },
1412
- ): OnnxActivationOperation
1413
- ```
1344
+ Derived graph names for one recurrent single-step layer payload.
1414
1345
 
1415
- Map an internal activation function (squash) to an ONNX op_type.
1346
+ ### RecurrentHeuristicEmissionContext
1416
1347
 
1417
- Parameters:
1418
- - `squash` - Activation function reference.
1348
+ Context for heuristic recurrent operator emission traversal.
1419
1349
 
1420
- Returns: ONNX activation operator name.
1350
+ ### RecurrentInitializerEmissionContext
1421
1351
 
1422
- ### inferLayerOrdering
1352
+ Context for pushing recurrent initializers into ONNX graph state.
1353
+
1354
+ ### RecurrentInitializerNames
1355
+
1356
+ Initializer tensor names for one single-step recurrent layer.
1357
+
1358
+ ### RecurrentInitializerValues
1359
+
1360
+ Collected initializer vectors for one single-step recurrent layer.
1361
+
1362
+ ### RecurrentLayerEmissionContext
1363
+
1364
+ Derived execution context for single-step recurrent layer emission.
1365
+
1366
+ ### RecurrentLayerEmissionParams
1367
+
1368
+ Parameters for single-step recurrent layer emission.
1369
+
1370
+ ### RecurrentRowCollectionContext
1371
+
1372
+ Context for collecting one recurrent matrix row.
1373
+
1374
+ ### SharedActivationNodeBuildParams
1375
+
1376
+ Shared parameters for constructing an activation node payload.
1377
+
1378
+ ### SharedGemmNodeBuildParams
1379
+
1380
+ Shared parameters for constructing a Gemm node payload.
1381
+
1382
+ ### SpecMetadataAppendContext
1383
+
1384
+ Append-a-spec metadata context for JSON-array metadata keys.
1385
+
1386
+ ### WeightToleranceComparisonContext
1387
+
1388
+ Context for comparing two scalar weights with numeric tolerance.
1389
+
1390
+ ## architecture/network/onnx/network.onnx.layer-analysis.utils.ts
1391
+
1392
+ ### appendLastResolvedLayer
1423
1393
 
1424
1394
  ```ts
1425
- inferLayerOrdering(
1426
- network: default,
1427
- ): default[][]
1395
+ appendLastResolvedLayer(
1396
+ resolutionContext: LayerOrderingResolutionContext,
1397
+ ): LayerOrderingResolutionContext
1428
1398
  ```
1429
1399
 
1430
- Infer strictly layered ordering from a network.
1400
+ Append the final resolved hidden layer into ordered layer output.
1431
1401
 
1432
1402
  Parameters:
1433
- - `network` - Source network.
1403
+ - `resolutionContext` - Final traversal state before append.
1434
1404
 
1435
- Returns: Ordered layers: input, hidden..., output.
1405
+ Returns: Traversal state with last hidden layer persisted.
1436
1406
 
1437
- ### validateLayerHomogeneityAndConnectivity
1407
+ ### buildLayerValidationContexts
1438
1408
 
1439
1409
  ```ts
1440
- validateLayerHomogeneityAndConnectivity(
1410
+ buildLayerValidationContexts(
1441
1411
  layers: default[][],
1442
- network: default,
1443
1412
  options: OnnxExportOptions,
1444
- ): void
1413
+ ): LayerValidationTraversalContext[]
1445
1414
  ```
1446
1415
 
1447
- Validate connectivity and activation homogeneity constraints per layer.
1416
+ Build per-layer validation contexts for all non-input layers.
1448
1417
 
1449
1418
  Parameters:
1450
- - `layers` - Layered node arrays.
1451
- - `network` - Source network (reserved for compatibility).
1452
- - `options` - Export options.
1419
+ - `layers` - Ordered network layers.
1420
+ - `options` - ONNX export options.
1453
1421
 
1454
- Returns: Nothing.
1422
+ Returns: Traversal contexts used by layer validators.
1455
1423
 
1456
- ### collectUniqueOutgoingConnections
1424
+ ### collectCurrentResolvableHiddenLayer
1457
1425
 
1458
1426
  ```ts
1459
- collectUniqueOutgoingConnections(
1460
- nodes: default[],
1427
+ collectCurrentResolvableHiddenLayer(
1428
+ resolutionContext: LayerOrderingResolutionContext,
1461
1429
  ): default[]
1462
1430
  ```
1463
1431
 
1464
- Collect unique outgoing connections across a node list.
1432
+ Collect unresolved hidden nodes that can be placed in the next layer.
1465
1433
 
1466
1434
  Parameters:
1467
- - `nodes` - Nodes to traverse.
1435
+ - `resolutionContext` - Current hidden-layer resolution context.
1468
1436
 
1469
- Returns: Stable array of unique connections.
1437
+ Returns: Hidden nodes that are resolvable in this pass.
1470
1438
 
1471
- ### normalizeActivationName
1439
+ ### collectLayerOrderingNodeGroups
1472
1440
 
1473
1441
  ```ts
1474
- normalizeActivationName(
1475
- squash: ((x: number, derivate?: boolean | undefined) => number) & { name?: string | undefined; },
1476
- ): string
1442
+ collectLayerOrderingNodeGroups(
1443
+ network: default,
1444
+ ): LayerOrderingNodeGroups
1477
1445
  ```
1478
1446
 
1479
- Normalize activation function name to uppercase for token matching.
1447
+ Partition all network nodes into input/hidden/output groups.
1480
1448
 
1481
1449
  Parameters:
1482
- - `squash` - Runtime activation function reference.
1450
+ - `network` - Source network.
1483
1451
 
1484
- Returns: Uppercased activation name or empty string.
1452
+ Returns: Node groups used by layered-ordering inference.
1485
1453
 
1486
- ### resolveOnnxActivationOperation
1454
+ ### collectUniqueOutgoingConnections
1487
1455
 
1488
1456
  ```ts
1489
- resolveOnnxActivationOperation(
1490
- normalizedActivationName: string,
1491
- ): OnnxActivationOperation
1457
+ collectUniqueOutgoingConnections(
1458
+ nodes: default[],
1459
+ ): default[]
1492
1460
  ```
1493
1461
 
1494
- Resolve ONNX activation op from a normalized activation name token.
1462
+ Collect unique outgoing connections across a node list.
1495
1463
 
1496
1464
  Parameters:
1497
- - `normalizedActivationName` - Uppercased activation name.
1465
+ - `nodes` - Nodes to traverse.
1498
1466
 
1499
- Returns: ONNX activation operation.
1467
+ Returns: Stable array of unique connections.
1500
1468
 
1501
- ### warnWhenActivationFallbackIsUsed
1469
+ ### createLayerActivationValidationContext
1502
1470
 
1503
1471
  ```ts
1504
- warnWhenActivationFallbackIsUsed(
1505
- context: { squash: ((x: number, derivate?: boolean | undefined) => number) & { name?: string | undefined; }; resolvedActivationOperation: OnnxActivationOperation; },
1506
- ): void
1472
+ createLayerActivationValidationContext(
1473
+ layerValidationContext: LayerValidationTraversalContext,
1474
+ ): LayerActivationValidationContext
1507
1475
  ```
1508
1476
 
1509
- Emit a warning when activation export falls back to Identity.
1477
+ Create activation validation context from one layer traversal context.
1510
1478
 
1511
1479
  Parameters:
1512
- - `context` - Activation fallback evaluation context.
1480
+ - `layerValidationContext` - Layer validation context.
1513
1481
 
1514
- Returns: Nothing.
1482
+ Returns: Activation validation context.
1515
1483
 
1516
- ### collectLayerOrderingNodeGroups
1484
+ ### ensureLayerWasResolved
1517
1485
 
1518
1486
  ```ts
1519
- collectLayerOrderingNodeGroups(
1520
- network: default,
1521
- ): LayerOrderingNodeGroups
1487
+ ensureLayerWasResolved(
1488
+ currentLayerNodes: default[],
1489
+ ): void
1522
1490
  ```
1523
1491
 
1524
- Partition all network nodes into input/hidden/output groups.
1492
+ Ensure current hidden-layer resolution pass produced at least one node.
1525
1493
 
1526
1494
  Parameters:
1527
- - `network` - Source network.
1495
+ - `currentLayerNodes` - Nodes resolved for current layer.
1528
1496
 
1529
- Returns: Node groups used by layered-ordering inference.
1497
+ Returns: Nothing.
1530
1498
 
1531
1499
  ### filterNodesByType
1532
1500
 
@@ -1545,20 +1513,20 @@ Parameters:
1545
1513
 
1546
1514
  Returns: Matching nodes.
1547
1515
 
1548
- ### hasNoHiddenNodes
1516
+ ### filterUnresolvedHiddenNodes
1549
1517
 
1550
1518
  ```ts
1551
- hasNoHiddenNodes(
1552
- nodeGroups: LayerOrderingNodeGroups,
1553
- ): boolean
1519
+ filterUnresolvedHiddenNodes(
1520
+ context: { remainingHiddenNodes: default[]; currentLayerNodes: default[]; },
1521
+ ): default[]
1554
1522
  ```
1555
1523
 
1556
- Check whether the layer groups contain no hidden nodes.
1524
+ Remove just-resolved hidden nodes from unresolved candidates.
1557
1525
 
1558
1526
  Parameters:
1559
- - `nodeGroups` - Partitioned node groups.
1527
+ - `context` - Remaining/just-resolved hidden node context.
1560
1528
 
1561
- Returns: True when hidden layer traversal can be skipped.
1529
+ Returns: Hidden nodes still unresolved.
1562
1530
 
1563
1531
  ### finalizeOrderingWithoutHiddenNodes
1564
1532
 
@@ -1575,215 +1543,247 @@ Parameters:
1575
1543
 
1576
1544
  Returns: Input and output layers only.
1577
1545
 
1578
- ### initializeLayerOrderingResolutionContext
1546
+ ### finalizeOrderingWithOutputLayer
1579
1547
 
1580
1548
  ```ts
1581
- initializeLayerOrderingResolutionContext(
1549
+ finalizeOrderingWithOutputLayer(
1550
+ context: { orderedLayers: default[][]; outputNodes: default[]; },
1551
+ ): default[][]
1552
+ ```
1553
+
1554
+ Append output layer to resolved input/hidden ordering.
1555
+
1556
+ Parameters:
1557
+ - `context` - Final ordering context.
1558
+
1559
+ Returns: Full layer ordering including output layer.
1560
+
1561
+ ### hasAllIncomingConnectionsFromPreviousLayer
1562
+
1563
+ ```ts
1564
+ hasAllIncomingConnectionsFromPreviousLayer(
1565
+ context: { hiddenNode: default; previousLayerNodes: default[]; },
1566
+ ): boolean
1567
+ ```
1568
+
1569
+ Check whether a hidden node receives all inputs from the previous layer.
1570
+
1571
+ Parameters:
1572
+ - `context` - Hidden-node connectivity check context.
1573
+
1574
+ Returns: True when the hidden node is layer-resolvable.
1575
+
1576
+ ### hasNoHiddenNodes
1577
+
1578
+ ```ts
1579
+ hasNoHiddenNodes(
1582
1580
  nodeGroups: LayerOrderingNodeGroups,
1583
- ): LayerOrderingResolutionContext
1581
+ ): boolean
1584
1582
  ```
1585
1583
 
1586
- Create initial hidden-layer resolution context.
1584
+ Check whether the layer groups contain no hidden nodes.
1587
1585
 
1588
1586
  Parameters:
1589
1587
  - `nodeGroups` - Partitioned node groups.
1590
1588
 
1591
- Returns: Initial mutable state for hidden-layer resolution.
1589
+ Returns: True when hidden layer traversal can be skipped.
1592
1590
 
1593
- ### resolveAllHiddenLayers
1591
+ ### inferLayerOrdering
1594
1592
 
1595
1593
  ```ts
1596
- resolveAllHiddenLayers(
1597
- initialContext: LayerOrderingResolutionContext,
1598
- ): LayerOrderingResolutionContext
1594
+ inferLayerOrdering(
1595
+ network: default,
1596
+ ): default[][]
1599
1597
  ```
1600
1598
 
1601
- Resolve all hidden layers in dependency order.
1599
+ Infer strictly layered ordering from a network.
1602
1600
 
1603
1601
  Parameters:
1604
- - `initialContext` - Starting hidden-layer resolution context.
1602
+ - `network` - Source network.
1605
1603
 
1606
- Returns: Final resolved layer-ordering context.
1604
+ Returns: Ordered layers: input, hidden..., output.
1607
1605
 
1608
- ### resolveNextHiddenLayer
1606
+ ### initializeLayerOrderingResolutionContext
1609
1607
 
1610
1608
  ```ts
1611
- resolveNextHiddenLayer(
1612
- resolutionContext: LayerOrderingResolutionContext,
1609
+ initializeLayerOrderingResolutionContext(
1610
+ nodeGroups: LayerOrderingNodeGroups,
1613
1611
  ): LayerOrderingResolutionContext
1614
1612
  ```
1615
1613
 
1616
- Resolve the next hidden layer from unresolved candidates.
1614
+ Create initial hidden-layer resolution context.
1617
1615
 
1618
1616
  Parameters:
1619
- - `resolutionContext` - Current resolution state.
1617
+ - `nodeGroups` - Partitioned node groups.
1620
1618
 
1621
- Returns: Updated resolution state.
1619
+ Returns: Initial mutable state for hidden-layer resolution.
1622
1620
 
1623
- ### collectCurrentResolvableHiddenLayer
1621
+ ### mapActivationToOnnx
1624
1622
 
1625
1623
  ```ts
1626
- collectCurrentResolvableHiddenLayer(
1627
- resolutionContext: LayerOrderingResolutionContext,
1628
- ): default[]
1624
+ mapActivationToOnnx(
1625
+ squash: ((x: number, derivate?: boolean | undefined) => number) & { name?: string | undefined; },
1626
+ ): OnnxActivationOperation
1629
1627
  ```
1630
1628
 
1631
- Collect unresolved hidden nodes that can be placed in the next layer.
1629
+ Map an internal activation function (squash) to an ONNX op_type.
1632
1630
 
1633
1631
  Parameters:
1634
- - `resolutionContext` - Current hidden-layer resolution context.
1632
+ - `squash` - Activation function reference.
1635
1633
 
1636
- Returns: Hidden nodes that are resolvable in this pass.
1634
+ Returns: ONNX activation operator name.
1637
1635
 
1638
- ### hasAllIncomingConnectionsFromPreviousLayer
1636
+ ### normalizeActivationName
1639
1637
 
1640
1638
  ```ts
1641
- hasAllIncomingConnectionsFromPreviousLayer(
1642
- context: { hiddenNode: default; previousLayerNodes: default[]; },
1643
- ): boolean
1639
+ normalizeActivationName(
1640
+ squash: ((x: number, derivate?: boolean | undefined) => number) & { name?: string | undefined; },
1641
+ ): string
1644
1642
  ```
1645
1643
 
1646
- Check whether a hidden node receives all inputs from the previous layer.
1644
+ Normalize activation function name to uppercase for token matching.
1647
1645
 
1648
1646
  Parameters:
1649
- - `context` - Hidden-node connectivity check context.
1647
+ - `squash` - Runtime activation function reference.
1650
1648
 
1651
- Returns: True when the hidden node is layer-resolvable.
1649
+ Returns: Uppercased activation name or empty string.
1652
1650
 
1653
- ### ensureLayerWasResolved
1651
+ ### rebuildConnectionsLocal
1654
1652
 
1655
1653
  ```ts
1656
- ensureLayerWasResolved(
1657
- currentLayerNodes: default[],
1654
+ rebuildConnectionsLocal(
1655
+ networkLike: default,
1658
1656
  ): void
1659
1657
  ```
1660
1658
 
1661
- Ensure current hidden-layer resolution pass produced at least one node.
1659
+ Rebuild the network's flat connections array from each node's outgoing list.
1662
1660
 
1663
1661
  Parameters:
1664
- - `currentLayerNodes` - Nodes resolved for current layer.
1662
+ - `networkLike` - Network-like instance to mutate.
1665
1663
 
1666
1664
  Returns: Nothing.
1667
1665
 
1668
- ### filterUnresolvedHiddenNodes
1666
+ ### resolveAllHiddenLayers
1669
1667
 
1670
1668
  ```ts
1671
- filterUnresolvedHiddenNodes(
1672
- context: { remainingHiddenNodes: default[]; currentLayerNodes: default[]; },
1673
- ): default[]
1669
+ resolveAllHiddenLayers(
1670
+ initialContext: LayerOrderingResolutionContext,
1671
+ ): LayerOrderingResolutionContext
1674
1672
  ```
1675
1673
 
1676
- Remove just-resolved hidden nodes from unresolved candidates.
1674
+ Resolve all hidden layers in dependency order.
1677
1675
 
1678
1676
  Parameters:
1679
- - `context` - Remaining/just-resolved hidden node context.
1677
+ - `initialContext` - Starting hidden-layer resolution context.
1680
1678
 
1681
- Returns: Hidden nodes still unresolved.
1679
+ Returns: Final resolved layer-ordering context.
1682
1680
 
1683
- ### appendLastResolvedLayer
1681
+ ### resolveNextHiddenLayer
1684
1682
 
1685
1683
  ```ts
1686
- appendLastResolvedLayer(
1684
+ resolveNextHiddenLayer(
1687
1685
  resolutionContext: LayerOrderingResolutionContext,
1688
1686
  ): LayerOrderingResolutionContext
1689
1687
  ```
1690
1688
 
1691
- Append the final resolved hidden layer into ordered layer output.
1689
+ Resolve the next hidden layer from unresolved candidates.
1692
1690
 
1693
1691
  Parameters:
1694
- - `resolutionContext` - Final traversal state before append.
1692
+ - `resolutionContext` - Current resolution state.
1695
1693
 
1696
- Returns: Traversal state with last hidden layer persisted.
1694
+ Returns: Updated resolution state.
1697
1695
 
1698
- ### finalizeOrderingWithOutputLayer
1696
+ ### resolveOnnxActivationOperation
1699
1697
 
1700
1698
  ```ts
1701
- finalizeOrderingWithOutputLayer(
1702
- context: { orderedLayers: default[][]; outputNodes: default[]; },
1703
- ): default[][]
1699
+ resolveOnnxActivationOperation(
1700
+ normalizedActivationName: string,
1701
+ ): OnnxActivationOperation
1704
1702
  ```
1705
1703
 
1706
- Append output layer to resolved input/hidden ordering.
1704
+ Resolve ONNX activation op from a normalized activation name token.
1707
1705
 
1708
1706
  Parameters:
1709
- - `context` - Final ordering context.
1707
+ - `normalizedActivationName` - Uppercased activation name.
1710
1708
 
1711
- Returns: Full layer ordering including output layer.
1709
+ Returns: ONNX activation operation.
1712
1710
 
1713
- ### buildLayerValidationContexts
1711
+ ### validateLayerActivationHomogeneity
1714
1712
 
1715
1713
  ```ts
1716
- buildLayerValidationContexts(
1717
- layers: default[][],
1718
- options: OnnxExportOptions,
1719
- ): LayerValidationTraversalContext[]
1714
+ validateLayerActivationHomogeneity(
1715
+ activationValidationContext: LayerActivationValidationContext,
1716
+ ): void
1720
1717
  ```
1721
1718
 
1722
- Build per-layer validation contexts for all non-input layers.
1719
+ Validate that a layer has homogeneous activation unless explicitly allowed.
1723
1720
 
1724
1721
  Parameters:
1725
- - `layers` - Ordered network layers.
1726
- - `options` - ONNX export options.
1722
+ - `activationValidationContext` - Activation validation context.
1727
1723
 
1728
- Returns: Traversal contexts used by layer validators.
1724
+ Returns: Nothing.
1729
1725
 
1730
- ### validateSingleLayer
1726
+ ### validateLayerConnectivity
1731
1727
 
1732
1728
  ```ts
1733
- validateSingleLayer(
1729
+ validateLayerConnectivity(
1734
1730
  layerValidationContext: LayerValidationTraversalContext,
1735
1731
  ): void
1736
1732
  ```
1737
1733
 
1738
- Validate one current layer against activation/connectivity constraints.
1734
+ Validate that each current-layer node has required incoming connectivity.
1739
1735
 
1740
1736
  Parameters:
1741
- - `layerValidationContext` - Layer validation context.
1737
+ - `layerValidationContext` - Layer connectivity traversal context.
1742
1738
 
1743
1739
  Returns: Nothing.
1744
1740
 
1745
- ### createLayerActivationValidationContext
1741
+ ### validateLayerHomogeneityAndConnectivity
1746
1742
 
1747
1743
  ```ts
1748
- createLayerActivationValidationContext(
1749
- layerValidationContext: LayerValidationTraversalContext,
1750
- ): LayerActivationValidationContext
1744
+ validateLayerHomogeneityAndConnectivity(
1745
+ layers: default[][],
1746
+ network: default,
1747
+ options: OnnxExportOptions,
1748
+ ): void
1751
1749
  ```
1752
1750
 
1753
- Create activation validation context from one layer traversal context.
1751
+ Validate connectivity and activation homogeneity constraints per layer.
1754
1752
 
1755
1753
  Parameters:
1756
- - `layerValidationContext` - Layer validation context.
1754
+ - `layers` - Layered node arrays.
1755
+ - `network` - Source network (reserved for compatibility).
1756
+ - `options` - Export options.
1757
1757
 
1758
- Returns: Activation validation context.
1758
+ Returns: Nothing.
1759
1759
 
1760
- ### validateLayerActivationHomogeneity
1760
+ ### validateSingleLayer
1761
1761
 
1762
1762
  ```ts
1763
- validateLayerActivationHomogeneity(
1764
- activationValidationContext: LayerActivationValidationContext,
1763
+ validateSingleLayer(
1764
+ layerValidationContext: LayerValidationTraversalContext,
1765
1765
  ): void
1766
1766
  ```
1767
1767
 
1768
- Validate that a layer has homogeneous activation unless explicitly allowed.
1768
+ Validate one current layer against activation/connectivity constraints.
1769
1769
 
1770
1770
  Parameters:
1771
- - `activationValidationContext` - Activation validation context.
1771
+ - `layerValidationContext` - Layer validation context.
1772
1772
 
1773
1773
  Returns: Nothing.
1774
1774
 
1775
- ### validateLayerConnectivity
1775
+ ### validateSourceToTargetConnectivity
1776
1776
 
1777
1777
  ```ts
1778
- validateLayerConnectivity(
1779
- layerValidationContext: LayerValidationTraversalContext,
1778
+ validateSourceToTargetConnectivity(
1779
+ connectivityValidationContext: LayerConnectivityValidationContext,
1780
1780
  ): void
1781
1781
  ```
1782
1782
 
1783
- Validate that each current-layer node has required incoming connectivity.
1783
+ Validate one source->target connection pair under export constraints.
1784
1784
 
1785
1785
  Parameters:
1786
- - `layerValidationContext` - Layer connectivity traversal context.
1786
+ - `connectivityValidationContext` - Source/target connectivity context.
1787
1787
 
1788
1788
  Returns: Nothing.
1789
1789
 
@@ -1802,17 +1802,17 @@ Parameters:
1802
1802
 
1803
1803
  Returns: Nothing.
1804
1804
 
1805
- ### validateSourceToTargetConnectivity
1805
+ ### warnWhenActivationFallbackIsUsed
1806
1806
 
1807
1807
  ```ts
1808
- validateSourceToTargetConnectivity(
1809
- connectivityValidationContext: LayerConnectivityValidationContext,
1808
+ warnWhenActivationFallbackIsUsed(
1809
+ context: { squash: ((x: number, derivate?: boolean | undefined) => number) & { name?: string | undefined; }; resolvedActivationOperation: OnnxActivationOperation; },
1810
1810
  ): void
1811
1811
  ```
1812
1812
 
1813
- Validate one source->target connection pair under export constraints.
1813
+ Emit a warning when activation export falls back to Identity.
1814
1814
 
1815
1815
  Parameters:
1816
- - `connectivityValidationContext` - Source/target connectivity context.
1816
+ - `context` - Activation fallback evaluation context.
1817
1817
 
1818
1818
  Returns: Nothing.