@reicek/neataptic-ts 0.1.26 → 0.1.27

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 (123) hide show
  1. package/.github/agents/boundary-mapper.agent.md +13 -8
  2. package/.github/agents/docs-scout.agent.md +14 -9
  3. package/.github/agents/plan-scout.agent.md +11 -6
  4. package/.github/agents/solid-split.agent.md +33 -17
  5. package/.github/copilot-instructions.md +100 -88
  6. package/.github/skills/educational-docs/SKILL.md +90 -40
  7. package/.github/skills/educational-docs/assets/mermaid-diagram-playbook.md +141 -141
  8. package/.github/skills/educational-docs/assets/visual-style-guide.md +1 -1
  9. package/.github/skills/plan-alignment/SKILL.md +1 -1
  10. package/.github/skills/solid-split/SKILL.md +54 -35
  11. package/.github/skills/solid-split/assets/docs-checklist.md +1 -1
  12. package/.github/skills/solid-split/assets/split-plan-template.md +41 -12
  13. package/.github/skills/solid-split/assets/split-workflow-checklist.md +4 -1
  14. package/.github/skills/test-fix-workflow/SKILL.md +12 -7
  15. package/.github/skills/trace-analyzer-extension/SKILL.md +1 -1
  16. package/.github/skills/trace-analyzer-extension/assets/extension-checklist.md +1 -1
  17. package/.github/skills/trace-analyzer-extension/references/analyzer-extension-workflow.md +1 -1
  18. package/.github/skills/trace-audit-reporting/SKILL.md +1 -1
  19. package/.github/skills/trace-audit-reporting/assets/performance-report-template.md +1 -1
  20. package/.github/skills/trace-audit-reporting/references/trace-analysis-workflow.md +1 -1
  21. package/.github/skills/tracker-handoff/SKILL.md +53 -5
  22. package/package.json +1 -1
  23. package/plans/Flappy_Bird_Folder_Documentation_Pass.logs.md +42 -0
  24. package/plans/Flappy_Bird_Folder_Documentation_Pass.md +22 -104
  25. package/plans/README.md +6 -2
  26. package/plans/Roadmap.md +35 -31
  27. package/plans/analyze-trace-solid-split.logs.md +35 -0
  28. package/plans/analyze-trace-solid-split.plans.md +21 -52
  29. package/plans/architecture-solid-split.logs.md +44 -0
  30. package/plans/architecture-solid-split.plans.md +20 -653
  31. package/plans/asciiMaze-typescript-repair.logs.md +35 -0
  32. package/plans/asciiMaze-typescript-repair.plans.md +30 -36
  33. package/plans/generate-docs-solid-split.logs.md +36 -0
  34. package/plans/generate-docs-solid-split.plans.md +21 -73
  35. package/plans/methods-docs.logs.md +37 -0
  36. package/plans/methods-docs.plans.md +22 -183
  37. package/plans/methods-solid-split.logs.md +41 -0
  38. package/plans/methods-solid-split.plans.md +23 -65
  39. package/plans/neat-docs.logs.md +38 -0
  40. package/plans/neat-docs.plans.md +21 -63
  41. package/plans/neat-test-surface-repair.logs.md +38 -0
  42. package/plans/neat-test-surface-repair.plans.md +24 -24
  43. package/plans/readme-first-section-pass.logs.md +63 -0
  44. package/plans/readme-first-section-pass.plans.md +42 -0
  45. package/plans/render-docs-html-solid-split.logs.md +36 -0
  46. package/plans/render-docs-html-solid-split.plans.md +20 -54
  47. package/plans/src-no-explicit-any-cleanup.logs.md +39 -0
  48. package/plans/src-no-explicit-any-cleanup.plans.md +23 -161
  49. package/plans/utils-docs.logs.md +37 -0
  50. package/plans/utils-docs.plans.md +20 -35
  51. package/src/README.md +88 -22
  52. package/src/architecture/README.md +94 -17
  53. package/src/architecture/activationArrayPool/README.md +53 -0
  54. package/src/architecture/activationArrayPool/activationArrayPool.ts +53 -0
  55. package/src/architecture/layer/README.md +94 -5
  56. package/src/architecture/layer/layer.ts +94 -5
  57. package/src/architecture/network/README.md +85 -14
  58. package/src/architecture/network/activate/README.md +301 -213
  59. package/src/architecture/network/activate/docs.order.json +9 -0
  60. package/src/architecture/network/activate/network.activate.utils.ts +90 -0
  61. package/src/architecture/network/connect/README.md +80 -3
  62. package/src/architecture/network/connect/docs.order.json +9 -0
  63. package/src/architecture/network/connect/network.connect.utils.ts +79 -0
  64. package/src/architecture/network/deterministic/README.md +96 -12
  65. package/src/architecture/network/deterministic/docs.order.json +10 -0
  66. package/src/architecture/network/deterministic/network.deterministic.utils.ts +90 -0
  67. package/src/architecture/network/evolve/README.md +286 -228
  68. package/src/architecture/network/evolve/docs.order.json +11 -0
  69. package/src/architecture/network/evolve/network.evolve.utils.ts +59 -0
  70. package/src/architecture/network/gating/README.md +58 -16
  71. package/src/architecture/network/gating/docs.order.json +9 -0
  72. package/src/architecture/network/gating/network.gating.utils.ts +43 -0
  73. package/src/architecture/network/genetic/README.md +75 -36
  74. package/src/architecture/network/genetic/docs.order.json +10 -0
  75. package/src/architecture/network/genetic/network.genetic.utils.ts +53 -17
  76. package/src/architecture/network/network.ts +91 -46
  77. package/src/architecture/network/standalone/README.md +309 -285
  78. package/src/architecture/network/standalone/docs.order.json +13 -0
  79. package/src/architecture/network/standalone/network.standalone.utils.ts +51 -28
  80. package/src/architecture/network.ts +94 -17
  81. package/src/architecture/nodePool/README.md +53 -0
  82. package/src/architecture/nodePool/nodePool.ts +53 -0
  83. package/src/methods/README.md +80 -34
  84. package/src/methods/methods.ts +80 -34
  85. package/src/methods/mutation/README.md +39 -93
  86. package/src/methods/mutation/mutation.ts +58 -0
  87. package/src/multithreading/README.md +114 -14
  88. package/src/multithreading/docs.order.json +5 -0
  89. package/src/multithreading/multi.ts +103 -7
  90. package/src/multithreading/types.ts +6 -1
  91. package/src/multithreading/workers/README.md +72 -2
  92. package/src/multithreading/workers/browser/README.md +39 -0
  93. package/src/multithreading/workers/browser/testworker.ts +40 -0
  94. package/src/multithreading/workers/node/README.md +50 -11
  95. package/src/multithreading/workers/node/docs.order.json +4 -0
  96. package/src/multithreading/workers/node/testworker.ts +43 -3
  97. package/src/multithreading/workers/workers.ts +36 -1
  98. package/src/neat/README.md +230 -152
  99. package/src/neat/adaptive/core/README.md +99 -42
  100. package/src/neat/adaptive/core/adaptive.core.ts +71 -14
  101. package/src/neat/adaptive/core/docs.order.json +8 -0
  102. package/src/neat/docs.order.json +9 -0
  103. package/src/neat/lineage/README.md +118 -16
  104. package/src/neat/lineage/lineage.ts +115 -13
  105. package/src/neat/neat.defaults.constants.ts +91 -13
  106. package/src/neat.ts +86 -20
  107. package/src/utils/README.md +71 -21
  108. package/src/utils/memory.ts +69 -19
  109. package/test/examples/asciiMaze/browser-entry/README.md +81 -8
  110. package/test/examples/asciiMaze/browser-entry/browser-entry.ts +81 -8
  111. package/test/examples/asciiMaze/dashboardManager/README.md +68 -4
  112. package/test/examples/asciiMaze/dashboardManager/dashboardManager.ts +68 -4
  113. package/test/examples/asciiMaze/evolutionEngine/README.md +1259 -1174
  114. package/test/examples/asciiMaze/evolutionEngine/docs.order.json +10 -0
  115. package/test/examples/asciiMaze/evolutionEngine/evolutionEngine.types.ts +87 -0
  116. package/test/examples/asciiMaze/mazeMovement/README.md +81 -4
  117. package/test/examples/asciiMaze/mazeMovement/mazeMovement.ts +81 -4
  118. package/test/examples/flappy_bird/browser-entry/README.md +64 -21
  119. package/test/examples/flappy_bird/browser-entry/browser-entry.ts +64 -21
  120. package/test/examples/flappy_bird/flappy-evolution-worker/README.md +98 -10
  121. package/test/examples/flappy_bird/flappy-evolution-worker/flappy-evolution-worker.ts +98 -10
  122. package/test/examples/flappy_bird/simulation-shared/README.md +88 -4
  123. package/test/examples/flappy_bird/simulation-shared/simulation-shared.types.ts +88 -4
