@reicek/neataptic-ts 0.1.25 → 0.1.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/copilot-instructions.md +11 -0
- package/.github/skills/trace-analyzer-extension/SKILL.md +3 -3
- package/.github/skills/trace-analyzer-extension/assets/extension-checklist.md +1 -1
- package/.github/skills/trace-analyzer-extension/references/analyzer-extension-workflow.md +1 -1
- package/.github/skills/trace-audit-reporting/SKILL.md +3 -3
- package/.github/skills/trace-audit-reporting/references/trace-analysis-workflow.md +1 -1
- package/package.json +19 -13
- package/plans/Flappy_Bird_Folder_Documentation_Pass.md +4 -4
- package/plans/README.md +24 -0
- package/plans/Roadmap.md +62 -40
- package/plans/analyze-trace-solid-split.plans.md +66 -0
- package/plans/architecture-solid-split.plans.md +9 -15
- package/plans/asciiMaze-typescript-repair.plans.md +1 -1
- package/plans/generate-docs-solid-split.plans.md +87 -0
- package/plans/methods-docs.plans.md +25 -1
- package/plans/methods-solid-split.plans.md +14 -14
- package/plans/neat-docs.plans.md +9 -1
- package/plans/neat-test-surface-repair.plans.md +1 -1
- package/plans/render-docs-html-solid-split.plans.md +68 -0
- package/plans/src-no-explicit-any-cleanup.plans.md +1 -1
- package/plans/utils-docs.plans.md +6 -1
- package/scripts/analyze-trace/analyze-trace.analysis.ts +479 -0
- package/scripts/analyze-trace/analyze-trace.constants.ts +35 -0
- package/scripts/analyze-trace/analyze-trace.io.ts +69 -0
- package/scripts/analyze-trace/analyze-trace.report.ts +100 -0
- package/scripts/analyze-trace/analyze-trace.shared.ts +116 -0
- package/scripts/analyze-trace/analyze-trace.ts +45 -0
- package/scripts/analyze-trace/analyze-trace.types.ts +72 -0
- package/scripts/assets/theme.css +80 -23
- package/scripts/copy-examples.ts +239 -0
- package/scripts/export-onnx.ts +223 -0
- package/scripts/generate-bench-tables.ts +378 -37
- package/scripts/generate-docs/generate-docs.constants.ts +107 -0
- package/scripts/generate-docs/generate-docs.order.ts +355 -0
- package/scripts/generate-docs/generate-docs.state.ts +31 -0
- package/scripts/generate-docs/generate-docs.targets.ts +165 -0
- package/scripts/generate-docs/generate-docs.ts +63 -0
- package/scripts/generate-docs/generate-docs.types.ts +112 -0
- package/scripts/generate-docs/output/generate-docs.output.folder-index.utils.ts +167 -0
- package/scripts/generate-docs/output/generate-docs.output.ordering.utils.ts +353 -0
- package/scripts/generate-docs/output/generate-docs.output.readme.utils.ts +420 -0
- package/scripts/generate-docs/output/generate-docs.output.ts +123 -0
- package/scripts/generate-docs/output/generate-docs.output.warnings.utils.ts +219 -0
- package/scripts/generate-docs/symbols/generate-docs.symbols.collection.utils.ts +365 -0
- package/scripts/generate-docs/symbols/generate-docs.symbols.jsdoc.utils.ts +373 -0
- package/scripts/generate-docs/symbols/generate-docs.symbols.normalize.utils.ts +155 -0
- package/scripts/generate-docs/symbols/generate-docs.symbols.render.utils.ts +149 -0
- package/scripts/generate-docs/symbols/generate-docs.symbols.signature.utils.ts +289 -0
- package/scripts/generate-docs/symbols/generate-docs.symbols.ts +11 -0
- package/scripts/mermaid-cli.mjs +102 -22
- package/scripts/mermaid-cli.ts +736 -0
- package/scripts/render-docs-html/render-docs-html.assets.ts +54 -0
- package/scripts/render-docs-html/render-docs-html.mermaid.ts +245 -0
- package/scripts/{render-docs-html.sidebar.ts → render-docs-html/render-docs-html.navigation.ts} +141 -144
- package/scripts/render-docs-html/render-docs-html.pages.ts +333 -0
- package/scripts/render-docs-html/render-docs-html.shared.ts +333 -0
- package/scripts/render-docs-html/render-docs-html.types.ts +42 -0
- package/scripts/render-docs-html.ts +23 -587
- package/scripts/run-docs.ts +238 -0
- package/scripts/write-dist-docs-pkg.ts +40 -0
- package/src/README.md +75 -75
- package/src/architecture/connection/README.md +5 -5
- package/src/architecture/layer/README.md +508 -508
- package/src/architecture/network/README.md +1458 -1458
- package/src/architecture/network/activate/README.md +694 -694
- package/src/architecture/network/bootstrap/README.md +77 -77
- package/src/architecture/network/connect/README.md +74 -74
- package/src/architecture/network/deterministic/README.md +135 -135
- package/src/architecture/network/evolve/README.md +364 -364
- package/src/architecture/network/gating/README.md +130 -130
- package/src/architecture/network/genetic/README.md +399 -399
- package/src/architecture/network/mutate/README.md +897 -897
- package/src/architecture/network/onnx/README.md +720 -720
- package/src/architecture/network/onnx/export/README.md +728 -728
- package/src/architecture/network/onnx/export/layers/README.md +450 -450
- package/src/architecture/network/onnx/import/README.md +618 -618
- package/src/architecture/network/onnx/schema/README.md +32 -32
- package/src/architecture/network/prune/README.md +245 -245
- package/src/architecture/network/remove/README.md +135 -135
- package/src/architecture/network/runtime/README.md +106 -106
- package/src/architecture/network/serialize/README.md +542 -542
- package/src/architecture/network/slab/README.md +608 -608
- package/src/architecture/network/standalone/README.md +212 -212
- package/src/architecture/network/stats/README.md +84 -84
- package/src/architecture/network/topology/README.md +465 -465
- package/src/architecture/network/training/README.md +200 -200
- package/src/architecture/node/README.md +5 -5
- package/src/architecture/nodePool/README.md +14 -14
- package/src/methods/README.md +99 -99
- package/src/methods/activation/README.md +189 -189
- package/src/methods/cost/README.md +131 -131
- package/src/methods/rate/README.md +86 -86
- package/src/multithreading/README.md +77 -77
- package/src/multithreading/workers/browser/README.md +8 -8
- package/src/multithreading/workers/node/README.md +8 -8
- package/src/neat/README.md +148 -148
- package/src/neat/adaptive/README.md +120 -120
- package/src/neat/adaptive/acceptance/README.md +40 -40
- package/src/neat/adaptive/complexity/README.md +137 -137
- package/src/neat/adaptive/core/README.md +197 -197
- package/src/neat/adaptive/lineage/README.md +90 -90
- package/src/neat/adaptive/mutation/README.md +284 -284
- package/src/neat/compat/README.md +43 -43
- package/src/neat/compat/core/README.md +90 -90
- package/src/neat/diversity/README.md +35 -35
- package/src/neat/diversity/core/README.md +88 -88
- package/src/neat/evaluate/README.md +85 -85
- package/src/neat/evaluate/auto-distance/README.md +75 -75
- package/src/neat/evaluate/entropy-compat/README.md +37 -37
- package/src/neat/evaluate/entropy-sharing/README.md +43 -43
- package/src/neat/evaluate/fitness/README.md +23 -23
- package/src/neat/evaluate/novelty/README.md +120 -120
- package/src/neat/evaluate/objectives/README.md +17 -17
- package/src/neat/evaluate/shared/README.md +94 -94
- package/src/neat/evolve/README.md +96 -96
- package/src/neat/evolve/adaptive/README.md +60 -60
- package/src/neat/evolve/objectives/README.md +63 -63
- package/src/neat/evolve/offspring/README.md +56 -56
- package/src/neat/evolve/population/README.md +171 -171
- package/src/neat/evolve/runtime/README.md +79 -79
- package/src/neat/evolve/speciation/README.md +74 -74
- package/src/neat/evolve/warnings/README.md +10 -10
- package/src/neat/export/README.md +114 -114
- package/src/neat/helpers/README.md +50 -50
- package/src/neat/init/README.md +9 -9
- package/src/neat/lineage/core/README.md +101 -101
- package/src/neat/multiobjective/category/README.md +74 -74
- package/src/neat/multiobjective/crowding/README.md +272 -272
- package/src/neat/multiobjective/dominance/README.md +171 -171
- package/src/neat/multiobjective/fronts/README.md +68 -68
- package/src/neat/multiobjective/metrics/README.md +43 -43
- package/src/neat/multiobjective/objectives/README.md +31 -31
- package/src/neat/multiobjective/shared/README.md +27 -27
- package/src/neat/mutation/README.md +97 -97
- package/src/neat/mutation/add-conn/README.md +115 -115
- package/src/neat/mutation/add-node/README.md +126 -126
- package/src/neat/mutation/flow/README.md +149 -149
- package/src/neat/mutation/repair/README.md +185 -185
- package/src/neat/mutation/select/README.md +117 -117
- package/src/neat/mutation/shared/README.md +32 -32
- package/src/neat/objectives/README.md +25 -25
- package/src/neat/objectives/core/README.md +67 -67
- package/src/neat/pruning/README.md +40 -40
- package/src/neat/pruning/core/README.md +171 -171
- package/src/neat/pruning/facade/README.md +32 -32
- package/src/neat/rng/README.md +104 -104
- package/src/neat/rng/core/README.md +137 -137
- package/src/neat/rng/facade/README.md +50 -50
- package/src/neat/selection/README.md +111 -111
- package/src/neat/selection/core/README.md +227 -227
- package/src/neat/selection/facade/README.md +61 -61
- package/src/neat/shared/README.md +163 -163
- package/src/neat/speciation/README.md +31 -31
- package/src/neat/speciation/threshold/README.md +35 -35
- package/src/neat/species/README.md +25 -25
- package/src/neat/species/core/README.md +20 -20
- package/src/neat/species/core/shared/README.md +18 -18
- package/src/neat/species/history/context/README.md +22 -22
- package/src/neat/telemetry/accessors/README.md +58 -58
- package/src/neat/telemetry/exports/README.md +233 -233
- package/src/neat/telemetry/facade/README.md +252 -252
- package/src/neat/telemetry/facade/archive/README.md +57 -57
- package/src/neat/telemetry/facade/buffer/README.md +43 -43
- package/src/neat/telemetry/facade/lineage/README.md +12 -12
- package/src/neat/telemetry/facade/objectives/README.md +44 -44
- package/src/neat/telemetry/facade/runtime/README.md +26 -26
- package/src/neat/telemetry/facade/species/README.md +27 -27
- package/src/neat/telemetry/metrics/README.md +696 -696
- package/src/neat/telemetry/recorder/README.md +57 -57
- package/src/neat/telemetry/types/README.md +32 -32
- package/src/neat/topology-intent/README.md +75 -75
- package/src/utils/README.md +193 -193
- package/test/examples/asciiMaze/browser-entry/README.md +92 -92
- package/test/examples/asciiMaze/dashboardManager/README.md +109 -109
- package/test/examples/asciiMaze/dashboardManager/telemetry/README.md +28 -28
- package/test/examples/asciiMaze/evolutionEngine/README.md +1527 -1527
- package/test/examples/asciiMaze/mazeMovement/README.md +105 -105
- package/test/examples/asciiMaze/mazeMovement/finalization/README.md +16 -16
- package/test/examples/asciiMaze/mazeMovement/policy/README.md +57 -57
- package/test/examples/asciiMaze/mazeMovement/runtime/README.md +52 -52
- package/test/examples/asciiMaze/mazeMovement/shaping/README.md +46 -46
- package/test/examples/flappy_bird/browser-entry/README.md +508 -508
- package/test/examples/flappy_bird/browser-entry/host/README.md +101 -101
- package/test/examples/flappy_bird/browser-entry/host/resize/README.md +144 -144
- package/test/examples/flappy_bird/browser-entry/network-view/README.md +194 -194
- package/test/examples/flappy_bird/browser-entry/playback/README.md +278 -278
- package/test/examples/flappy_bird/browser-entry/playback/background/README.md +129 -129
- package/test/examples/flappy_bird/browser-entry/playback/background/ground-grid/README.md +502 -502
- package/test/examples/flappy_bird/browser-entry/playback/frame-render/README.md +139 -139
- package/test/examples/flappy_bird/browser-entry/playback/snapshot/README.md +10 -10
- package/test/examples/flappy_bird/browser-entry/playback/trail/README.md +43 -43
- package/test/examples/flappy_bird/browser-entry/playback/worker-channel/README.md +30 -30
- package/test/examples/flappy_bird/browser-entry/runtime/README.md +59 -59
- package/test/examples/flappy_bird/browser-entry/visualization/README.md +276 -276
- package/test/examples/flappy_bird/browser-entry/worker-channel/README.md +16 -16
- package/test/examples/flappy_bird/constants/README.md +1070 -1070
- package/test/examples/flappy_bird/environment/README.md +22 -22
- package/test/examples/flappy_bird/evaluation/README.md +32 -32
- package/test/examples/flappy_bird/evaluation/rollout/README.md +141 -141
- package/test/examples/flappy_bird/flappy-evolution-worker/README.md +425 -425
- package/test/examples/flappy_bird/simulation-shared/README.md +170 -170
- package/test/examples/flappy_bird/simulation-shared/observation/README.md +109 -109
- package/test/examples/flappy_bird/trainer/README.md +325 -325
- package/test/examples/flappy_bird/trainer/evaluation/README.md +74 -74
- package/scripts/analyze-trace.ts +0 -590
- package/scripts/copy-examples.mjs +0 -114
- package/scripts/export-onnx.mjs +0 -86
- package/scripts/generate-bench-tables.mjs +0 -182
- package/scripts/generate-docs.ts +0 -2900
- package/scripts/write-dist-docs-pkg.mjs +0 -16
|
@@ -374,38 +374,6 @@ const activationContext: LayerActivationContext = {
|
|
|
374
374
|
// activateLayer(activationContext, values, true)
|
|
375
375
|
```
|
|
376
376
|
|
|
377
|
-
### LayerPropagationContext
|
|
378
|
-
|
|
379
|
-
Minimal state required to run backpropagation helpers.
|
|
380
|
-
|
|
381
|
-
Helpers only need access to the node sequence to propagate in reverse order.
|
|
382
|
-
|
|
383
|
-
Example:
|
|
384
|
-
|
|
385
|
-
```ts
|
|
386
|
-
const propagationContext: LayerPropagationContext = { nodes: layer.nodes };
|
|
387
|
-
|
|
388
|
-
// propagateLayer(propagationContext, 0.3, 0.1, targets)
|
|
389
|
-
```
|
|
390
|
-
|
|
391
|
-
### LayerLike
|
|
392
|
-
|
|
393
|
-
Structural contract for "layer-like" objects used in utility wiring.
|
|
394
|
-
|
|
395
|
-
This type avoids direct class coupling while preserving the behaviors needed
|
|
396
|
-
by connection helpers (`input`, `nodes`, and `output`).
|
|
397
|
-
|
|
398
|
-
Example:
|
|
399
|
-
|
|
400
|
-
```ts
|
|
401
|
-
// A real layer class typically satisfies this shape.
|
|
402
|
-
const layerLike: LayerLike = {
|
|
403
|
-
input: (from) => [],
|
|
404
|
-
nodes: [],
|
|
405
|
-
output: null,
|
|
406
|
-
};
|
|
407
|
-
```
|
|
408
|
-
|
|
409
377
|
### LayerConnectionContext
|
|
410
378
|
|
|
411
379
|
Context bundle required by connection/disconnection orchestration.
|
|
@@ -426,6 +394,23 @@ const connectionContext: LayerConnectionContext = {
|
|
|
426
394
|
};
|
|
427
395
|
```
|
|
428
396
|
|
|
397
|
+
### LayerFactoryContext
|
|
398
|
+
|
|
399
|
+
Generic factory context used to create layers without circular imports.
|
|
400
|
+
|
|
401
|
+
`createLayer` builds the target instance, and `isLayer` enables structural
|
|
402
|
+
narrowing whenever helpers accept mixed layer/group values.
|
|
403
|
+
|
|
404
|
+
Example:
|
|
405
|
+
|
|
406
|
+
```ts
|
|
407
|
+
const factoryContext: LayerFactoryContext<MyLayer> = {
|
|
408
|
+
createLayer: () => new MyLayer(),
|
|
409
|
+
isLayer: (value): value is LayerLike =>
|
|
410
|
+
!!value && typeof (value as LayerLike).input === 'function',
|
|
411
|
+
};
|
|
412
|
+
```
|
|
413
|
+
|
|
429
414
|
### LayerFactoryLayer
|
|
430
415
|
|
|
431
416
|
Public layer surface required by factory construction helpers.
|
|
@@ -439,23 +424,38 @@ Example:
|
|
|
439
424
|
// (Concrete layer classes typically provide many more helpers.)
|
|
440
425
|
```
|
|
441
426
|
|
|
442
|
-
###
|
|
427
|
+
### LayerLike
|
|
443
428
|
|
|
444
|
-
|
|
429
|
+
Structural contract for "layer-like" objects used in utility wiring.
|
|
445
430
|
|
|
446
|
-
|
|
447
|
-
|
|
431
|
+
This type avoids direct class coupling while preserving the behaviors needed
|
|
432
|
+
by connection helpers (`input`, `nodes`, and `output`).
|
|
448
433
|
|
|
449
434
|
Example:
|
|
450
435
|
|
|
451
436
|
```ts
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
437
|
+
// A real layer class typically satisfies this shape.
|
|
438
|
+
const layerLike: LayerLike = {
|
|
439
|
+
input: (from) => [],
|
|
440
|
+
nodes: [],
|
|
441
|
+
output: null,
|
|
456
442
|
};
|
|
457
443
|
```
|
|
458
444
|
|
|
445
|
+
### LayerPropagationContext
|
|
446
|
+
|
|
447
|
+
Minimal state required to run backpropagation helpers.
|
|
448
|
+
|
|
449
|
+
Helpers only need access to the node sequence to propagate in reverse order.
|
|
450
|
+
|
|
451
|
+
Example:
|
|
452
|
+
|
|
453
|
+
```ts
|
|
454
|
+
const propagationContext: LayerPropagationContext = { nodes: layer.nodes };
|
|
455
|
+
|
|
456
|
+
// propagateLayer(propagationContext, 0.3, 0.1, targets)
|
|
457
|
+
```
|
|
458
|
+
|
|
459
459
|
## architecture/layer/layer.utils.ts
|
|
460
460
|
|
|
461
461
|
### activateLayer
|
|
@@ -498,38 +498,24 @@ Parameters:
|
|
|
498
498
|
|
|
499
499
|
Returns: A cloned array of activation values.
|
|
500
500
|
|
|
501
|
-
###
|
|
501
|
+
### clearLayer
|
|
502
502
|
|
|
503
503
|
```ts
|
|
504
|
-
|
|
505
|
-
context:
|
|
506
|
-
rate: number,
|
|
507
|
-
momentum: number,
|
|
508
|
-
targets: number[] | undefined,
|
|
504
|
+
clearLayer(
|
|
505
|
+
context: LayerConnectionContext,
|
|
509
506
|
): void
|
|
510
507
|
```
|
|
511
508
|
|
|
512
|
-
Orchestrates
|
|
513
|
-
|
|
514
|
-
If `targets` is provided, it must be one value per node (output layer).
|
|
515
|
-
If omitted, propagation behaves like a hidden layer.
|
|
509
|
+
Orchestrates clearing node activation state with a high-level flow.
|
|
516
510
|
|
|
517
|
-
|
|
511
|
+
Parameters:
|
|
512
|
+
- `context` - - The layer state needed to reset nodes.
|
|
513
|
+
Example:
|
|
518
514
|
|
|
519
515
|
```ts
|
|
520
|
-
|
|
521
|
-
propagateLayer({ nodes: layer.nodes }, 0.3, 0.1);
|
|
522
|
-
|
|
523
|
-
// Output layer propagation.
|
|
524
|
-
propagateLayer({ nodes: layer.nodes }, 0.3, 0.1, [1, 0, 0]);
|
|
516
|
+
clearLayer(layerConnectionContext);
|
|
525
517
|
```
|
|
526
518
|
|
|
527
|
-
Parameters:
|
|
528
|
-
- `context` - - The layer state needed for propagation.
|
|
529
|
-
- `rate` - - The learning rate for weight updates.
|
|
530
|
-
- `momentum` - - The momentum factor for smoothing updates.
|
|
531
|
-
- `targets` - - Optional target values for output layers.
|
|
532
|
-
|
|
533
519
|
### connectLayer
|
|
534
520
|
|
|
535
521
|
```ts
|
|
@@ -560,161 +546,166 @@ Parameters:
|
|
|
560
546
|
|
|
561
547
|
Returns: The created connection list.
|
|
562
548
|
|
|
563
|
-
###
|
|
549
|
+
### createAttentionLayer
|
|
564
550
|
|
|
565
551
|
```ts
|
|
566
|
-
|
|
567
|
-
context:
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
):
|
|
552
|
+
createAttentionLayer(
|
|
553
|
+
context: LayerFactoryContext<TLayer>,
|
|
554
|
+
size: number,
|
|
555
|
+
heads: number,
|
|
556
|
+
): TLayer
|
|
571
557
|
```
|
|
572
558
|
|
|
573
|
-
Orchestrates layer
|
|
559
|
+
Orchestrates attention layer creation with a high-level flow.
|
|
560
|
+
|
|
561
|
+
Parameters:
|
|
562
|
+
- `context` - - Factory helpers for constructing the layer instance.
|
|
563
|
+
- `size` - - Number of output nodes.
|
|
564
|
+
- `heads` - - Number of attention heads.
|
|
574
565
|
|
|
566
|
+
Returns: The configured layer instance.
|
|
575
567
|
Example:
|
|
576
568
|
|
|
577
569
|
```ts
|
|
578
|
-
|
|
570
|
+
const attention = createAttentionLayer(factoryContext, 8, 4);
|
|
579
571
|
```
|
|
580
572
|
|
|
581
|
-
|
|
582
|
-
- `context` - - The layer state needed for gating.
|
|
583
|
-
- `connections` - - The connections to gate.
|
|
584
|
-
- `method` - - The gating method.
|
|
585
|
-
|
|
586
|
-
### inputLayer
|
|
573
|
+
### createBatchNormLayer
|
|
587
574
|
|
|
588
575
|
```ts
|
|
589
|
-
|
|
590
|
-
context:
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
weight: number | undefined,
|
|
594
|
-
): default[]
|
|
576
|
+
createBatchNormLayer(
|
|
577
|
+
context: LayerFactoryContext<TLayer>,
|
|
578
|
+
size: number,
|
|
579
|
+
): TLayer
|
|
595
580
|
```
|
|
596
581
|
|
|
597
|
-
Orchestrates layer
|
|
582
|
+
Orchestrates batch normalization layer creation with a high-level flow.
|
|
583
|
+
|
|
584
|
+
Parameters:
|
|
585
|
+
- `context` - - Factory helpers for constructing the layer instance.
|
|
586
|
+
- `size` - - Number of nodes in the normalization layer.
|
|
598
587
|
|
|
588
|
+
Returns: The configured layer instance.
|
|
599
589
|
Example:
|
|
600
590
|
|
|
601
591
|
```ts
|
|
602
|
-
|
|
592
|
+
const batchNorm = createBatchNormLayer(factoryContext, 16);
|
|
603
593
|
```
|
|
604
594
|
|
|
605
|
-
|
|
606
|
-
- `context` - - The layer state needed for input wiring.
|
|
607
|
-
- `from` - - The source layer or group.
|
|
608
|
-
- `method` - - Optional connection method override.
|
|
609
|
-
- `weight` - - Optional fixed weight to apply.
|
|
610
|
-
|
|
611
|
-
Returns: The created connection list.
|
|
612
|
-
|
|
613
|
-
### disconnectLayer
|
|
595
|
+
### createConv1dLayer
|
|
614
596
|
|
|
615
597
|
```ts
|
|
616
|
-
|
|
617
|
-
context:
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
598
|
+
createConv1dLayer(
|
|
599
|
+
context: LayerFactoryContext<TLayer>,
|
|
600
|
+
size: number,
|
|
601
|
+
kernelSize: number,
|
|
602
|
+
stride: number,
|
|
603
|
+
padding: number,
|
|
604
|
+
): TLayer
|
|
621
605
|
```
|
|
622
606
|
|
|
623
|
-
Orchestrates
|
|
607
|
+
Orchestrates 1D convolution layer creation with a high-level flow.
|
|
608
|
+
|
|
609
|
+
Parameters:
|
|
610
|
+
- `context` - - Factory helpers for constructing the layer instance.
|
|
611
|
+
- `size` - - Number of output nodes.
|
|
612
|
+
- `kernelSize` - - Size of the convolution kernel.
|
|
613
|
+
- `stride` - - Stride of the convolution.
|
|
614
|
+
- `padding` - - Padding size for the convolution.
|
|
624
615
|
|
|
616
|
+
Returns: The configured layer instance.
|
|
625
617
|
Example:
|
|
626
618
|
|
|
627
619
|
```ts
|
|
628
|
-
|
|
620
|
+
const conv1d = createConv1dLayer(factoryContext, 8, 3);
|
|
629
621
|
```
|
|
630
622
|
|
|
631
|
-
|
|
632
|
-
- `context` - - The layer state needed for disconnecting.
|
|
633
|
-
- `target` - - The group or node to disconnect.
|
|
634
|
-
- `twoSided` - - Whether to remove reciprocal connections as well.
|
|
635
|
-
|
|
636
|
-
### clearLayer
|
|
623
|
+
### createDenseLayer
|
|
637
624
|
|
|
638
625
|
```ts
|
|
639
|
-
|
|
640
|
-
context:
|
|
641
|
-
|
|
626
|
+
createDenseLayer(
|
|
627
|
+
context: LayerFactoryContext<TLayer>,
|
|
628
|
+
size: number,
|
|
629
|
+
): TLayer
|
|
642
630
|
```
|
|
643
631
|
|
|
644
|
-
Orchestrates
|
|
632
|
+
Orchestrates dense layer creation with a high-level flow.
|
|
645
633
|
|
|
646
634
|
Parameters:
|
|
647
|
-
- `context` - -
|
|
635
|
+
- `context` - - Factory helpers for constructing the layer instance.
|
|
636
|
+
- `size` - - Number of nodes in the dense layer.
|
|
637
|
+
|
|
638
|
+
Returns: The configured layer instance.
|
|
648
639
|
Example:
|
|
649
640
|
|
|
650
641
|
```ts
|
|
651
|
-
|
|
642
|
+
const dense = createDenseLayer(factoryContext, 8);
|
|
652
643
|
```
|
|
653
644
|
|
|
654
|
-
###
|
|
645
|
+
### createGruLayer
|
|
655
646
|
|
|
656
647
|
```ts
|
|
657
|
-
|
|
648
|
+
createGruLayer(
|
|
658
649
|
context: LayerFactoryContext<TLayer>,
|
|
659
650
|
size: number,
|
|
660
651
|
): TLayer
|
|
661
652
|
```
|
|
662
653
|
|
|
663
|
-
Orchestrates
|
|
654
|
+
Orchestrates GRU layer creation with a high-level flow.
|
|
664
655
|
|
|
665
656
|
Parameters:
|
|
666
657
|
- `context` - - Factory helpers for constructing the layer instance.
|
|
667
|
-
- `size` - - Number of
|
|
658
|
+
- `size` - - Number of units in the GRU layer.
|
|
668
659
|
|
|
669
660
|
Returns: The configured layer instance.
|
|
670
661
|
Example:
|
|
671
662
|
|
|
672
663
|
```ts
|
|
673
|
-
const
|
|
664
|
+
const gru = createGruLayer(factoryContext, 8);
|
|
674
665
|
```
|
|
675
666
|
|
|
676
|
-
###
|
|
667
|
+
### createLayerNormLayer
|
|
677
668
|
|
|
678
669
|
```ts
|
|
679
|
-
|
|
670
|
+
createLayerNormLayer(
|
|
680
671
|
context: LayerFactoryContext<TLayer>,
|
|
681
672
|
size: number,
|
|
682
673
|
): TLayer
|
|
683
674
|
```
|
|
684
675
|
|
|
685
|
-
Orchestrates
|
|
676
|
+
Orchestrates layer normalization layer creation with a high-level flow.
|
|
686
677
|
|
|
687
678
|
Parameters:
|
|
688
679
|
- `context` - - Factory helpers for constructing the layer instance.
|
|
689
|
-
- `size` - - Number of
|
|
680
|
+
- `size` - - Number of nodes in the normalization layer.
|
|
690
681
|
|
|
691
682
|
Returns: The configured layer instance.
|
|
692
683
|
Example:
|
|
693
684
|
|
|
694
685
|
```ts
|
|
695
|
-
const
|
|
686
|
+
const layerNorm = createLayerNormLayer(factoryContext, 16);
|
|
696
687
|
```
|
|
697
688
|
|
|
698
|
-
###
|
|
689
|
+
### createLstmLayer
|
|
699
690
|
|
|
700
691
|
```ts
|
|
701
|
-
|
|
692
|
+
createLstmLayer(
|
|
702
693
|
context: LayerFactoryContext<TLayer>,
|
|
703
694
|
size: number,
|
|
704
695
|
): TLayer
|
|
705
696
|
```
|
|
706
697
|
|
|
707
|
-
Orchestrates
|
|
698
|
+
Orchestrates LSTM layer creation with a high-level flow.
|
|
708
699
|
|
|
709
700
|
Parameters:
|
|
710
701
|
- `context` - - Factory helpers for constructing the layer instance.
|
|
711
|
-
- `size` - - Number of units in the
|
|
702
|
+
- `size` - - Number of units in the LSTM layer.
|
|
712
703
|
|
|
713
704
|
Returns: The configured layer instance.
|
|
714
705
|
Example:
|
|
715
706
|
|
|
716
707
|
```ts
|
|
717
|
-
const
|
|
708
|
+
const lstm = createLstmLayer(factoryContext, 8);
|
|
718
709
|
```
|
|
719
710
|
|
|
720
711
|
### createMemoryLayer
|
|
@@ -741,102 +732,111 @@ Example:
|
|
|
741
732
|
const memoryLayer = createMemoryLayer(factoryContext, 4, 3);
|
|
742
733
|
```
|
|
743
734
|
|
|
744
|
-
###
|
|
735
|
+
### disconnectLayer
|
|
745
736
|
|
|
746
737
|
```ts
|
|
747
|
-
|
|
748
|
-
context:
|
|
749
|
-
|
|
750
|
-
|
|
738
|
+
disconnectLayer(
|
|
739
|
+
context: LayerConnectionContext,
|
|
740
|
+
target: default | default,
|
|
741
|
+
twoSided: boolean,
|
|
742
|
+
): void
|
|
751
743
|
```
|
|
752
744
|
|
|
753
|
-
Orchestrates
|
|
754
|
-
|
|
755
|
-
Parameters:
|
|
756
|
-
- `context` - - Factory helpers for constructing the layer instance.
|
|
757
|
-
- `size` - - Number of nodes in the normalization layer.
|
|
745
|
+
Orchestrates disconnection behavior with a high-level flow.
|
|
758
746
|
|
|
759
|
-
Returns: The configured layer instance.
|
|
760
747
|
Example:
|
|
761
748
|
|
|
762
749
|
```ts
|
|
763
|
-
|
|
750
|
+
disconnectLayer(layerConnectionContext, someGroup, true);
|
|
764
751
|
```
|
|
765
752
|
|
|
766
|
-
|
|
753
|
+
Parameters:
|
|
754
|
+
- `context` - - The layer state needed for disconnecting.
|
|
755
|
+
- `target` - - The group or node to disconnect.
|
|
756
|
+
- `twoSided` - - Whether to remove reciprocal connections as well.
|
|
757
|
+
|
|
758
|
+
### gateLayer
|
|
767
759
|
|
|
768
760
|
```ts
|
|
769
|
-
|
|
770
|
-
context:
|
|
771
|
-
|
|
772
|
-
|
|
761
|
+
gateLayer(
|
|
762
|
+
context: LayerConnectionContext,
|
|
763
|
+
connections: default[],
|
|
764
|
+
method: unknown,
|
|
765
|
+
): void
|
|
773
766
|
```
|
|
774
767
|
|
|
775
|
-
Orchestrates layer
|
|
776
|
-
|
|
777
|
-
Parameters:
|
|
778
|
-
- `context` - - Factory helpers for constructing the layer instance.
|
|
779
|
-
- `size` - - Number of nodes in the normalization layer.
|
|
768
|
+
Orchestrates layer gating behavior with a high-level flow.
|
|
780
769
|
|
|
781
|
-
Returns: The configured layer instance.
|
|
782
770
|
Example:
|
|
783
771
|
|
|
784
772
|
```ts
|
|
785
|
-
|
|
773
|
+
gateLayer(layerConnectionContext, someConnections, method);
|
|
786
774
|
```
|
|
787
775
|
|
|
788
|
-
|
|
776
|
+
Parameters:
|
|
777
|
+
- `context` - - The layer state needed for gating.
|
|
778
|
+
- `connections` - - The connections to gate.
|
|
779
|
+
- `method` - - The gating method.
|
|
780
|
+
|
|
781
|
+
### inputLayer
|
|
789
782
|
|
|
790
783
|
```ts
|
|
791
|
-
|
|
792
|
-
context:
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
): TLayer
|
|
784
|
+
inputLayer(
|
|
785
|
+
context: LayerConnectionContext,
|
|
786
|
+
from: default | LayerLike,
|
|
787
|
+
method: unknown,
|
|
788
|
+
weight: number | undefined,
|
|
789
|
+
): default[]
|
|
798
790
|
```
|
|
799
791
|
|
|
800
|
-
Orchestrates
|
|
801
|
-
|
|
802
|
-
Parameters:
|
|
803
|
-
- `context` - - Factory helpers for constructing the layer instance.
|
|
804
|
-
- `size` - - Number of output nodes.
|
|
805
|
-
- `kernelSize` - - Size of the convolution kernel.
|
|
806
|
-
- `stride` - - Stride of the convolution.
|
|
807
|
-
- `padding` - - Padding size for the convolution.
|
|
792
|
+
Orchestrates layer input wiring with a high-level flow.
|
|
808
793
|
|
|
809
|
-
Returns: The configured layer instance.
|
|
810
794
|
Example:
|
|
811
795
|
|
|
812
796
|
```ts
|
|
813
|
-
|
|
797
|
+
inputLayer(layerConnectionContext, previousLayerLike);
|
|
814
798
|
```
|
|
815
799
|
|
|
816
|
-
|
|
800
|
+
Parameters:
|
|
801
|
+
- `context` - - The layer state needed for input wiring.
|
|
802
|
+
- `from` - - The source layer or group.
|
|
803
|
+
- `method` - - Optional connection method override.
|
|
804
|
+
- `weight` - - Optional fixed weight to apply.
|
|
805
|
+
|
|
806
|
+
Returns: The created connection list.
|
|
807
|
+
|
|
808
|
+
### propagateLayer
|
|
817
809
|
|
|
818
810
|
```ts
|
|
819
|
-
|
|
820
|
-
context:
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
811
|
+
propagateLayer(
|
|
812
|
+
context: LayerPropagationContext,
|
|
813
|
+
rate: number,
|
|
814
|
+
momentum: number,
|
|
815
|
+
targets: number[] | undefined,
|
|
816
|
+
): void
|
|
824
817
|
```
|
|
825
818
|
|
|
826
|
-
Orchestrates
|
|
819
|
+
Orchestrates layer backpropagation behavior with a high-level flow.
|
|
827
820
|
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
- `size` - - Number of output nodes.
|
|
831
|
-
- `heads` - - Number of attention heads.
|
|
821
|
+
If `targets` is provided, it must be one value per node (output layer).
|
|
822
|
+
If omitted, propagation behaves like a hidden layer.
|
|
832
823
|
|
|
833
|
-
|
|
834
|
-
Example:
|
|
824
|
+
Examples:
|
|
835
825
|
|
|
836
826
|
```ts
|
|
837
|
-
|
|
827
|
+
// Hidden layer propagation.
|
|
828
|
+
propagateLayer({ nodes: layer.nodes }, 0.3, 0.1);
|
|
829
|
+
|
|
830
|
+
// Output layer propagation.
|
|
831
|
+
propagateLayer({ nodes: layer.nodes }, 0.3, 0.1, [1, 0, 0]);
|
|
838
832
|
```
|
|
839
833
|
|
|
834
|
+
Parameters:
|
|
835
|
+
- `context` - - The layer state needed for propagation.
|
|
836
|
+
- `rate` - - The learning rate for weight updates.
|
|
837
|
+
- `momentum` - - The momentum factor for smoothing updates.
|
|
838
|
+
- `targets` - - Optional target values for output layers.
|
|
839
|
+
|
|
840
840
|
## architecture/layer/layer.guard.utils.ts
|
|
841
841
|
|
|
842
842
|
### isGroup
|
|
@@ -867,6 +867,61 @@ value.set({ bias: 0 });
|
|
|
867
867
|
|
|
868
868
|
## architecture/layer/layer.activation.utils.ts
|
|
869
869
|
|
|
870
|
+
### acquireActivationOutput
|
|
871
|
+
|
|
872
|
+
```ts
|
|
873
|
+
acquireActivationOutput(
|
|
874
|
+
nodeCount: number,
|
|
875
|
+
): number[]
|
|
876
|
+
```
|
|
877
|
+
|
|
878
|
+
Acquires a pooled output buffer sized for the current activation call.
|
|
879
|
+
|
|
880
|
+
Pooling avoids frequent temporary allocations in hot activation paths.
|
|
881
|
+
|
|
882
|
+
The returned array is owned by the pool. Treat it as **temporary**:
|
|
883
|
+
- Fill it.
|
|
884
|
+
- Clone it (if you need a stable output).
|
|
885
|
+
- Release it back to the pool.
|
|
886
|
+
|
|
887
|
+
Example (typical pattern):
|
|
888
|
+
|
|
889
|
+
```ts
|
|
890
|
+
const pooled = acquireActivationOutput(nodes.length);
|
|
891
|
+
fillActivationOutput(nodes, values, pooled);
|
|
892
|
+
const output = cloneActivationOutput(pooled);
|
|
893
|
+
releaseActivationOutput(pooled);
|
|
894
|
+
```
|
|
895
|
+
|
|
896
|
+
Parameters:
|
|
897
|
+
- `nodeCount` - - Number of nodes in the layer.
|
|
898
|
+
|
|
899
|
+
Returns: A pooled output array.
|
|
900
|
+
|
|
901
|
+
### applyLayerMask
|
|
902
|
+
|
|
903
|
+
```ts
|
|
904
|
+
applyLayerMask(
|
|
905
|
+
nodeList: default[],
|
|
906
|
+
mask: number,
|
|
907
|
+
): void
|
|
908
|
+
```
|
|
909
|
+
|
|
910
|
+
Applies one mask value to every node in the layer.
|
|
911
|
+
|
|
912
|
+
In this library, a node-level `mask` is used as a lightweight dropout control.
|
|
913
|
+
A mask of `0` effectively disables the node for the current activation step.
|
|
914
|
+
|
|
915
|
+
Example:
|
|
916
|
+
|
|
917
|
+
```ts
|
|
918
|
+
applyLayerMask(layer.nodes, 1);
|
|
919
|
+
```
|
|
920
|
+
|
|
921
|
+
Parameters:
|
|
922
|
+
- `nodeList` - - The layer nodes to update.
|
|
923
|
+
- `mask` - - The mask value to apply.
|
|
924
|
+
|
|
870
925
|
### assertActivationInputSize
|
|
871
926
|
|
|
872
927
|
```ts
|
|
@@ -903,94 +958,59 @@ Parameters:
|
|
|
903
958
|
- `nodeCount` - - Number of nodes in the layer.
|
|
904
959
|
- `inputValues` - - Optional activation values provided by the caller.
|
|
905
960
|
|
|
906
|
-
###
|
|
961
|
+
### cloneActivationOutput
|
|
907
962
|
|
|
908
963
|
```ts
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
): number
|
|
964
|
+
cloneActivationOutput(
|
|
965
|
+
output: number[],
|
|
966
|
+
): number[]
|
|
913
967
|
```
|
|
914
968
|
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
In this layer-level dropout model, all nodes receive the same mask per call,
|
|
918
|
-
which keeps activation behavior synchronized for grouped layer semantics.
|
|
969
|
+
Clones pooled output into a stable caller-owned array.
|
|
919
970
|
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
- A return value of `1` means "keep" and `0` means "drop".
|
|
923
|
-
- This helper intentionally does **not** rescale activations (some dropout
|
|
924
|
-
implementations divide by $(1 - p)$ during training). In this codebase the
|
|
925
|
-
mask is a simple on/off switch.
|
|
971
|
+
This is the "escape hatch" that turns a pooled scratch buffer into a normal
|
|
972
|
+
array you can safely return from APIs.
|
|
926
973
|
|
|
927
974
|
Example:
|
|
928
975
|
|
|
929
976
|
```ts
|
|
930
|
-
|
|
931
|
-
resolveLayerMask(0.5, true); // => 0 or 1
|
|
977
|
+
const stable = cloneActivationOutput(pooled);
|
|
932
978
|
```
|
|
933
979
|
|
|
934
980
|
Parameters:
|
|
935
|
-
- `
|
|
936
|
-
- `isTraining` - - Whether the layer is running in training mode.
|
|
981
|
+
- `output` - - The pooled output array to clone.
|
|
937
982
|
|
|
938
|
-
Returns: A
|
|
983
|
+
Returns: A cloned output array.
|
|
939
984
|
|
|
940
|
-
###
|
|
985
|
+
### fillActivationOutput
|
|
941
986
|
|
|
942
987
|
```ts
|
|
943
|
-
|
|
988
|
+
fillActivationOutput(
|
|
944
989
|
nodeList: default[],
|
|
945
|
-
|
|
990
|
+
inputValues: number[] | undefined,
|
|
991
|
+
output: number[],
|
|
946
992
|
): void
|
|
947
993
|
```
|
|
948
994
|
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
In this library, a node-level `mask` is used as a lightweight dropout control.
|
|
952
|
-
A mask of `0` effectively disables the node for the current activation step.
|
|
953
|
-
|
|
954
|
-
Example:
|
|
955
|
-
|
|
956
|
-
```ts
|
|
957
|
-
applyLayerMask(layer.nodes, 1);
|
|
958
|
-
```
|
|
959
|
-
|
|
960
|
-
Parameters:
|
|
961
|
-
- `nodeList` - - The layer nodes to update.
|
|
962
|
-
- `mask` - - The mask value to apply.
|
|
963
|
-
|
|
964
|
-
### acquireActivationOutput
|
|
965
|
-
|
|
966
|
-
```ts
|
|
967
|
-
acquireActivationOutput(
|
|
968
|
-
nodeCount: number,
|
|
969
|
-
): number[]
|
|
970
|
-
```
|
|
971
|
-
|
|
972
|
-
Acquires a pooled output buffer sized for the current activation call.
|
|
995
|
+
Activates each node and writes outputs into the provided buffer.
|
|
973
996
|
|
|
974
|
-
|
|
997
|
+
When `inputValues` is provided, each node receives the corresponding input
|
|
998
|
+
value. Otherwise each node self-activates from incoming state.
|
|
975
999
|
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
- Release it back to the pool.
|
|
1000
|
+
This function is deliberately low-level: it does not allocate and it does not
|
|
1001
|
+
return anything. That makes it ideal for hot paths where you want to reuse a
|
|
1002
|
+
buffer (typically a pooled one).
|
|
980
1003
|
|
|
981
|
-
Example
|
|
1004
|
+
Example:
|
|
982
1005
|
|
|
983
1006
|
```ts
|
|
984
|
-
|
|
985
|
-
fillActivationOutput(nodes, values, pooled);
|
|
986
|
-
const output = cloneActivationOutput(pooled);
|
|
987
|
-
releaseActivationOutput(pooled);
|
|
1007
|
+
fillActivationOutput(layer.nodes, [0.2, 0.4], pooled);
|
|
988
1008
|
```
|
|
989
1009
|
|
|
990
1010
|
Parameters:
|
|
991
|
-
- `
|
|
992
|
-
|
|
993
|
-
|
|
1011
|
+
- `nodeList` - - Nodes to activate.
|
|
1012
|
+
- `inputValues` - - Optional activation values for each node.
|
|
1013
|
+
- `output` - - Output buffer to populate.
|
|
994
1014
|
|
|
995
1015
|
### releaseActivationOutput
|
|
996
1016
|
|
|
@@ -1009,61 +1029,63 @@ Important: do not keep using `output` after releasing it.
|
|
|
1009
1029
|
Parameters:
|
|
1010
1030
|
- `output` - - The pooled output array to release.
|
|
1011
1031
|
|
|
1012
|
-
###
|
|
1032
|
+
### resolveLayerMask
|
|
1013
1033
|
|
|
1014
1034
|
```ts
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1035
|
+
resolveLayerMask(
|
|
1036
|
+
layerDropout: number,
|
|
1037
|
+
isTraining: boolean,
|
|
1038
|
+
): number
|
|
1018
1039
|
```
|
|
1019
1040
|
|
|
1020
|
-
|
|
1041
|
+
Resolves a shared dropout mask for the full layer.
|
|
1021
1042
|
|
|
1022
|
-
|
|
1023
|
-
|
|
1043
|
+
In this layer-level dropout model, all nodes receive the same mask per call,
|
|
1044
|
+
which keeps activation behavior synchronized for grouped layer semantics.
|
|
1045
|
+
|
|
1046
|
+
Notes:
|
|
1047
|
+
- Dropout is only applied when `isTraining` is true.
|
|
1048
|
+
- A return value of `1` means "keep" and `0` means "drop".
|
|
1049
|
+
- This helper intentionally does **not** rescale activations (some dropout
|
|
1050
|
+
implementations divide by $(1 - p)$ during training). In this codebase the
|
|
1051
|
+
mask is a simple on/off switch.
|
|
1024
1052
|
|
|
1025
1053
|
Example:
|
|
1026
1054
|
|
|
1027
1055
|
```ts
|
|
1028
|
-
|
|
1056
|
+
resolveLayerMask(0.5, false); // => 1 (dropout disabled)
|
|
1057
|
+
resolveLayerMask(0.5, true); // => 0 or 1
|
|
1029
1058
|
```
|
|
1030
1059
|
|
|
1031
1060
|
Parameters:
|
|
1032
|
-
- `
|
|
1061
|
+
- `layerDropout` - - The dropout rate configured for the layer.
|
|
1062
|
+
- `isTraining` - - Whether the layer is running in training mode.
|
|
1033
1063
|
|
|
1034
|
-
Returns: A
|
|
1064
|
+
Returns: A mask value of 1 or 0 for all nodes in the layer.
|
|
1035
1065
|
|
|
1036
|
-
|
|
1066
|
+
## architecture/layer/layer.connection.utils.ts
|
|
1067
|
+
|
|
1068
|
+
### clearLayer
|
|
1037
1069
|
|
|
1038
1070
|
```ts
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
inputValues: number[] | undefined,
|
|
1042
|
-
output: number[],
|
|
1071
|
+
clearLayer(
|
|
1072
|
+
context: LayerConnectionContext,
|
|
1043
1073
|
): void
|
|
1044
1074
|
```
|
|
1045
1075
|
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
When `inputValues` is provided, each node receives the corresponding input
|
|
1049
|
-
value. Otherwise each node self-activates from incoming state.
|
|
1076
|
+
Clears activation state for all nodes in a layer.
|
|
1050
1077
|
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
buffer (typically a pooled one).
|
|
1078
|
+
Use this when you want to reset per-node transient state between runs
|
|
1079
|
+
(especially helpful in recurrent networks that keep state across timesteps).
|
|
1054
1080
|
|
|
1055
1081
|
Example:
|
|
1056
1082
|
|
|
1057
1083
|
```ts
|
|
1058
|
-
|
|
1084
|
+
clearLayer(layerContext);
|
|
1059
1085
|
```
|
|
1060
1086
|
|
|
1061
1087
|
Parameters:
|
|
1062
|
-
- `
|
|
1063
|
-
- `inputValues` - - Optional activation values for each node.
|
|
1064
|
-
- `output` - - Output buffer to populate.
|
|
1065
|
-
|
|
1066
|
-
## architecture/layer/layer.connection.utils.ts
|
|
1088
|
+
- `context` - - The layer state needed to reset nodes.
|
|
1067
1089
|
|
|
1068
1090
|
### connectLayer
|
|
1069
1091
|
|
|
@@ -1104,6 +1126,74 @@ Parameters:
|
|
|
1104
1126
|
|
|
1105
1127
|
Returns: The created connection list.
|
|
1106
1128
|
|
|
1129
|
+
### disconnectFromGroup
|
|
1130
|
+
|
|
1131
|
+
```ts
|
|
1132
|
+
disconnectFromGroup(
|
|
1133
|
+
layerNodes: default[],
|
|
1134
|
+
targetGroup: default,
|
|
1135
|
+
layerConnections: { in: default[]; out: default[]; self: default[]; },
|
|
1136
|
+
removeTwoSided: boolean,
|
|
1137
|
+
): void
|
|
1138
|
+
```
|
|
1139
|
+
|
|
1140
|
+
Disconnects all layer nodes from a target group.
|
|
1141
|
+
|
|
1142
|
+
This is a "cartesian disconnect": every node in this layer is disconnected
|
|
1143
|
+
from every node in the target group.
|
|
1144
|
+
|
|
1145
|
+
Parameters:
|
|
1146
|
+
- `layerNodes` - - Nodes in the layer.
|
|
1147
|
+
- `targetGroup` - - Group to disconnect from.
|
|
1148
|
+
- `layerConnections` - - Connection tracking for the layer.
|
|
1149
|
+
- `removeTwoSided` - - Whether to remove reciprocal connections as well.
|
|
1150
|
+
|
|
1151
|
+
### disconnectFromNode
|
|
1152
|
+
|
|
1153
|
+
```ts
|
|
1154
|
+
disconnectFromNode(
|
|
1155
|
+
layerNodes: default[],
|
|
1156
|
+
targetNode: default,
|
|
1157
|
+
layerConnections: { in: default[]; out: default[]; self: default[]; },
|
|
1158
|
+
removeTwoSided: boolean,
|
|
1159
|
+
): void
|
|
1160
|
+
```
|
|
1161
|
+
|
|
1162
|
+
Disconnects all layer nodes from a target node.
|
|
1163
|
+
|
|
1164
|
+
Parameters:
|
|
1165
|
+
- `layerNodes` - - Nodes in the layer.
|
|
1166
|
+
- `targetNode` - - Node to disconnect from.
|
|
1167
|
+
- `layerConnections` - - Connection tracking for the layer.
|
|
1168
|
+
- `removeTwoSided` - - Whether to remove reciprocal connections as well.
|
|
1169
|
+
|
|
1170
|
+
### disconnectLayer
|
|
1171
|
+
|
|
1172
|
+
```ts
|
|
1173
|
+
disconnectLayer(
|
|
1174
|
+
context: LayerConnectionContext,
|
|
1175
|
+
target: default | default,
|
|
1176
|
+
twoSided: boolean,
|
|
1177
|
+
): void
|
|
1178
|
+
```
|
|
1179
|
+
|
|
1180
|
+
Disconnects nodes in this layer from a target group or node.
|
|
1181
|
+
|
|
1182
|
+
This iterates through this layer's nodes and calls `node.disconnect(...)`.
|
|
1183
|
+
It also updates the layer's tracked `connections.in/out` arrays so they
|
|
1184
|
+
remain consistent with the underlying node graph.
|
|
1185
|
+
|
|
1186
|
+
Example:
|
|
1187
|
+
|
|
1188
|
+
```ts
|
|
1189
|
+
disconnectLayer(layerContext, someNode, false);
|
|
1190
|
+
```
|
|
1191
|
+
|
|
1192
|
+
Parameters:
|
|
1193
|
+
- `context` - - The layer state needed for disconnecting.
|
|
1194
|
+
- `target` - - The group or node to disconnect.
|
|
1195
|
+
- `twoSided` - - Whether to remove reciprocal connections as well.
|
|
1196
|
+
|
|
1107
1197
|
### gateLayer
|
|
1108
1198
|
|
|
1109
1199
|
```ts
|
|
@@ -1171,85 +1261,17 @@ Parameters:
|
|
|
1171
1261
|
|
|
1172
1262
|
Returns: The created connection list.
|
|
1173
1263
|
|
|
1174
|
-
###
|
|
1175
|
-
|
|
1176
|
-
```ts
|
|
1177
|
-
disconnectLayer(
|
|
1178
|
-
context: LayerConnectionContext,
|
|
1179
|
-
target: default | default,
|
|
1180
|
-
twoSided: boolean,
|
|
1181
|
-
): void
|
|
1182
|
-
```
|
|
1183
|
-
|
|
1184
|
-
Disconnects nodes in this layer from a target group or node.
|
|
1185
|
-
|
|
1186
|
-
This iterates through this layer's nodes and calls `node.disconnect(...)`.
|
|
1187
|
-
It also updates the layer's tracked `connections.in/out` arrays so they
|
|
1188
|
-
remain consistent with the underlying node graph.
|
|
1189
|
-
|
|
1190
|
-
Example:
|
|
1191
|
-
|
|
1192
|
-
```ts
|
|
1193
|
-
disconnectLayer(layerContext, someNode, false);
|
|
1194
|
-
```
|
|
1195
|
-
|
|
1196
|
-
Parameters:
|
|
1197
|
-
- `context` - - The layer state needed for disconnecting.
|
|
1198
|
-
- `target` - - The group or node to disconnect.
|
|
1199
|
-
- `twoSided` - - Whether to remove reciprocal connections as well.
|
|
1200
|
-
|
|
1201
|
-
### disconnectFromGroup
|
|
1202
|
-
|
|
1203
|
-
```ts
|
|
1204
|
-
disconnectFromGroup(
|
|
1205
|
-
layerNodes: default[],
|
|
1206
|
-
targetGroup: default,
|
|
1207
|
-
layerConnections: { in: default[]; out: default[]; self: default[]; },
|
|
1208
|
-
removeTwoSided: boolean,
|
|
1209
|
-
): void
|
|
1210
|
-
```
|
|
1211
|
-
|
|
1212
|
-
Disconnects all layer nodes from a target group.
|
|
1213
|
-
|
|
1214
|
-
This is a "cartesian disconnect": every node in this layer is disconnected
|
|
1215
|
-
from every node in the target group.
|
|
1216
|
-
|
|
1217
|
-
Parameters:
|
|
1218
|
-
- `layerNodes` - - Nodes in the layer.
|
|
1219
|
-
- `targetGroup` - - Group to disconnect from.
|
|
1220
|
-
- `layerConnections` - - Connection tracking for the layer.
|
|
1221
|
-
- `removeTwoSided` - - Whether to remove reciprocal connections as well.
|
|
1222
|
-
|
|
1223
|
-
### disconnectFromNode
|
|
1224
|
-
|
|
1225
|
-
```ts
|
|
1226
|
-
disconnectFromNode(
|
|
1227
|
-
layerNodes: default[],
|
|
1228
|
-
targetNode: default,
|
|
1229
|
-
layerConnections: { in: default[]; out: default[]; self: default[]; },
|
|
1230
|
-
removeTwoSided: boolean,
|
|
1231
|
-
): void
|
|
1232
|
-
```
|
|
1233
|
-
|
|
1234
|
-
Disconnects all layer nodes from a target node.
|
|
1235
|
-
|
|
1236
|
-
Parameters:
|
|
1237
|
-
- `layerNodes` - - Nodes in the layer.
|
|
1238
|
-
- `targetNode` - - Node to disconnect from.
|
|
1239
|
-
- `layerConnections` - - Connection tracking for the layer.
|
|
1240
|
-
- `removeTwoSided` - - Whether to remove reciprocal connections as well.
|
|
1241
|
-
|
|
1242
|
-
### removeOutgoingConnection
|
|
1264
|
+
### removeIncomingConnection
|
|
1243
1265
|
|
|
1244
1266
|
```ts
|
|
1245
|
-
|
|
1267
|
+
removeIncomingConnection(
|
|
1246
1268
|
layerConnections: { in: default[]; out: default[]; self: default[]; },
|
|
1247
1269
|
sourceNode: default,
|
|
1248
1270
|
targetNode: default,
|
|
1249
1271
|
): void
|
|
1250
1272
|
```
|
|
1251
1273
|
|
|
1252
|
-
Removes an
|
|
1274
|
+
Removes an incoming connection from layer tracking.
|
|
1253
1275
|
|
|
1254
1276
|
This scans in reverse so we can `splice(...)` safely while iterating.
|
|
1255
1277
|
|
|
@@ -1258,17 +1280,17 @@ Parameters:
|
|
|
1258
1280
|
- `sourceNode` - - Source node for the connection.
|
|
1259
1281
|
- `targetNode` - - Target node for the connection.
|
|
1260
1282
|
|
|
1261
|
-
###
|
|
1283
|
+
### removeOutgoingConnection
|
|
1262
1284
|
|
|
1263
1285
|
```ts
|
|
1264
|
-
|
|
1286
|
+
removeOutgoingConnection(
|
|
1265
1287
|
layerConnections: { in: default[]; out: default[]; self: default[]; },
|
|
1266
1288
|
sourceNode: default,
|
|
1267
1289
|
targetNode: default,
|
|
1268
1290
|
): void
|
|
1269
1291
|
```
|
|
1270
1292
|
|
|
1271
|
-
Removes an
|
|
1293
|
+
Removes an outgoing connection from layer tracking.
|
|
1272
1294
|
|
|
1273
1295
|
This scans in reverse so we can `splice(...)` safely while iterating.
|
|
1274
1296
|
|
|
@@ -1277,28 +1299,6 @@ Parameters:
|
|
|
1277
1299
|
- `sourceNode` - - Source node for the connection.
|
|
1278
1300
|
- `targetNode` - - Target node for the connection.
|
|
1279
1301
|
|
|
1280
|
-
### clearLayer
|
|
1281
|
-
|
|
1282
|
-
```ts
|
|
1283
|
-
clearLayer(
|
|
1284
|
-
context: LayerConnectionContext,
|
|
1285
|
-
): void
|
|
1286
|
-
```
|
|
1287
|
-
|
|
1288
|
-
Clears activation state for all nodes in a layer.
|
|
1289
|
-
|
|
1290
|
-
Use this when you want to reset per-node transient state between runs
|
|
1291
|
-
(especially helpful in recurrent networks that keep state across timesteps).
|
|
1292
|
-
|
|
1293
|
-
Example:
|
|
1294
|
-
|
|
1295
|
-
```ts
|
|
1296
|
-
clearLayer(layerContext);
|
|
1297
|
-
```
|
|
1298
|
-
|
|
1299
|
-
Parameters:
|
|
1300
|
-
- `context` - - The layer state needed to reset nodes.
|
|
1301
|
-
|
|
1302
1302
|
## architecture/layer/layer.propagation.utils.ts
|
|
1303
1303
|
|
|
1304
1304
|
### assertTargetInputSize
|
|
@@ -1404,68 +1404,68 @@ dense.input(previousLayerLike);
|
|
|
1404
1404
|
|
|
1405
1405
|
## architecture/layer/layer.factory.recurrent.utils.ts
|
|
1406
1406
|
|
|
1407
|
-
###
|
|
1407
|
+
### buildGruLayer
|
|
1408
1408
|
|
|
1409
1409
|
```ts
|
|
1410
|
-
|
|
1410
|
+
buildGruLayer(
|
|
1411
1411
|
context: LayerFactoryContext<TLayer>,
|
|
1412
1412
|
size: number,
|
|
1413
1413
|
): TLayer
|
|
1414
1414
|
```
|
|
1415
1415
|
|
|
1416
|
-
Builds
|
|
1416
|
+
Builds a GRU layer using the provided factory context.
|
|
1417
1417
|
|
|
1418
1418
|
Educational overview:
|
|
1419
|
-
-
|
|
1420
|
-
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
This builder wires the classic LSTM topology using `Group` blocks and gating.
|
|
1424
|
-
It returns a layer object that is compatible with the rest of the layer
|
|
1425
|
-
utilities (`layer.input(...)`, `layer.activate(...)`, `layer.output`, etc.).
|
|
1419
|
+
- GRU is a gated recurrent unit with fewer gates than LSTM.
|
|
1420
|
+
- This implementation wires update/reset gates and a memory cell, then
|
|
1421
|
+
exposes a standard `layer.output` group.
|
|
1426
1422
|
|
|
1427
1423
|
Parameters:
|
|
1428
1424
|
- `context` - - Factory helpers for constructing the layer instance.
|
|
1429
|
-
- `size` - - Number of units in each
|
|
1425
|
+
- `size` - - Number of units in each GRU gate and cell.
|
|
1430
1426
|
|
|
1431
1427
|
Returns: The configured layer instance.
|
|
1432
1428
|
|
|
1433
1429
|
Example:
|
|
1434
1430
|
|
|
1435
1431
|
```ts
|
|
1436
|
-
const
|
|
1437
|
-
|
|
1438
|
-
// Wire a previous layer (or Group) into the LSTM.
|
|
1439
|
-
lstm.input(previousLayerLike);
|
|
1432
|
+
const gru = buildGruLayer(factoryContext, 8);
|
|
1433
|
+
gru.input(previousLayerLike);
|
|
1440
1434
|
```
|
|
1441
1435
|
|
|
1442
|
-
###
|
|
1436
|
+
### buildLstmLayer
|
|
1443
1437
|
|
|
1444
1438
|
```ts
|
|
1445
|
-
|
|
1439
|
+
buildLstmLayer(
|
|
1446
1440
|
context: LayerFactoryContext<TLayer>,
|
|
1447
1441
|
size: number,
|
|
1448
1442
|
): TLayer
|
|
1449
1443
|
```
|
|
1450
1444
|
|
|
1451
|
-
Builds
|
|
1445
|
+
Builds an LSTM layer using the provided factory context.
|
|
1452
1446
|
|
|
1453
1447
|
Educational overview:
|
|
1454
|
-
-
|
|
1455
|
-
-
|
|
1456
|
-
exposes
|
|
1448
|
+
- **Gates** control information flow (input / forget / output).
|
|
1449
|
+
- The **memory cell** stores recurrent state via a self-connection.
|
|
1450
|
+
- The **output block** is what this layer exposes as `layer.output`.
|
|
1451
|
+
|
|
1452
|
+
This builder wires the classic LSTM topology using `Group` blocks and gating.
|
|
1453
|
+
It returns a layer object that is compatible with the rest of the layer
|
|
1454
|
+
utilities (`layer.input(...)`, `layer.activate(...)`, `layer.output`, etc.).
|
|
1457
1455
|
|
|
1458
1456
|
Parameters:
|
|
1459
1457
|
- `context` - - Factory helpers for constructing the layer instance.
|
|
1460
|
-
- `size` - - Number of units in each
|
|
1458
|
+
- `size` - - Number of units in each LSTM gate and cell.
|
|
1461
1459
|
|
|
1462
1460
|
Returns: The configured layer instance.
|
|
1463
1461
|
|
|
1464
1462
|
Example:
|
|
1465
1463
|
|
|
1466
1464
|
```ts
|
|
1467
|
-
const
|
|
1468
|
-
|
|
1465
|
+
const lstm = buildLstmLayer(factoryContext, 8);
|
|
1466
|
+
|
|
1467
|
+
// Wire a previous layer (or Group) into the LSTM.
|
|
1468
|
+
lstm.input(previousLayerLike);
|
|
1469
1469
|
```
|
|
1470
1470
|
|
|
1471
1471
|
### buildMemoryLayer
|
|
@@ -1502,30 +1502,28 @@ const memoryLayer = buildMemoryLayer(factoryContext, 4, 3);
|
|
|
1502
1502
|
memoryLayer.input(previousLayerLike);
|
|
1503
1503
|
```
|
|
1504
1504
|
|
|
1505
|
-
###
|
|
1505
|
+
### flattenConnections
|
|
1506
1506
|
|
|
1507
1507
|
```ts
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
): default
|
|
1508
|
+
flattenConnections(
|
|
1509
|
+
connectionLists: default[][],
|
|
1510
|
+
): default[]
|
|
1512
1511
|
```
|
|
1513
1512
|
|
|
1514
|
-
|
|
1513
|
+
Flattens grouped connection arrays into a single list.
|
|
1515
1514
|
|
|
1516
|
-
|
|
1517
|
-
|
|
1515
|
+
This keeps builder code declarative: build connections per gate/block,
|
|
1516
|
+
then flatten once at the end.
|
|
1518
1517
|
|
|
1519
1518
|
Parameters:
|
|
1520
|
-
- `
|
|
1521
|
-
- `from` - - Source input candidate.
|
|
1519
|
+
- `connectionLists` - - Connection groups to flatten.
|
|
1522
1520
|
|
|
1523
|
-
Returns:
|
|
1521
|
+
Returns: Flattened connection list.
|
|
1524
1522
|
|
|
1525
1523
|
Example:
|
|
1526
1524
|
|
|
1527
1525
|
```ts
|
|
1528
|
-
const
|
|
1526
|
+
const connections = flattenConnections([gateConnections, cellConnections]);
|
|
1529
1527
|
```
|
|
1530
1528
|
|
|
1531
1529
|
### resolveConnectionMethod
|
|
@@ -1552,70 +1550,56 @@ Example:
|
|
|
1552
1550
|
const method = resolveConnectionMethod(undefined);
|
|
1553
1551
|
```
|
|
1554
1552
|
|
|
1555
|
-
###
|
|
1553
|
+
### resolveSourceGroup
|
|
1556
1554
|
|
|
1557
1555
|
```ts
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1556
|
+
resolveSourceGroup(
|
|
1557
|
+
factoryContext: LayerFactoryContext<TLayer>,
|
|
1558
|
+
from: default | LayerLike,
|
|
1559
|
+
): default
|
|
1561
1560
|
```
|
|
1562
1561
|
|
|
1563
|
-
|
|
1562
|
+
Resolves a source group from a layer-like or group input.
|
|
1564
1563
|
|
|
1565
|
-
|
|
1566
|
-
|
|
1564
|
+
Many wiring helpers accept either a `Group` or a "layer-like" object.
|
|
1565
|
+
When a layer is provided, we treat `layer.output` as the actual source group.
|
|
1567
1566
|
|
|
1568
1567
|
Parameters:
|
|
1569
|
-
- `
|
|
1568
|
+
- `factoryContext` - - Factory context providing layer guards.
|
|
1569
|
+
- `from` - - Source input candidate.
|
|
1570
1570
|
|
|
1571
|
-
Returns:
|
|
1571
|
+
Returns: Source group used for connections.
|
|
1572
1572
|
|
|
1573
1573
|
Example:
|
|
1574
1574
|
|
|
1575
1575
|
```ts
|
|
1576
|
-
const
|
|
1576
|
+
const sourceGroup = resolveSourceGroup(factoryContext, previousLayerLike);
|
|
1577
1577
|
```
|
|
1578
1578
|
|
|
1579
1579
|
## architecture/layer/layer.factory.experimental.utils.ts
|
|
1580
1580
|
|
|
1581
|
-
###
|
|
1581
|
+
### activateStubNodes
|
|
1582
1582
|
|
|
1583
1583
|
```ts
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
kernelSize: number,
|
|
1588
|
-
stride: number,
|
|
1589
|
-
padding: number,
|
|
1590
|
-
): TLayer
|
|
1584
|
+
activateStubNodes(
|
|
1585
|
+
layer: TLayer,
|
|
1586
|
+
): number[]
|
|
1591
1587
|
```
|
|
1592
1588
|
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
This is an experimental placeholder: it stores Conv1D metadata and returns
|
|
1596
|
-
either activated node outputs (no input values) or a bounded slice from
|
|
1597
|
-
provided values. It does not perform real convolution math.
|
|
1589
|
+
Activates all nodes in a stub layer and returns their outputs.
|
|
1598
1590
|
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
implementation yet.
|
|
1591
|
+
This helper keeps fallback activation behavior identical across experimental
|
|
1592
|
+
layer variants.
|
|
1602
1593
|
|
|
1603
1594
|
Parameters:
|
|
1604
|
-
- `
|
|
1605
|
-
- `size` - - Number of output nodes (filters).
|
|
1606
|
-
- `kernelSize` - - Size of the convolution kernel.
|
|
1607
|
-
- `stride` - - Stride of the convolution.
|
|
1608
|
-
- `padding` - - Padding size for the convolution.
|
|
1595
|
+
- `layer` - - Layer containing nodes to activate.
|
|
1609
1596
|
|
|
1610
|
-
Returns:
|
|
1597
|
+
Returns: Activated node outputs.
|
|
1611
1598
|
|
|
1612
1599
|
Example:
|
|
1613
1600
|
|
|
1614
1601
|
```ts
|
|
1615
|
-
const
|
|
1616
|
-
|
|
1617
|
-
// When called with values, the stub returns a slice (not a true convolution).
|
|
1618
|
-
const out = conv.activate([10, 11, 12, 13]);
|
|
1602
|
+
const outputs = activateStubNodes(layer);
|
|
1619
1603
|
```
|
|
1620
1604
|
|
|
1621
1605
|
### buildAttentionLayer
|
|
@@ -1653,116 +1637,160 @@ const out = attention.activate([1, 2, 3, 4]);
|
|
|
1653
1637
|
// out is length 8, every entry is the average (2.5)
|
|
1654
1638
|
```
|
|
1655
1639
|
|
|
1656
|
-
###
|
|
1640
|
+
### buildConv1dLayer
|
|
1657
1641
|
|
|
1658
1642
|
```ts
|
|
1659
|
-
|
|
1643
|
+
buildConv1dLayer(
|
|
1660
1644
|
context: LayerFactoryContext<TLayer>,
|
|
1661
1645
|
size: number,
|
|
1646
|
+
kernelSize: number,
|
|
1647
|
+
stride: number,
|
|
1648
|
+
padding: number,
|
|
1662
1649
|
): TLayer
|
|
1663
1650
|
```
|
|
1664
1651
|
|
|
1665
|
-
|
|
1652
|
+
Builds a lightweight Conv1D-style stub layer.
|
|
1666
1653
|
|
|
1667
|
-
|
|
1668
|
-
|
|
1654
|
+
This is an experimental placeholder: it stores Conv1D metadata and returns
|
|
1655
|
+
either activated node outputs (no input values) or a bounded slice from
|
|
1656
|
+
provided values. It does not perform real convolution math.
|
|
1669
1657
|
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
wired projection of `nodes`.
|
|
1658
|
+
Educational note: this is designed as an integration seam. It lets you
|
|
1659
|
+
prototype graphs that *mention* Conv1D without requiring a full convolution
|
|
1660
|
+
implementation yet.
|
|
1674
1661
|
|
|
1675
1662
|
Parameters:
|
|
1676
1663
|
- `context` - - Factory helpers for constructing the layer instance.
|
|
1677
|
-
- `size` - - Number of output nodes
|
|
1664
|
+
- `size` - - Number of output nodes (filters).
|
|
1665
|
+
- `kernelSize` - - Size of the convolution kernel.
|
|
1666
|
+
- `stride` - - Stride of the convolution.
|
|
1667
|
+
- `padding` - - Padding size for the convolution.
|
|
1678
1668
|
|
|
1679
|
-
Returns:
|
|
1669
|
+
Returns: The configured layer instance.
|
|
1680
1670
|
|
|
1681
|
-
|
|
1671
|
+
Example:
|
|
1682
1672
|
|
|
1683
1673
|
```ts
|
|
1684
|
-
|
|
1674
|
+
const conv = buildConv1dLayer(factoryContext, 8, 3, 1, 1);
|
|
1675
|
+
|
|
1676
|
+
// When called with values, the stub returns a slice (not a true convolution).
|
|
1677
|
+
const out = conv.activate([10, 11, 12, 13]);
|
|
1678
|
+
```
|
|
1679
|
+
|
|
1680
|
+
### createAttentionActivator
|
|
1681
|
+
|
|
1682
|
+
```ts
|
|
1683
|
+
createAttentionActivator(
|
|
1685
1684
|
layer: TLayer,
|
|
1686
1685
|
size: number,
|
|
1687
1686
|
): (values?: number[] | undefined) => number[]
|
|
1688
1687
|
```
|
|
1689
1688
|
|
|
1690
|
-
Builds the activation function used by the
|
|
1689
|
+
Builds the activation function used by the attention stub.
|
|
1691
1690
|
|
|
1692
|
-
When values are provided,
|
|
1691
|
+
When values are provided, all outputs are filled with their average.
|
|
1693
1692
|
When values are omitted, it delegates to node activation.
|
|
1694
1693
|
|
|
1695
|
-
This
|
|
1696
|
-
|
|
1694
|
+
This behavior is *not* meant to represent real attention math; it simply
|
|
1695
|
+
produces a stable, shape-correct output while attention internals evolve.
|
|
1697
1696
|
|
|
1698
1697
|
Parameters:
|
|
1699
1698
|
- `layer` - - Layer whose nodes can self-activate.
|
|
1700
1699
|
- `size` - - Number of output values to return.
|
|
1701
1700
|
|
|
1702
|
-
Returns: Activation callback for
|
|
1701
|
+
Returns: Activation callback for attention behavior.
|
|
1703
1702
|
|
|
1704
1703
|
Example:
|
|
1705
1704
|
|
|
1706
1705
|
```ts
|
|
1707
|
-
const activate =
|
|
1708
|
-
activate([
|
|
1706
|
+
const activate = createAttentionActivator(layer, 4);
|
|
1707
|
+
activate([1, 3]); // -> [2, 2, 2, 2]
|
|
1709
1708
|
```
|
|
1710
1709
|
|
|
1711
|
-
###
|
|
1710
|
+
### createConv1dActivator
|
|
1712
1711
|
|
|
1713
1712
|
```ts
|
|
1714
|
-
|
|
1713
|
+
createConv1dActivator(
|
|
1715
1714
|
layer: TLayer,
|
|
1716
1715
|
size: number,
|
|
1717
1716
|
): (values?: number[] | undefined) => number[]
|
|
1718
1717
|
```
|
|
1719
1718
|
|
|
1720
|
-
Builds the activation function used by the
|
|
1719
|
+
Builds the activation function used by the Conv1D stub.
|
|
1721
1720
|
|
|
1722
|
-
When values are provided,
|
|
1721
|
+
When values are provided, this function returns a length-bounded slice.
|
|
1723
1722
|
When values are omitted, it delegates to node activation.
|
|
1724
1723
|
|
|
1725
|
-
This
|
|
1726
|
-
|
|
1724
|
+
This keeps the call signature compatible with real layers while remaining
|
|
1725
|
+
intentionally cheap.
|
|
1727
1726
|
|
|
1728
1727
|
Parameters:
|
|
1729
1728
|
- `layer` - - Layer whose nodes can self-activate.
|
|
1730
1729
|
- `size` - - Number of output values to return.
|
|
1731
1730
|
|
|
1732
|
-
Returns: Activation callback for
|
|
1731
|
+
Returns: Activation callback for Conv1D behavior.
|
|
1733
1732
|
|
|
1734
1733
|
Example:
|
|
1735
1734
|
|
|
1736
1735
|
```ts
|
|
1737
|
-
const activate =
|
|
1738
|
-
activate([
|
|
1736
|
+
const activate = createConv1dActivator(layer, 3);
|
|
1737
|
+
activate([9, 8, 7, 6]); // -> [9, 8, 7]
|
|
1739
1738
|
```
|
|
1740
1739
|
|
|
1741
|
-
###
|
|
1740
|
+
### createStubLayer
|
|
1742
1741
|
|
|
1743
1742
|
```ts
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1743
|
+
createStubLayer(
|
|
1744
|
+
context: LayerFactoryContext<TLayer>,
|
|
1745
|
+
size: number,
|
|
1746
|
+
): TLayer
|
|
1747
1747
|
```
|
|
1748
1748
|
|
|
1749
|
-
|
|
1749
|
+
Creates shared node/output scaffolding for experimental layers.
|
|
1750
1750
|
|
|
1751
|
-
|
|
1752
|
-
|
|
1751
|
+
Centralizing this setup keeps the experimental builders focused on their
|
|
1752
|
+
metadata and activation behavior.
|
|
1753
|
+
|
|
1754
|
+
Implementation detail: the returned layer contains a `nodes` list (for basic
|
|
1755
|
+
activation) and an `output` group (for API compatibility with the rest of the
|
|
1756
|
+
architecture). In these stubs, the output group is not intended to be a fully
|
|
1757
|
+
wired projection of `nodes`.
|
|
1753
1758
|
|
|
1754
1759
|
Parameters:
|
|
1755
|
-
- `
|
|
1760
|
+
- `context` - - Factory helpers for constructing the layer instance.
|
|
1761
|
+
- `size` - - Number of output nodes to allocate.
|
|
1756
1762
|
|
|
1757
|
-
Returns:
|
|
1763
|
+
Returns: Initialized experimental layer.
|
|
1758
1764
|
|
|
1759
|
-
|
|
1765
|
+
## architecture/layer/layer.factory.normalization.utils.ts
|
|
1766
|
+
|
|
1767
|
+
### applyNormalizationActivation
|
|
1760
1768
|
|
|
1761
1769
|
```ts
|
|
1762
|
-
|
|
1770
|
+
applyNormalizationActivation(
|
|
1771
|
+
layer: TLayer,
|
|
1772
|
+
): void
|
|
1763
1773
|
```
|
|
1764
1774
|
|
|
1765
|
-
|
|
1775
|
+
Wraps a layer activation function with normalization post-processing.
|
|
1776
|
+
|
|
1777
|
+
The wrapper preserves existing activation semantics, then applies
|
|
1778
|
+
`normalizeActivations(...)` to produce zero-centered, variance-scaled output.
|
|
1779
|
+
|
|
1780
|
+
This is implemented as a function wrapper rather than modifying node math.
|
|
1781
|
+
That makes it easy to layer normalization behavior onto each dense layer.
|
|
1782
|
+
|
|
1783
|
+
Parameters:
|
|
1784
|
+
- `layer` - - Dense layer to decorate with normalization behavior.
|
|
1785
|
+
|
|
1786
|
+
Returns: No return value.
|
|
1787
|
+
|
|
1788
|
+
Example (conceptual flow):
|
|
1789
|
+
|
|
1790
|
+
```ts
|
|
1791
|
+
// 1) baseActivate(...) computes raw activations
|
|
1792
|
+
// 2) wrapper normalizes the vector before returning
|
|
1793
|
+
```
|
|
1766
1794
|
|
|
1767
1795
|
### buildBatchNormLayer
|
|
1768
1796
|
|
|
@@ -1827,34 +1855,6 @@ Example:
|
|
|
1827
1855
|
const normalized = buildLayerNormLayer(factoryContext, 16);
|
|
1828
1856
|
```
|
|
1829
1857
|
|
|
1830
|
-
### applyNormalizationActivation
|
|
1831
|
-
|
|
1832
|
-
```ts
|
|
1833
|
-
applyNormalizationActivation(
|
|
1834
|
-
layer: TLayer,
|
|
1835
|
-
): void
|
|
1836
|
-
```
|
|
1837
|
-
|
|
1838
|
-
Wraps a layer activation function with normalization post-processing.
|
|
1839
|
-
|
|
1840
|
-
The wrapper preserves existing activation semantics, then applies
|
|
1841
|
-
`normalizeActivations(...)` to produce zero-centered, variance-scaled output.
|
|
1842
|
-
|
|
1843
|
-
This is implemented as a function wrapper rather than modifying node math.
|
|
1844
|
-
That makes it easy to layer normalization behavior onto each dense layer.
|
|
1845
|
-
|
|
1846
|
-
Parameters:
|
|
1847
|
-
- `layer` - - Dense layer to decorate with normalization behavior.
|
|
1848
|
-
|
|
1849
|
-
Returns: No return value.
|
|
1850
|
-
|
|
1851
|
-
Example (conceptual flow):
|
|
1852
|
-
|
|
1853
|
-
```ts
|
|
1854
|
-
// 1) baseActivate(...) computes raw activations
|
|
1855
|
-
// 2) wrapper normalizes the vector before returning
|
|
1856
|
-
```
|
|
1857
|
-
|
|
1858
1858
|
### computeMean
|
|
1859
1859
|
|
|
1860
1860
|
```ts
|