@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.
- package/.github/agents/boundary-mapper.agent.md +13 -8
- package/.github/agents/docs-scout.agent.md +14 -9
- package/.github/agents/plan-scout.agent.md +11 -6
- package/.github/agents/solid-split.agent.md +33 -17
- package/.github/copilot-instructions.md +100 -88
- package/.github/skills/educational-docs/SKILL.md +90 -40
- package/.github/skills/educational-docs/assets/mermaid-diagram-playbook.md +141 -141
- package/.github/skills/educational-docs/assets/visual-style-guide.md +1 -1
- package/.github/skills/plan-alignment/SKILL.md +1 -1
- package/.github/skills/solid-split/SKILL.md +54 -35
- package/.github/skills/solid-split/assets/docs-checklist.md +1 -1
- package/.github/skills/solid-split/assets/split-plan-template.md +41 -12
- package/.github/skills/solid-split/assets/split-workflow-checklist.md +4 -1
- package/.github/skills/test-fix-workflow/SKILL.md +12 -7
- package/.github/skills/trace-analyzer-extension/SKILL.md +1 -1
- package/.github/skills/trace-analyzer-extension/assets/extension-checklist.md +1 -1
- package/.github/skills/trace-analyzer-extension/references/analyzer-extension-workflow.md +1 -1
- package/.github/skills/trace-audit-reporting/SKILL.md +1 -1
- package/.github/skills/trace-audit-reporting/assets/performance-report-template.md +1 -1
- package/.github/skills/trace-audit-reporting/references/trace-analysis-workflow.md +1 -1
- package/.github/skills/tracker-handoff/SKILL.md +53 -5
- package/package.json +1 -1
- package/plans/Flappy_Bird_Folder_Documentation_Pass.logs.md +42 -0
- package/plans/Flappy_Bird_Folder_Documentation_Pass.md +22 -104
- package/plans/README.md +6 -2
- package/plans/Roadmap.md +35 -31
- package/plans/analyze-trace-solid-split.logs.md +35 -0
- package/plans/analyze-trace-solid-split.plans.md +21 -52
- package/plans/architecture-solid-split.logs.md +44 -0
- package/plans/architecture-solid-split.plans.md +20 -653
- package/plans/asciiMaze-typescript-repair.logs.md +35 -0
- package/plans/asciiMaze-typescript-repair.plans.md +30 -36
- package/plans/generate-docs-solid-split.logs.md +36 -0
- package/plans/generate-docs-solid-split.plans.md +21 -73
- package/plans/methods-docs.logs.md +37 -0
- package/plans/methods-docs.plans.md +22 -183
- package/plans/methods-solid-split.logs.md +41 -0
- package/plans/methods-solid-split.plans.md +23 -65
- package/plans/neat-docs.logs.md +38 -0
- package/plans/neat-docs.plans.md +21 -63
- package/plans/neat-test-surface-repair.logs.md +38 -0
- package/plans/neat-test-surface-repair.plans.md +24 -24
- package/plans/readme-first-section-pass.logs.md +63 -0
- package/plans/readme-first-section-pass.plans.md +42 -0
- package/plans/render-docs-html-solid-split.logs.md +36 -0
- package/plans/render-docs-html-solid-split.plans.md +20 -54
- package/plans/src-no-explicit-any-cleanup.logs.md +39 -0
- package/plans/src-no-explicit-any-cleanup.plans.md +23 -161
- package/plans/utils-docs.logs.md +37 -0
- package/plans/utils-docs.plans.md +20 -35
- package/src/README.md +88 -22
- package/src/architecture/README.md +94 -17
- package/src/architecture/activationArrayPool/README.md +53 -0
- package/src/architecture/activationArrayPool/activationArrayPool.ts +53 -0
- package/src/architecture/layer/README.md +94 -5
- package/src/architecture/layer/layer.ts +94 -5
- package/src/architecture/network/README.md +85 -14
- package/src/architecture/network/activate/README.md +301 -213
- package/src/architecture/network/activate/docs.order.json +9 -0
- package/src/architecture/network/activate/network.activate.utils.ts +90 -0
- package/src/architecture/network/connect/README.md +80 -3
- package/src/architecture/network/connect/docs.order.json +9 -0
- package/src/architecture/network/connect/network.connect.utils.ts +79 -0
- package/src/architecture/network/deterministic/README.md +96 -12
- package/src/architecture/network/deterministic/docs.order.json +10 -0
- package/src/architecture/network/deterministic/network.deterministic.utils.ts +90 -0
- package/src/architecture/network/evolve/README.md +286 -228
- package/src/architecture/network/evolve/docs.order.json +11 -0
- package/src/architecture/network/evolve/network.evolve.utils.ts +59 -0
- package/src/architecture/network/gating/README.md +58 -16
- package/src/architecture/network/gating/docs.order.json +9 -0
- package/src/architecture/network/gating/network.gating.utils.ts +43 -0
- package/src/architecture/network/genetic/README.md +75 -36
- package/src/architecture/network/genetic/docs.order.json +10 -0
- package/src/architecture/network/genetic/network.genetic.utils.ts +53 -17
- package/src/architecture/network/network.ts +91 -46
- package/src/architecture/network/standalone/README.md +309 -285
- package/src/architecture/network/standalone/docs.order.json +13 -0
- package/src/architecture/network/standalone/network.standalone.utils.ts +51 -28
- package/src/architecture/network.ts +94 -17
- package/src/architecture/nodePool/README.md +53 -0
- package/src/architecture/nodePool/nodePool.ts +53 -0
- package/src/methods/README.md +80 -34
- package/src/methods/methods.ts +80 -34
- package/src/methods/mutation/README.md +39 -93
- package/src/methods/mutation/mutation.ts +58 -0
- package/src/multithreading/README.md +114 -14
- package/src/multithreading/docs.order.json +5 -0
- package/src/multithreading/multi.ts +103 -7
- package/src/multithreading/types.ts +6 -1
- package/src/multithreading/workers/README.md +72 -2
- package/src/multithreading/workers/browser/README.md +39 -0
- package/src/multithreading/workers/browser/testworker.ts +40 -0
- package/src/multithreading/workers/node/README.md +50 -11
- package/src/multithreading/workers/node/docs.order.json +4 -0
- package/src/multithreading/workers/node/testworker.ts +43 -3
- package/src/multithreading/workers/workers.ts +36 -1
- package/src/neat/README.md +230 -152
- package/src/neat/adaptive/core/README.md +99 -42
- package/src/neat/adaptive/core/adaptive.core.ts +71 -14
- package/src/neat/adaptive/core/docs.order.json +8 -0
- package/src/neat/docs.order.json +9 -0
- package/src/neat/lineage/README.md +118 -16
- package/src/neat/lineage/lineage.ts +115 -13
- package/src/neat/neat.defaults.constants.ts +91 -13
- package/src/neat.ts +86 -20
- package/src/utils/README.md +71 -21
- package/src/utils/memory.ts +69 -19
- package/test/examples/asciiMaze/browser-entry/README.md +81 -8
- package/test/examples/asciiMaze/browser-entry/browser-entry.ts +81 -8
- package/test/examples/asciiMaze/dashboardManager/README.md +68 -4
- package/test/examples/asciiMaze/dashboardManager/dashboardManager.ts +68 -4
- package/test/examples/asciiMaze/evolutionEngine/README.md +1259 -1174
- package/test/examples/asciiMaze/evolutionEngine/docs.order.json +10 -0
- package/test/examples/asciiMaze/evolutionEngine/evolutionEngine.types.ts +87 -0
- package/test/examples/asciiMaze/mazeMovement/README.md +81 -4
- package/test/examples/asciiMaze/mazeMovement/mazeMovement.ts +81 -4
- package/test/examples/flappy_bird/browser-entry/README.md +64 -21
- package/test/examples/flappy_bird/browser-entry/browser-entry.ts +64 -21
- package/test/examples/flappy_bird/flappy-evolution-worker/README.md +98 -10
- package/test/examples/flappy_bird/flappy-evolution-worker/flappy-evolution-worker.ts +98 -10
- package/test/examples/flappy_bird/simulation-shared/README.md +88 -4
- package/test/examples/flappy_bird/simulation-shared/simulation-shared.types.ts +88 -4
|
@@ -1,3 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Activation chapter for `Network` execution policy.
|
|
3
|
+
*
|
|
4
|
+
* This folder answers the moment when a graph already exists and the next
|
|
5
|
+
* question becomes: how should signal move through it right now? The same
|
|
6
|
+
* network may be stepped for ordinary inference, training-aware forward passes,
|
|
7
|
+
* zero-copy raw output reuse, or a sequence of batch rows. Keeping those paths
|
|
8
|
+
* together makes the execution tradeoffs visible without mixing them into
|
|
9
|
+
* topology or serialization code.
|
|
10
|
+
*
|
|
11
|
+
* The important split is between graph meaning and graph execution. Node and
|
|
12
|
+
* connection chapters explain what the structure is. `activate/` explains how
|
|
13
|
+
* that structure is stepped: validate inputs, decide whether the slab fast path
|
|
14
|
+
* is still legal, preserve or skip training traces, and return outputs in the
|
|
15
|
+
* shape the caller requested.
|
|
16
|
+
*
|
|
17
|
+
* A second useful lens is to read the public exports as four modes.
|
|
18
|
+
* `activate()` is the ordinary compatibility path. `noTraceActivate()` is the
|
|
19
|
+
* hot inference path when trace bookkeeping would be wasteful. `activateRaw()`
|
|
20
|
+
* keeps typed-array reuse available when pooling matters more than boxed
|
|
21
|
+
* outputs. `activateBatch()` is the clear orchestration layer for repeated
|
|
22
|
+
* forward passes over many rows.
|
|
23
|
+
*
|
|
24
|
+
* The performance lesson here is not "always choose the fastest path." It is
|
|
25
|
+
* "choose the narrowest path that still matches the caller's semantics." If a
|
|
26
|
+
* network is slab-ready, this chapter can exploit contiguous typed arrays. If a
|
|
27
|
+
* structural edit made that layout stale, the same boundary falls back to node
|
|
28
|
+
* traversal instead of forcing callers to understand storage internals first.
|
|
29
|
+
*
|
|
30
|
+
* ```mermaid
|
|
31
|
+
* flowchart LR
|
|
32
|
+
* classDef base fill:#08131f,stroke:#1ea7ff,color:#dff6ff,stroke-width:1px;
|
|
33
|
+
* classDef accent fill:#0f2233,stroke:#ffd166,color:#fff4cc,stroke-width:1.5px;
|
|
34
|
+
*
|
|
35
|
+
* Input[caller input]:::base --> Modes[activate chapter]:::accent
|
|
36
|
+
* Modes --> Trace[activate<br/>keep traces]:::base
|
|
37
|
+
* Modes --> NoTrace[noTraceActivate<br/>inference hot path]:::base
|
|
38
|
+
* Modes --> Raw[activateRaw<br/>typed output reuse]:::base
|
|
39
|
+
* Modes --> Batch[activateBatch<br/>repeat over rows]:::base
|
|
40
|
+
* ```
|
|
41
|
+
*
|
|
42
|
+
* ```mermaid
|
|
43
|
+
* flowchart TD
|
|
44
|
+
* classDef base fill:#08131f,stroke:#1ea7ff,color:#dff6ff,stroke-width:1px;
|
|
45
|
+
* classDef accent fill:#0f2233,stroke:#ffd166,color:#fff4cc,stroke-width:1.5px;
|
|
46
|
+
*
|
|
47
|
+
* ActivateChapter[activate/]:::accent --> Validation[input validation and contexts]:::base
|
|
48
|
+
* ActivateChapter --> FastPath[slab fast path when layout is ready]:::base
|
|
49
|
+
* ActivateChapter --> Traversal[node traversal fallback]:::base
|
|
50
|
+
* ActivateChapter --> Buffers[pooled activation buffers]:::base
|
|
51
|
+
* ```
|
|
52
|
+
*
|
|
53
|
+
* For background on why some activation paths preserve training traces while
|
|
54
|
+
* others skip them, see Wikipedia contributors,
|
|
55
|
+
* [Backpropagation](https://en.wikipedia.org/wiki/Backpropagation). This
|
|
56
|
+
* chapter sits at the forward-pass side of that story and decides how much
|
|
57
|
+
* training bookkeeping each call should carry along.
|
|
58
|
+
*
|
|
59
|
+
* Example: use the no-trace path when you only need inference outputs.
|
|
60
|
+
*
|
|
61
|
+
* ```ts
|
|
62
|
+
* const network = Network.createMLP(2, [3], 1);
|
|
63
|
+
* const outputValues = network.noTraceActivate([0.2, 0.8]);
|
|
64
|
+
* ```
|
|
65
|
+
*
|
|
66
|
+
* Example: run the same network over several input rows with one orchestration
|
|
67
|
+
* call.
|
|
68
|
+
*
|
|
69
|
+
* ```ts
|
|
70
|
+
* const network = Network.createMLP(2, [3], 1);
|
|
71
|
+
* const batchOutputs = network.activateBatch(
|
|
72
|
+
* [
|
|
73
|
+
* [0, 1],
|
|
74
|
+
* [1, 0],
|
|
75
|
+
* ],
|
|
76
|
+
* true,
|
|
77
|
+
* );
|
|
78
|
+
* ```
|
|
79
|
+
*
|
|
80
|
+
* Practical reading order:
|
|
81
|
+
*
|
|
82
|
+
* 1. Start here for the public activation modes and their semantic differences.
|
|
83
|
+
* 2. Continue into `network.activate.core.utils.ts` when you want the ordinary
|
|
84
|
+
* forward-pass pipeline.
|
|
85
|
+
* 3. Continue into `network.activate.raw.utils.ts` and the no-trace helpers
|
|
86
|
+
* when typed-array reuse or inference hot paths are the next question.
|
|
87
|
+
* 4. Finish with the context and helper files when you want the orchestration
|
|
88
|
+
* details behind validation, batching, and fallback behavior.
|
|
89
|
+
*/
|
|
90
|
+
|
|
1
91
|
import type Network from '../../network/network';
|
|
2
92
|
export { activate, gaussianRand } from './network.activate.core.utils';
|
|
3
93
|
import {
|
|
@@ -1,10 +1,81 @@
|
|
|
1
1
|
# architecture/network/connect
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Connection-editing chapter for single-edge graph surgery.
|
|
4
|
+
|
|
5
|
+
This folder owns the smallest structural change a `Network` can make: add or
|
|
6
|
+
remove one directed edge while keeping graph invariants, gating state, and
|
|
7
|
+
execution caches honest. Higher-level builders may connect layers or groups
|
|
8
|
+
in bulk, but they still depend on the legality and bookkeeping rules taught
|
|
9
|
+
here.
|
|
10
|
+
|
|
11
|
+
The important distinction is between edge creation and edge registration.
|
|
12
|
+
`Node.connect()` can manufacture one or more low-level connection objects,
|
|
13
|
+
but the network still has to decide whether those edges are legal in the
|
|
14
|
+
current topology policy, whether they belong in normal or self-connection
|
|
15
|
+
storage, and whether cached topological or slab views must be invalidated.
|
|
16
|
+
|
|
17
|
+
Acyclic mode makes that policy visible. In feed-forward configurations this
|
|
18
|
+
chapter refuses back-edges and self-edges that would violate the intended
|
|
19
|
+
execution order. In unconstrained mode the same surface accepts those edits
|
|
20
|
+
and simply keeps the runtime collections synchronized. That lets callers ask
|
|
21
|
+
for structural edits without duplicating the topology rules everywhere else.
|
|
22
|
+
|
|
23
|
+
The matching remove path is equally educational. Disconnecting one edge is
|
|
24
|
+
not just a splice from an array. If the edge is gated, the gating linkage has
|
|
25
|
+
to be released first. After that, structural caches are marked dirty so the
|
|
26
|
+
next activation or slab rebuild sees the new graph instead of a stale one.
|
|
27
|
+
|
|
28
|
+
```mermaid
|
|
29
|
+
flowchart LR
|
|
30
|
+
classDef base fill:#08131f,stroke:#1ea7ff,color:#dff6ff,stroke-width:1px;
|
|
31
|
+
classDef accent fill:#0f2233,stroke:#ffd166,color:#fff4cc,stroke-width:1.5px;
|
|
32
|
+
|
|
33
|
+
Request[connect request]:::base --> Guard[acyclic legality check]:::accent
|
|
34
|
+
Guard --> Create[Node.connect creates low-level edges]:::base
|
|
35
|
+
Create --> Register[classify self-edge or standard edge]:::base
|
|
36
|
+
Register --> Dirty[mark topology and slab caches dirty]:::base
|
|
37
|
+
```
|
|
4
38
|
|
|
5
|
-
|
|
39
|
+
```mermaid
|
|
40
|
+
flowchart TD
|
|
41
|
+
classDef base fill:#08131f,stroke:#1ea7ff,color:#dff6ff,stroke-width:1px;
|
|
42
|
+
classDef accent fill:#0f2233,stroke:#ffd166,color:#fff4cc,stroke-width:1.5px;
|
|
6
43
|
|
|
7
|
-
|
|
44
|
+
Mode[topology mode]:::accent --> FeedForward[feed-forward<br/>reject back-edges]:::base
|
|
45
|
+
Mode --> Unconstrained[unconstrained<br/>allow recurrent edits]:::base
|
|
46
|
+
FeedForward --> Collections[network collections stay valid]:::base
|
|
47
|
+
Unconstrained --> Collections
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
For background on the scheduling constraint behind acyclic mode, see
|
|
51
|
+
Wikipedia contributors,
|
|
52
|
+
[Topological sorting](https://en.wikipedia.org/wiki/Topological_sorting).
|
|
53
|
+
The legality checks in this folder protect the execution order assumptions
|
|
54
|
+
that feed-forward activation relies on.
|
|
55
|
+
|
|
56
|
+
Example: add one explicit edge between two nodes.
|
|
57
|
+
|
|
58
|
+
```ts
|
|
59
|
+
const [edge] = network.connect(sourceNode, targetNode, 0.5);
|
|
60
|
+
console.log(edge.weight);
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Example: remove one existing edge and let the network invalidate its cached
|
|
64
|
+
structure for the next run.
|
|
65
|
+
|
|
66
|
+
```ts
|
|
67
|
+
network.disconnect(sourceNode, targetNode);
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Practical reading order:
|
|
71
|
+
|
|
72
|
+
1. Start here for the public `connect()` and `disconnect()` semantics.
|
|
73
|
+
2. Continue into `network.connect.create.utils.ts` for edge creation,
|
|
74
|
+
registration, and acyclic guards.
|
|
75
|
+
3. Continue into `network.connect.remove.utils.ts` for disconnect cleanup and
|
|
76
|
+
gated-edge removal behavior.
|
|
77
|
+
4. Finish with `network.connect.utils.types.ts` when you need the internal
|
|
78
|
+
state shape shared across both flows.
|
|
8
79
|
|
|
9
80
|
## architecture/network/connect/network.connect.utils.ts
|
|
10
81
|
|
|
@@ -95,6 +166,12 @@ Example:
|
|
|
95
166
|
|
|
96
167
|
net.disconnect(nodeA, nodeB);
|
|
97
168
|
|
|
169
|
+
## architecture/network/connect/network.connect.utils.types.ts
|
|
170
|
+
|
|
171
|
+
### NetworkInternals
|
|
172
|
+
|
|
173
|
+
Internal network state shape shared by connect utility helper modules.
|
|
174
|
+
|
|
98
175
|
## architecture/network/connect/network.connect.create.utils.ts
|
|
99
176
|
|
|
100
177
|
### createConnectionsFromSourceNode
|
|
@@ -1,3 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Connection-editing chapter for single-edge graph surgery.
|
|
3
|
+
*
|
|
4
|
+
* This folder owns the smallest structural change a `Network` can make: add or
|
|
5
|
+
* remove one directed edge while keeping graph invariants, gating state, and
|
|
6
|
+
* execution caches honest. Higher-level builders may connect layers or groups
|
|
7
|
+
* in bulk, but they still depend on the legality and bookkeeping rules taught
|
|
8
|
+
* here.
|
|
9
|
+
*
|
|
10
|
+
* The important distinction is between edge creation and edge registration.
|
|
11
|
+
* `Node.connect()` can manufacture one or more low-level connection objects,
|
|
12
|
+
* but the network still has to decide whether those edges are legal in the
|
|
13
|
+
* current topology policy, whether they belong in normal or self-connection
|
|
14
|
+
* storage, and whether cached topological or slab views must be invalidated.
|
|
15
|
+
*
|
|
16
|
+
* Acyclic mode makes that policy visible. In feed-forward configurations this
|
|
17
|
+
* chapter refuses back-edges and self-edges that would violate the intended
|
|
18
|
+
* execution order. In unconstrained mode the same surface accepts those edits
|
|
19
|
+
* and simply keeps the runtime collections synchronized. That lets callers ask
|
|
20
|
+
* for structural edits without duplicating the topology rules everywhere else.
|
|
21
|
+
*
|
|
22
|
+
* The matching remove path is equally educational. Disconnecting one edge is
|
|
23
|
+
* not just a splice from an array. If the edge is gated, the gating linkage has
|
|
24
|
+
* to be released first. After that, structural caches are marked dirty so the
|
|
25
|
+
* next activation or slab rebuild sees the new graph instead of a stale one.
|
|
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[connect request]:::base --> Guard[acyclic legality check]:::accent
|
|
33
|
+
* Guard --> Create[Node.connect creates low-level edges]:::base
|
|
34
|
+
* Create --> Register[classify self-edge or standard edge]:::base
|
|
35
|
+
* Register --> Dirty[mark topology and slab caches dirty]:::base
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
* ```mermaid
|
|
39
|
+
* flowchart TD
|
|
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
|
+
* Mode[topology mode]:::accent --> FeedForward[feed-forward<br/>reject back-edges]:::base
|
|
44
|
+
* Mode --> Unconstrained[unconstrained<br/>allow recurrent edits]:::base
|
|
45
|
+
* FeedForward --> Collections[network collections stay valid]:::base
|
|
46
|
+
* Unconstrained --> Collections
|
|
47
|
+
* ```
|
|
48
|
+
*
|
|
49
|
+
* For background on the scheduling constraint behind acyclic mode, see
|
|
50
|
+
* Wikipedia contributors,
|
|
51
|
+
* [Topological sorting](https://en.wikipedia.org/wiki/Topological_sorting).
|
|
52
|
+
* The legality checks in this folder protect the execution order assumptions
|
|
53
|
+
* that feed-forward activation relies on.
|
|
54
|
+
*
|
|
55
|
+
* Example: add one explicit edge between two nodes.
|
|
56
|
+
*
|
|
57
|
+
* ```ts
|
|
58
|
+
* const [edge] = network.connect(sourceNode, targetNode, 0.5);
|
|
59
|
+
* console.log(edge.weight);
|
|
60
|
+
* ```
|
|
61
|
+
*
|
|
62
|
+
* Example: remove one existing edge and let the network invalidate its cached
|
|
63
|
+
* structure for the next run.
|
|
64
|
+
*
|
|
65
|
+
* ```ts
|
|
66
|
+
* network.disconnect(sourceNode, targetNode);
|
|
67
|
+
* ```
|
|
68
|
+
*
|
|
69
|
+
* Practical reading order:
|
|
70
|
+
*
|
|
71
|
+
* 1. Start here for the public `connect()` and `disconnect()` semantics.
|
|
72
|
+
* 2. Continue into `network.connect.create.utils.ts` for edge creation,
|
|
73
|
+
* registration, and acyclic guards.
|
|
74
|
+
* 3. Continue into `network.connect.remove.utils.ts` for disconnect cleanup and
|
|
75
|
+
* gated-edge removal behavior.
|
|
76
|
+
* 4. Finish with `network.connect.utils.types.ts` when you need the internal
|
|
77
|
+
* state shape shared across both flows.
|
|
78
|
+
*/
|
|
79
|
+
|
|
1
80
|
import type Network from '../../network/network';
|
|
2
81
|
import Node from '../../node';
|
|
3
82
|
import Connection from '../../connection';
|
|
@@ -1,28 +1,94 @@
|
|
|
1
1
|
# architecture/network/deterministic
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Deterministic RNG chapter for replayable `Network` behavior.
|
|
4
|
+
|
|
5
|
+
This folder keeps random state explicit so stochastic network behavior can be
|
|
6
|
+
repeated instead of merely hoped for. The same graph may use randomness for
|
|
7
|
+
dropout, stochastic depth, weight noise, training-time perturbations, or
|
|
8
|
+
mutation-adjacent helpers. Deterministic utilities give those flows a common
|
|
9
|
+
seed, checkpoint, and restore surface.
|
|
10
|
+
|
|
11
|
+
The important design split is between setup, state access, and lifecycle
|
|
12
|
+
capture. `setSeed()` installs a reproducible random stream. `getRNGState()`
|
|
13
|
+
and `setRNGState()` expose lightweight numeric checkpoints for pause-resume
|
|
14
|
+
workflows. `snapshotRNG()` and `restoreRNG()` support the slightly richer
|
|
15
|
+
lifecycle case where external tooling wants to branch or reconstruct the
|
|
16
|
+
active random function more deliberately.
|
|
17
|
+
|
|
18
|
+
This chapter matters because deterministic behavior is only useful when it is
|
|
19
|
+
applied consistently. A seed is not enough if callers cannot checkpoint the
|
|
20
|
+
current stream, resume it later, or understand which helper owns the active
|
|
21
|
+
random function. By keeping those responsibilities together, the network
|
|
22
|
+
surface stays reproducible across tests, debugging sessions, and long-running
|
|
23
|
+
experiments.
|
|
24
|
+
|
|
25
|
+
Another useful lens is to think in terms of branching timelines. Training or
|
|
26
|
+
evolution often needs to ask, "what happens if I continue from exactly this
|
|
27
|
+
stochastic point but change one later decision?" The deterministic helpers in
|
|
28
|
+
this folder are the bridge that makes that question answerable instead of
|
|
29
|
+
approximate.
|
|
30
|
+
|
|
31
|
+
```mermaid
|
|
32
|
+
flowchart LR
|
|
33
|
+
classDef base fill:#08131f,stroke:#1ea7ff,color:#dff6ff,stroke-width:1px;
|
|
34
|
+
classDef accent fill:#0f2233,stroke:#ffd166,color:#fff4cc,stroke-width:1.5px;
|
|
35
|
+
|
|
36
|
+
Seed[setSeed]:::accent --> RandomOps[stochastic network operations]:::base
|
|
37
|
+
RandomOps --> State[getRNGState checkpoint]:::base
|
|
38
|
+
RandomOps --> Snapshot[snapshotRNG lifecycle snapshot]:::base
|
|
39
|
+
State --> Resume[setRNGState resume]:::accent
|
|
40
|
+
Snapshot --> Restore[restoreRNG external restore]:::accent
|
|
41
|
+
```
|
|
4
42
|
|
|
5
|
-
|
|
43
|
+
```mermaid
|
|
44
|
+
flowchart TD
|
|
45
|
+
classDef base fill:#08131f,stroke:#1ea7ff,color:#dff6ff,stroke-width:1px;
|
|
46
|
+
classDef accent fill:#0f2233,stroke:#ffd166,color:#fff4cc,stroke-width:1.5px;
|
|
6
47
|
|
|
7
|
-
|
|
48
|
+
DeterministicChapter[deterministic/]:::accent --> Setup[setup utils<br/>install seed-backed RNG]:::base
|
|
49
|
+
DeterministicChapter --> State[state utils<br/>read and write numeric state]:::base
|
|
50
|
+
DeterministicChapter --> Lifecycle[lifecycle utils<br/>snapshot and restore]:::base
|
|
51
|
+
```
|
|
8
52
|
|
|
9
|
-
|
|
53
|
+
For background on why this chapter can stay reproducible with a small state
|
|
54
|
+
surface, see Wikipedia contributors,
|
|
55
|
+
[Pseudorandom number generator](https://en.wikipedia.org/wiki/Pseudorandom_number_generator).
|
|
56
|
+
The exported helpers here are about managing one deterministic stream, not
|
|
57
|
+
about generating cryptographic randomness.
|
|
10
58
|
|
|
11
|
-
|
|
59
|
+
Example: initialize one reproducible random stream and checkpoint its numeric
|
|
60
|
+
state for later reuse.
|
|
12
61
|
|
|
13
|
-
|
|
62
|
+
```ts
|
|
63
|
+
network.setSeed(42);
|
|
64
|
+
const checkpoint = network.getRNGState();
|
|
14
65
|
|
|
15
|
-
|
|
66
|
+
if (checkpoint !== undefined) {
|
|
67
|
+
network.setRNGState(checkpoint);
|
|
68
|
+
}
|
|
69
|
+
```
|
|
16
70
|
|
|
17
|
-
|
|
71
|
+
Example: capture a portable snapshot before branching into a debugging or
|
|
72
|
+
replay workflow.
|
|
18
73
|
|
|
19
|
-
|
|
74
|
+
```ts
|
|
75
|
+
network.setSeed(7);
|
|
76
|
+
const snapshot = network.snapshotRNG();
|
|
20
77
|
|
|
21
|
-
|
|
78
|
+
console.log(snapshot.state, snapshot.step);
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Practical reading order:
|
|
22
82
|
|
|
23
|
-
|
|
83
|
+
1. Start here for the public deterministic helpers and their intended use.
|
|
84
|
+
2. Continue into `network.deterministic.setup.utils.ts` for seed-backed RNG
|
|
85
|
+
installation.
|
|
86
|
+
3. Continue into `network.deterministic.state.utils.ts` for numeric
|
|
87
|
+
checkpoint accessors.
|
|
88
|
+
4. Finish in `network.deterministic.lifecycle.utils.ts` when you want the
|
|
89
|
+
richer snapshot and restore plumbing.
|
|
24
90
|
|
|
25
|
-
|
|
91
|
+
## architecture/network/deterministic/network.deterministic.utils.ts
|
|
26
92
|
|
|
27
93
|
### getRandomFn
|
|
28
94
|
|
|
@@ -181,6 +247,24 @@ Example:
|
|
|
181
247
|
const snapshot = network.snapshotRNG();
|
|
182
248
|
```
|
|
183
249
|
|
|
250
|
+
## architecture/network/deterministic/network.deterministic.utils.types.ts
|
|
251
|
+
|
|
252
|
+
### NetworkInternals
|
|
253
|
+
|
|
254
|
+
Internal deterministic network state shape used across deterministic utility modules.
|
|
255
|
+
|
|
256
|
+
### RNG_WEYL_INCREMENT
|
|
257
|
+
|
|
258
|
+
Fixed Weyl increment used to advance deterministic PRNG state.
|
|
259
|
+
|
|
260
|
+
### RNGSnapshot
|
|
261
|
+
|
|
262
|
+
Snapshot payload for RNG state restore flows.
|
|
263
|
+
|
|
264
|
+
### UINT32_NORMALIZER
|
|
265
|
+
|
|
266
|
+
Divisor used to normalize uint32 PRNG output into [0, 1).
|
|
267
|
+
|
|
184
268
|
## architecture/network/deterministic/network.deterministic.setup.utils.ts
|
|
185
269
|
|
|
186
270
|
### advanceStateWithWeylIncrement
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"introFile": "network.deterministic.utils.ts",
|
|
3
|
+
"fileOrder": [
|
|
4
|
+
"network.deterministic.utils.ts",
|
|
5
|
+
"network.deterministic.utils.types.ts",
|
|
6
|
+
"network.deterministic.setup.utils.ts",
|
|
7
|
+
"network.deterministic.state.utils.ts",
|
|
8
|
+
"network.deterministic.lifecycle.utils.ts"
|
|
9
|
+
]
|
|
10
|
+
}
|
|
@@ -1,3 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deterministic RNG chapter for replayable `Network` behavior.
|
|
3
|
+
*
|
|
4
|
+
* This folder keeps random state explicit so stochastic network behavior can be
|
|
5
|
+
* repeated instead of merely hoped for. The same graph may use randomness for
|
|
6
|
+
* dropout, stochastic depth, weight noise, training-time perturbations, or
|
|
7
|
+
* mutation-adjacent helpers. Deterministic utilities give those flows a common
|
|
8
|
+
* seed, checkpoint, and restore surface.
|
|
9
|
+
*
|
|
10
|
+
* The important design split is between setup, state access, and lifecycle
|
|
11
|
+
* capture. `setSeed()` installs a reproducible random stream. `getRNGState()`
|
|
12
|
+
* and `setRNGState()` expose lightweight numeric checkpoints for pause-resume
|
|
13
|
+
* workflows. `snapshotRNG()` and `restoreRNG()` support the slightly richer
|
|
14
|
+
* lifecycle case where external tooling wants to branch or reconstruct the
|
|
15
|
+
* active random function more deliberately.
|
|
16
|
+
*
|
|
17
|
+
* This chapter matters because deterministic behavior is only useful when it is
|
|
18
|
+
* applied consistently. A seed is not enough if callers cannot checkpoint the
|
|
19
|
+
* current stream, resume it later, or understand which helper owns the active
|
|
20
|
+
* random function. By keeping those responsibilities together, the network
|
|
21
|
+
* surface stays reproducible across tests, debugging sessions, and long-running
|
|
22
|
+
* experiments.
|
|
23
|
+
*
|
|
24
|
+
* Another useful lens is to think in terms of branching timelines. Training or
|
|
25
|
+
* evolution often needs to ask, "what happens if I continue from exactly this
|
|
26
|
+
* stochastic point but change one later decision?" The deterministic helpers in
|
|
27
|
+
* this folder are the bridge that makes that question answerable instead of
|
|
28
|
+
* approximate.
|
|
29
|
+
*
|
|
30
|
+
* ```mermaid
|
|
31
|
+
* flowchart LR
|
|
32
|
+
* classDef base fill:#08131f,stroke:#1ea7ff,color:#dff6ff,stroke-width:1px;
|
|
33
|
+
* classDef accent fill:#0f2233,stroke:#ffd166,color:#fff4cc,stroke-width:1.5px;
|
|
34
|
+
*
|
|
35
|
+
* Seed[setSeed]:::accent --> RandomOps[stochastic network operations]:::base
|
|
36
|
+
* RandomOps --> State[getRNGState checkpoint]:::base
|
|
37
|
+
* RandomOps --> Snapshot[snapshotRNG lifecycle snapshot]:::base
|
|
38
|
+
* State --> Resume[setRNGState resume]:::accent
|
|
39
|
+
* Snapshot --> Restore[restoreRNG external restore]:::accent
|
|
40
|
+
* ```
|
|
41
|
+
*
|
|
42
|
+
* ```mermaid
|
|
43
|
+
* flowchart TD
|
|
44
|
+
* classDef base fill:#08131f,stroke:#1ea7ff,color:#dff6ff,stroke-width:1px;
|
|
45
|
+
* classDef accent fill:#0f2233,stroke:#ffd166,color:#fff4cc,stroke-width:1.5px;
|
|
46
|
+
*
|
|
47
|
+
* DeterministicChapter[deterministic/]:::accent --> Setup[setup utils<br/>install seed-backed RNG]:::base
|
|
48
|
+
* DeterministicChapter --> State[state utils<br/>read and write numeric state]:::base
|
|
49
|
+
* DeterministicChapter --> Lifecycle[lifecycle utils<br/>snapshot and restore]:::base
|
|
50
|
+
* ```
|
|
51
|
+
*
|
|
52
|
+
* For background on why this chapter can stay reproducible with a small state
|
|
53
|
+
* surface, see Wikipedia contributors,
|
|
54
|
+
* [Pseudorandom number generator](https://en.wikipedia.org/wiki/Pseudorandom_number_generator).
|
|
55
|
+
* The exported helpers here are about managing one deterministic stream, not
|
|
56
|
+
* about generating cryptographic randomness.
|
|
57
|
+
*
|
|
58
|
+
* Example: initialize one reproducible random stream and checkpoint its numeric
|
|
59
|
+
* state for later reuse.
|
|
60
|
+
*
|
|
61
|
+
* ```ts
|
|
62
|
+
* network.setSeed(42);
|
|
63
|
+
* const checkpoint = network.getRNGState();
|
|
64
|
+
*
|
|
65
|
+
* if (checkpoint !== undefined) {
|
|
66
|
+
* network.setRNGState(checkpoint);
|
|
67
|
+
* }
|
|
68
|
+
* ```
|
|
69
|
+
*
|
|
70
|
+
* Example: capture a portable snapshot before branching into a debugging or
|
|
71
|
+
* replay workflow.
|
|
72
|
+
*
|
|
73
|
+
* ```ts
|
|
74
|
+
* network.setSeed(7);
|
|
75
|
+
* const snapshot = network.snapshotRNG();
|
|
76
|
+
*
|
|
77
|
+
* console.log(snapshot.state, snapshot.step);
|
|
78
|
+
* ```
|
|
79
|
+
*
|
|
80
|
+
* Practical reading order:
|
|
81
|
+
*
|
|
82
|
+
* 1. Start here for the public deterministic helpers and their intended use.
|
|
83
|
+
* 2. Continue into `network.deterministic.setup.utils.ts` for seed-backed RNG
|
|
84
|
+
* installation.
|
|
85
|
+
* 3. Continue into `network.deterministic.state.utils.ts` for numeric
|
|
86
|
+
* checkpoint accessors.
|
|
87
|
+
* 4. Finish in `network.deterministic.lifecycle.utils.ts` when you want the
|
|
88
|
+
* richer snapshot and restore plumbing.
|
|
89
|
+
*/
|
|
90
|
+
|
|
1
91
|
import type Network from '../../network/network';
|
|
2
92
|
import type { RNGSnapshot } from './network.deterministic.utils.types';
|
|
3
93
|
import { setSeed as setupSeed } from './network.deterministic.setup.utils';
|