@@ -6,6 +6,43 @@
6
6
  * pool is not a new runtime primitive; it is the memory policy that decides
7
7
  * when temporary activation storage should be reused instead of reallocated.
8
8
  *
9
+ * Think of this boundary as scratch-space policy for activation-heavy code.
10
+ * Network execution repeatedly asks for short-lived arrays whose shapes often
11
+ * repeat from sample to sample. Reallocating those arrays every pass adds
12
+ * garbage-collector work without changing the model's behavior. This chapter
13
+ * keeps the reusable buffer story explicit while leaving graph semantics to
14
+ * the node, layer, and network chapters.
15
+ *
16
+ * The key design choice is that pooling happens by array length, not by caller
17
+ * identity. A network slab path and a layer helper can share the same retained
18
+ * storage as long as they request the same length and release the buffer after
19
+ * use. Acquire always returns a zeroed buffer, so the pool promises clean
20
+ * scratch memory rather than cached activations or memoized results.
21
+ *
22
+ * That distinction matters when you are debugging correctness. This folder is
23
+ * not a semantic cache and it does not preserve intermediate values for later
24
+ * reads. It only keeps array shells alive long enough to reduce allocation
25
+ * churn in hot loops, worker batches, and repeated forward passes.
26
+ *
27
+ * ```mermaid
28
+ * flowchart LR
29
+ * classDef base fill:#08131f,stroke:#1ea7ff,color:#dff6ff,stroke-width:1px;
30
+ * classDef accent fill:#0f2233,stroke:#ffd166,color:#fff4cc,stroke-width:1.5px;
31
+ *
32
+ * Request[Activation request]:::base --> Acquire[acquire by length]:::accent
33
+ * Acquire -->|bucket hit| Reuse[Zeroed reused buffer]:::base
34
+ * Acquire -->|bucket miss| Fresh[Freshly allocated buffer]:::base
35
+ * Reuse --> Execute[Layer or network activation]:::base
36
+ * Fresh --> Execute
37
+ * Execute --> Release[release buffer]:::accent
38
+ * Release --> Bucket[Length bucket]:::base
39
+ * ```
40
+ *
41
+ * For background on the broader software pattern, see Wikipedia contributors,
42
+ * [Object pool pattern](https://en.wikipedia.org/wiki/Object_pool_pattern).
43
+ * This chapter applies that idea to activation scratch space, not to long-lived
44
+ * model parameters.
45
+ *
9
46
  * Read this chapter in three passes:
10
47
  *
11
48
  * 1. start with `ActivationArray` to see which buffer shapes the runtime can
@@ -14,6 +51,22 @@
14
51
  * the hot-path allocation story,
15
52
  * 3. finish with `stats()`, `setMaxPerBucket()`, and `prewarm()` when you want
16
53
  * observability and capacity control.
54
+ *
55
+ * Example: reuse one scratch buffer around a custom activation-heavy loop.
56
+ *
57
+ * ```ts
58
+ * const activationArray = activationArrayPool.acquire(128);
59
+ * // fill and consume the buffer here
60
+ * activationArrayPool.release(activationArray);
61
+ * ```
62
+ *
63
+ * Example: prewarm one common bucket before a large evaluation batch.
64
+ *
65
+ * ```ts
66
+ * activationArrayPool.setMaxPerBucket(32);
67
+ * activationArrayPool.prewarm(256, 8);
68
+ * const stats = activationArrayPool.stats();
69
+ * ```
17
70
  */
18
71
 
19
72
  import { config } from '../../config';
@@ -8,6 +8,59 @@ this chapter keep activation, connection, propagation, and factory policies
8
8
  focused, while this file preserves the orchestration story that readers and
9
9
  callers actually meet first.
10
10
 
11
+ If `Node` is the single-neuron chapter and `Network` is the whole-graph
12
+ chapter, `Layer` is the middle shelf that lets builders talk in model-sized
13
+ blocks. Dense stages, recurrent cells, normalization passes, and memory-
14
+ shaped motifs all need more intent than a raw list of nodes, but far less
15
+ ceremony than constructing an entire network by hand.
16
+
17
+ That middle shelf matters for two audiences at once. Callers want one place
18
+ to say "make a dense block" or "connect this stage to that stage" without
19
+ manually pushing node arrays around. Maintainers want activation, wiring,
20
+ propagation, and factory mechanics separated so the public API can stay easy
21
+ to read while the underlying policies continue to evolve. This folderized
22
+ chapter is how the repo serves both goals at the same time.
23
+
24
+ One useful mental model is to place `Layer` between `Group` and `Network`.
25
+ `Group` exposes a reusable cluster of nodes plus wiring vocabulary. `Layer`
26
+ adds the stronger promise that the cluster represents a recognizable model
27
+ stage with standard entrypoints such as `activate()`, `propagate()`,
28
+ `connect()`, and factory constructors. `Network` then chains many of those
29
+ stages into a runnable, mutable graph.
30
+
31
+ A second mental model is to treat `layer.ts` as a public facade over several
32
+ helper shelves. Readers should start here because this file owns the stable
33
+ orchestration story. The helper files exist to keep concerns narrow: one set
34
+ handles activation and propagation, another handles wiring and guards, and
35
+ the factory helpers explain how dense, recurrent, normalization, and
36
+ experimental layer families are assembled.
37
+
38
+ ```mermaid
39
+ flowchart LR
40
+ classDef base fill:#08131f,stroke:#1ea7ff,color:#dff6ff,stroke-width:1px;
41
+ classDef accent fill:#0f2233,stroke:#ffd166,color:#fff4cc,stroke-width:1.5px;
42
+
43
+ Node[Node primitives]:::base --> Group[Group blocks]:::base
44
+ Group --> Layer[Layer model stage]:::accent
45
+ Layer --> Network[Network orchestration]:::base
46
+ Layer --> Architect[Architect presets]:::base
47
+ ```
48
+
49
+ ```mermaid
50
+ flowchart TD
51
+ classDef base fill:#08131f,stroke:#1ea7ff,color:#dff6ff,stroke-width:1px;
52
+ classDef accent fill:#0f2233,stroke:#ffd166,color:#fff4cc,stroke-width:1.5px;
53
+
54
+ LayerFacade[Layer facade]:::accent --> Runtime[activate propagate clear gate input]:::base
55
+ LayerFacade --> Wiring[connection and guard helpers]:::base
56
+ LayerFacade --> Factories[dense recurrent normalization experimental factories]:::base
57
+ ```
58
+
59
+ For background on the broader modeling idea, see Wikipedia contributors,
60
+ [Artificial neural network](https://en.wikipedia.org/wiki/Artificial_neural_network).
61
+ This chapter is narrower: it documents the library boundary that packages
62
+ those ideas into reusable blocks and helper-owned policies.
63
+
11
64
  Read this chapter in three passes:
12
65
 
13
66
  1. start with the `Layer` class overview to understand why the boundary
@@ -17,16 +70,52 @@ Read this chapter in three passes:
17
70
  3. finish with the static factory methods when you want named layer shapes
18
71
  such as dense, recurrent, normalization, or experimental blocks.
19
72
 
73
+ Example: wire a small dense stack using the same block-level API that higher
74
+ level builders depend on.
75
+
76
+ ```ts
77
+ const input = Layer.dense(2);
78
+ input.set({ type: 'input' });
79
+ const hidden = Layer.dense(4);
80
+ const output = Layer.dense(1);
81
+ output.set({ type: 'output' });
82
+
83
+ input.connect(hidden);
84
+ hidden.connect(output);
85
+
86
+ input.activate([0, 1]);
87
+ hidden.activate();
88
+ const values = output.activate();
89
+ ```
90
+
91
+ Example: swap in a richer factory-built block without changing the top-level
92
+ layer-to-layer wiring vocabulary.
93
+
94
+ ```ts
95
+ const recurrent = Layer.lstm(8);
96
+ const readout = Layer.dense(2);
97
+
98
+ recurrent.connect(readout);
99
+ ```
100
+
20
101
  ## architecture/layer/layer.ts
21
102
 
22
103
  ### Layer
23
104
 
24
- Represents a functional layer within a neural network architecture.
105
+ Public block-level facade for layer-oriented architecture building.
106
+
107
+ `Layer` is the boundary readers reach for when a graph region should behave
108
+ like one model stage rather than a loose collection of neurons. It
109
+ normalizes common operations across dense, recurrent, normalization, and
110
+ experimental factories so higher-level chapters can compose readable graphs
111
+ without depending on each helper shelf's private implementation details.
112
+
113
+ This makes the class useful when you want to:
25
114
 
26
- Layers act as organizational units for nodes, facilitating the creation of
27
- complex network structures like Dense, LSTM, GRU, or Memory layers.
28
- They manage the collective behavior of their nodes, including activation,
29
- propagation, and connection to other network components.
115
+ - assemble a network from named blocks instead of raw nodes,
116
+ - reuse the same activation, wiring, and propagation vocabulary across layer
117
+ families,
118
+ - keep factory-specific mechanics below the public API.
30
119
 
31
120
  ### default
32
121
 
@@ -7,6 +7,59 @@
7
7
  * focused, while this file preserves the orchestration story that readers and
8
8
  * callers actually meet first.
9
9
  *
10
+ * If `Node` is the single-neuron chapter and `Network` is the whole-graph
11
+ * chapter, `Layer` is the middle shelf that lets builders talk in model-sized
12
+ * blocks. Dense stages, recurrent cells, normalization passes, and memory-
13
+ * shaped motifs all need more intent than a raw list of nodes, but far less
14
+ * ceremony than constructing an entire network by hand.
15
+ *
16
+ * That middle shelf matters for two audiences at once. Callers want one place
17
+ * to say "make a dense block" or "connect this stage to that stage" without
18
+ * manually pushing node arrays around. Maintainers want activation, wiring,
19
+ * propagation, and factory mechanics separated so the public API can stay easy
20
+ * to read while the underlying policies continue to evolve. This folderized
21
+ * chapter is how the repo serves both goals at the same time.
22
+ *
23
+ * One useful mental model is to place `Layer` between `Group` and `Network`.
24
+ * `Group` exposes a reusable cluster of nodes plus wiring vocabulary. `Layer`
25
+ * adds the stronger promise that the cluster represents a recognizable model
26
+ * stage with standard entrypoints such as `activate()`, `propagate()`,
27
+ * `connect()`, and factory constructors. `Network` then chains many of those
28
+ * stages into a runnable, mutable graph.
29
+ *
30
+ * A second mental model is to treat `layer.ts` as a public facade over several
31
+ * helper shelves. Readers should start here because this file owns the stable
32
+ * orchestration story. The helper files exist to keep concerns narrow: one set
33
+ * handles activation and propagation, another handles wiring and guards, and
34
+ * the factory helpers explain how dense, recurrent, normalization, and
35
+ * experimental layer families are assembled.
36
+ *
37
+ * ```mermaid
38
+ * flowchart LR
39
+ * classDef base fill:#08131f,stroke:#1ea7ff,color:#dff6ff,stroke-width:1px;
40
+ * classDef accent fill:#0f2233,stroke:#ffd166,color:#fff4cc,stroke-width:1.5px;
41
+ *
42
+ * Node[Node primitives]:::base --> Group[Group blocks]:::base
43
+ * Group --> Layer[Layer model stage]:::accent
44
+ * Layer --> Network[Network orchestration]:::base
45
+ * Layer --> Architect[Architect presets]:::base
46
+ * ```
47
+ *
48
+ * ```mermaid
49
+ * flowchart TD
50
+ * classDef base fill:#08131f,stroke:#1ea7ff,color:#dff6ff,stroke-width:1px;
51
+ * classDef accent fill:#0f2233,stroke:#ffd166,color:#fff4cc,stroke-width:1.5px;
52
+ *
53
+ * LayerFacade[Layer facade]:::accent --> Runtime[activate propagate clear gate input]:::base
54
+ * LayerFacade --> Wiring[connection and guard helpers]:::base
55
+ * LayerFacade --> Factories[dense recurrent normalization experimental factories]:::base
56
+ * ```
57
+ *
58
+ * For background on the broader modeling idea, see Wikipedia contributors,
59
+ * [Artificial neural network](https://en.wikipedia.org/wiki/Artificial_neural_network).
60
+ * This chapter is narrower: it documents the library boundary that packages
61
+ * those ideas into reusable blocks and helper-owned policies.
62
+ *
10
63
  * Read this chapter in three passes:
11
64
  *
12
65
  * 1. start with the `Layer` class overview to understand why the boundary
@@ -15,6 +68,34 @@
15
68
  * you need the runtime wiring surface,
16
69
  * 3. finish with the static factory methods when you want named layer shapes
17
70
  * such as dense, recurrent, normalization, or experimental blocks.
71
+ *
72
+ * Example: wire a small dense stack using the same block-level API that higher
73
+ * level builders depend on.
74
+ *
75
+ * ```ts
76
+ * const input = Layer.dense(2);
77
+ * input.set({ type: 'input' });
78
+ * const hidden = Layer.dense(4);
79
+ * const output = Layer.dense(1);
80
+ * output.set({ type: 'output' });
81
+ *
82
+ * input.connect(hidden);
83
+ * hidden.connect(output);
84
+ *
85
+ * input.activate([0, 1]);
86
+ * hidden.activate();
87
+ * const values = output.activate();
88
+ * ```
89
+ *
90
+ * Example: swap in a richer factory-built block without changing the top-level
91
+ * layer-to-layer wiring vocabulary.
92
+ *
93
+ * ```ts
94
+ * const recurrent = Layer.lstm(8);
95
+ * const readout = Layer.dense(2);
96
+ *
97
+ * recurrent.connect(readout);
98
+ * ```
18
99
  */
19
100
 
20
101
  import Node from '../node/node';
@@ -50,12 +131,20 @@ const NODE_INDEX_START = 0;
50
131
  const NODE_INDEX_STEP = 1;
51
132
 
52
133
  /**
53
- * Represents a functional layer within a neural network architecture.
134
+ * Public block-level facade for layer-oriented architecture building.
135
+ *
136
+ * `Layer` is the boundary readers reach for when a graph region should behave
137
+ * like one model stage rather than a loose collection of neurons. It
138
+ * normalizes common operations across dense, recurrent, normalization, and
139
+ * experimental factories so higher-level chapters can compose readable graphs
140
+ * without depending on each helper shelf's private implementation details.
141
+ *
142
+ * This makes the class useful when you want to:
54
143
  *
55
- * Layers act as organizational units for nodes, facilitating the creation of
56
- * complex network structures like Dense, LSTM, GRU, or Memory layers.
57
- * They manage the collective behavior of their nodes, including activation,
58
- * propagation, and connection to other network components.
144
+ * - assemble a network from named blocks instead of raw nodes,
145
+ * - reuse the same activation, wiring, and propagation vocabulary across layer
146
+ * families,
147
+ * - keep factory-specific mechanics below the public API.
59
148
  */
60
149
  export default class Layer {
61
150
  /**
@@ -2,20 +2,91 @@
2
2
 
3
3
  Core network chapter for the architecture surface.
4
4
 
5
- This folder now owns the public `Network` class that readers and callers use
6
- to build, activate, evolve, serialize, and export graph-shaped neural
7
- systems. The surrounding helper chapters keep activation, training,
8
- topology, pruning, ONNX, and slab execution policy focused, while this file
9
- preserves the orchestration story that ties those responsibilities into one
10
- runtime boundary.
11
-
12
- Read this chapter in three passes:
13
-
14
- 1. start here to understand the public `Network` contract and why it sits
15
- above nodes, layers, and connections,
16
- 2. continue into the helper chapters when you want one subsystem in detail,
17
- 3. return here when you need to see how the public API composes those
18
- subsystem policies back into one runtime object.
5
+ This folder owns the public `Network` class: the boundary where a graph stops
6
+ being only nodes and connections and starts behaving like one runnable,
7
+ mutable, trainable system. Higher-level NEAT code can mutate or score a
8
+ network, but this chapter is where the graph itself learns how to activate,
9
+ accept structural edits, preserve deterministic state, serialize, and cross
10
+ the ONNX boundary.
11
+
12
+ That boundary matters because the same instance has to serve several jobs
13
+ without changing shape. A caller may want ordinary inference, training-aware
14
+ forward passes, topology edits, reproducible stochastic behavior, sparse
15
+ pruning, or a portable checkpoint. Keeping those responsibilities under one
16
+ facade makes the public API readable while the helper chapters keep each
17
+ policy cluster narrow enough to teach.
18
+
19
+ A useful mental model is to read `network/` as four cooperating shelves.
20
+ `bootstrap/` explains one-time construction policy. `activate/`, `runtime/`,
21
+ and `training/` explain how a graph is stepped and regularized once it is
22
+ alive. `connect/`, `mutate/`, `remove/`, `prune/`, and `topology/` explain
23
+ graph surgery. `serialize/`, `standalone/`, `onnx/`, and `stats/` explain
24
+ portability, inspection, and reporting.
25
+
26
+ The performance story is equally important. This chapter deliberately hides
27
+ storage details until they matter. Callers should be able to ask for
28
+ `activate()` or `train()` without first understanding slab packing, pooled
29
+ activation arrays, or cache invalidation. The helper folders then expose how
30
+ the same graph can switch between object traversal and denser typed-array
31
+ paths without changing the surface contract.
32
+
33
+ ```mermaid
34
+ flowchart LR
35
+ classDef base fill:#08131f,stroke:#1ea7ff,color:#dff6ff,stroke-width:1px;
36
+ classDef accent fill:#0f2233,stroke:#ffd166,color:#fff4cc,stroke-width:1.5px;
37
+
38
+ Build[bootstrap and topology intent]:::base --> NetworkClass[Network facade]:::accent
39
+ NetworkClass --> Execute[activate runtime and training]:::base
40
+ Execute --> Edit[connect mutate prune remove]:::base
41
+ Edit --> Persist[serialize standalone and ONNX]:::base
42
+ ```
43
+
44
+ ```mermaid
45
+ flowchart TD
46
+ classDef base fill:#08131f,stroke:#1ea7ff,color:#dff6ff,stroke-width:1px;
47
+ classDef accent fill:#0f2233,stroke:#ffd166,color:#fff4cc,stroke-width:1.5px;
48
+
49
+ NetworkChapter[network chapter]:::accent --> Bootstrap[bootstrap/ one-time setup]:::base
50
+ NetworkChapter --> Activate[activate/ forward-pass policy]:::base
51
+ NetworkChapter --> Runtime[runtime/ training-time controls]:::base
52
+ NetworkChapter --> Structure[connect mutate topology prune]:::base
53
+ NetworkChapter --> Interop[serialize standalone onnx stats]:::base
54
+ ```
55
+
56
+ For background on the execution-order side of this chapter, see Wikipedia
57
+ contributors, [Topological sorting](https://en.wikipedia.org/wiki/Topological_sorting).
58
+ Feed-forward network execution, acyclic guards, and some of the helper
59
+ policies in this folder all depend on the same scheduling idea even when the
60
+ public API keeps that detail out of the caller's way.
61
+
62
+ Example: create a compact layered network and use the ordinary activation
63
+ surface.
64
+
65
+ ```ts
66
+ const network = Network.createMLP(2, [4], 1);
67
+ const outputValues = network.activate([0, 1]);
68
+ ```
69
+
70
+ Example: checkpoint one network, then restore it for another run.
71
+
72
+ ```ts
73
+ const network = new Network(2, 1, { seed: 7 });
74
+ const saved = network.toJSON();
75
+ const restored = Network.fromJSON(saved);
76
+ const replayed = restored.activate([1, 0]);
77
+ ```
78
+
79
+ Practical reading order:
80
+
81
+ 1. Start here for the public `Network` facade and the cross-chapter map.
82
+ 2. Continue into `bootstrap/` when the constructor contract is the next
83
+ question.
84
+ 3. Continue into `activate/`, `runtime/`, and `training/` for execution and
85
+ learning policy.
86
+ 4. Continue into `connect/`, `mutate/`, `remove/`, `prune/`, and `topology/`
87
+ for structural editing.
88
+ 5. Finish in `serialize/`, `standalone/`, `onnx/`, and `stats/` for
89
+ portability, derived reports, and export flows.
19
90
 
20
91
  ## architecture/network/network.ts
21
92