@reicek/neataptic-ts 0.1.21 → 0.1.22
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 +29 -0
- package/.github/agents/docs-scout.agent.md +29 -0
- package/.github/agents/plan-scout.agent.md +29 -0
- package/.github/agents/solid-split.agent.md +138 -0
- package/.github/copilot-instructions.md +103 -0
- package/package.json +6 -3
- package/plans/ES2023 migration +13 -8
- package/plans/Evolution_Training_Interoperability_Contracts.md +1 -1
- package/plans/Interactive_Examples_and_Learning_Path.md +10 -2
- package/plans/Memory_Optimization.md +3 -3
- package/plans/README.md +63 -0
- package/plans/Roadmap.md +15 -3
- package/plans/asciiMaze_SOLID_split.done.md +130 -0
- package/plans/flappy_bird_SOLID_split.done.md +67 -0
- package/scripts/assets/theme.css +221 -34
- package/scripts/copy-examples.mjs +9 -5
- package/scripts/export-onnx.mjs +3 -3
- package/scripts/generate-bench-tables.mjs +10 -10
- package/scripts/generate-bench-tables.ts +10 -10
- package/scripts/generate-docs.ts +1415 -449
- package/scripts/render-docs-html.ts +15 -8
- package/src/README.md +101 -223
- package/src/architecture/README.md +57 -185
- package/src/architecture/layer/README.md +38 -38
- package/src/architecture/network/README.md +33 -31
- package/src/architecture/network/activate/README.md +77 -77
- package/src/architecture/network/connect/README.md +15 -13
- package/src/architecture/network/deterministic/README.md +7 -7
- package/src/architecture/network/evolve/README.md +44 -44
- package/src/architecture/network/gating/README.md +20 -20
- package/src/architecture/network/genetic/README.md +51 -51
- package/src/architecture/network/mutate/README.md +97 -97
- package/src/architecture/network/onnx/README.md +264 -264
- package/src/architecture/network/prune/README.md +39 -39
- package/src/architecture/network/remove/README.md +26 -26
- package/src/architecture/network/serialize/README.md +56 -56
- package/src/architecture/network/slab/README.md +61 -61
- package/src/architecture/network/standalone/README.md +24 -24
- package/src/architecture/network/stats/README.md +9 -9
- package/src/architecture/network/topology/README.md +46 -46
- package/src/architecture/network/training/README.md +21 -21
- package/src/methods/README.md +9 -87
- package/src/multithreading/README.md +8 -77
- package/src/multithreading/workers/README.md +2 -2
- package/src/multithreading/workers/browser/README.md +0 -6
- package/src/multithreading/workers/node/README.md +0 -3
- package/src/neat/README.md +562 -568
- package/src/utils/README.md +18 -18
- package/test/examples/asciiMaze/README.md +59 -59
- package/test/examples/asciiMaze/asciiMaze.e2e.test.ts +14 -9
- package/test/examples/asciiMaze/browser-entry/README.md +196 -0
- package/test/examples/asciiMaze/browser-entry/browser-entry.abort.services.ts +95 -0
- package/test/examples/asciiMaze/browser-entry/browser-entry.constants.ts +23 -0
- package/test/examples/asciiMaze/browser-entry/browser-entry.curriculum.services.ts +115 -0
- package/test/examples/asciiMaze/browser-entry/browser-entry.globals.services.ts +106 -0
- package/test/examples/asciiMaze/browser-entry/browser-entry.host.services.ts +157 -0
- package/test/examples/asciiMaze/browser-entry/browser-entry.services.ts +14 -0
- package/test/examples/asciiMaze/browser-entry/browser-entry.ts +129 -0
- package/test/examples/asciiMaze/browser-entry/browser-entry.types.ts +120 -0
- package/test/examples/asciiMaze/browser-entry/browser-entry.utils.ts +98 -0
- package/test/examples/asciiMaze/browser-entry.ts +10 -576
- package/test/examples/asciiMaze/dashboardManager/README.md +276 -0
- package/test/examples/asciiMaze/dashboardManager/archive/README.md +16 -0
- package/test/examples/asciiMaze/dashboardManager/archive/dashboardManager.archive.services.ts +267 -0
- package/test/examples/asciiMaze/dashboardManager/dashboardManager.constants.ts +35 -0
- package/test/examples/asciiMaze/dashboardManager/dashboardManager.services.ts +103 -0
- package/test/examples/asciiMaze/dashboardManager/dashboardManager.ts +181 -0
- package/test/examples/asciiMaze/dashboardManager/dashboardManager.types.ts +267 -0
- package/test/examples/asciiMaze/dashboardManager/dashboardManager.utils.ts +254 -0
- package/test/examples/asciiMaze/dashboardManager/live/README.md +14 -0
- package/test/examples/asciiMaze/dashboardManager/live/dashboardManager.live.services.ts +264 -0
- package/test/examples/asciiMaze/dashboardManager/telemetry/README.md +47 -0
- package/test/examples/asciiMaze/dashboardManager/telemetry/dashboardManager.telemetry.services.ts +513 -0
- package/test/examples/asciiMaze/dashboardManager.ts +13 -2335
- package/test/examples/asciiMaze/evolutionEngine/README.md +1058 -0
- package/test/examples/asciiMaze/evolutionEngine/curriculumPhase.ts +90 -0
- package/test/examples/asciiMaze/evolutionEngine/engineState.constants.ts +36 -0
- package/test/examples/asciiMaze/evolutionEngine/engineState.ts +58 -513
- package/test/examples/asciiMaze/evolutionEngine/engineState.types.ts +212 -0
- package/test/examples/asciiMaze/evolutionEngine/engineState.utils.ts +301 -0
- package/test/examples/asciiMaze/evolutionEngine/evolutionEngine.types.ts +445 -0
- package/test/examples/asciiMaze/evolutionEngine/evolutionLoop.ts +81 -50
- package/test/examples/asciiMaze/evolutionEngine/optionsAndSetup.ts +2 -4
- package/test/examples/asciiMaze/evolutionEngine/populationDynamics.ts +17 -33
- package/test/examples/asciiMaze/evolutionEngine/populationPruning.ts +1 -1
- package/test/examples/asciiMaze/evolutionEngine/rngAndTiming.ts +1 -2
- package/test/examples/asciiMaze/evolutionEngine/sampling.ts +1 -1
- package/test/examples/asciiMaze/evolutionEngine/scratchPools.ts +2 -5
- package/test/examples/asciiMaze/evolutionEngine/setupHelpers.ts +30 -37
- package/test/examples/asciiMaze/evolutionEngine/telemetryMetrics.ts +16 -58
- package/test/examples/asciiMaze/evolutionEngine/trainingWarmStart.ts +2 -2
- package/test/examples/asciiMaze/evolutionEngine.ts +55 -55
- package/test/examples/asciiMaze/fitness.ts +2 -2
- package/test/examples/asciiMaze/fitness.types.ts +65 -0
- package/test/examples/asciiMaze/interfaces.ts +64 -1352
- package/test/examples/asciiMaze/mazeMovement/README.md +356 -0
- package/test/examples/asciiMaze/mazeMovement/finalization/README.md +49 -0
- package/test/examples/asciiMaze/mazeMovement/finalization/mazeMovement.finalization.ts +138 -0
- package/test/examples/asciiMaze/mazeMovement/mazeMovement.constants.ts +101 -0
- package/test/examples/asciiMaze/mazeMovement/mazeMovement.services.ts +230 -0
- package/test/examples/asciiMaze/mazeMovement/mazeMovement.ts +299 -0
- package/test/examples/asciiMaze/mazeMovement/mazeMovement.types.ts +185 -0
- package/test/examples/asciiMaze/mazeMovement/mazeMovement.utils.ts +153 -0
- package/test/examples/asciiMaze/mazeMovement/policy/README.md +91 -0
- package/test/examples/asciiMaze/mazeMovement/policy/mazeMovement.policy.ts +467 -0
- package/test/examples/asciiMaze/mazeMovement/runtime/README.md +95 -0
- package/test/examples/asciiMaze/mazeMovement/runtime/mazeMovement.runtime.ts +354 -0
- package/test/examples/asciiMaze/mazeMovement/shaping/README.md +124 -0
- package/test/examples/asciiMaze/mazeMovement/shaping/mazeMovement.shaping.ts +459 -0
- package/test/examples/asciiMaze/mazeMovement.ts +12 -2978
- package/test/examples/flappy_bird/Trace-20260309T191949.json +24124 -0
- package/test/examples/flappy_bird/browser-entry/README.md +1129 -0
- package/test/examples/flappy_bird/browser-entry/browser-entry.host.utils.ts +4 -324
- package/test/examples/flappy_bird/browser-entry/browser-entry.network-view.utils.ts +6 -399
- package/test/examples/flappy_bird/browser-entry/browser-entry.playback.utils.ts +1 -717
- package/test/examples/flappy_bird/browser-entry/browser-entry.spawn.utils.ts +11 -31
- package/test/examples/flappy_bird/browser-entry/browser-entry.visualization.utils.ts +15 -893
- package/test/examples/flappy_bird/browser-entry/host/README.md +307 -0
- package/test/examples/flappy_bird/browser-entry/host/host.resize.service.ts +1 -295
- package/test/examples/flappy_bird/browser-entry/host/host.ts +562 -6
- package/test/examples/flappy_bird/browser-entry/host/resize/README.md +274 -0
- package/test/examples/flappy_bird/browser-entry/host/resize/host.resize.service.constants.ts +31 -0
- package/test/examples/flappy_bird/browser-entry/host/resize/host.resize.service.services.ts +360 -0
- package/test/examples/flappy_bird/browser-entry/host/resize/host.resize.service.ts +117 -0
- package/test/examples/flappy_bird/browser-entry/host/resize/host.resize.service.types.ts +63 -0
- package/test/examples/flappy_bird/browser-entry/host/resize/host.resize.service.utils.ts +250 -0
- package/test/examples/flappy_bird/browser-entry/network-view/README.md +399 -0
- package/test/examples/flappy_bird/browser-entry/network-view/network-view.topology.utils.ts +255 -0
- package/test/examples/flappy_bird/browser-entry/network-view/network-view.ts +802 -7
- package/test/examples/flappy_bird/browser-entry/playback/README.md +684 -0
- package/test/examples/flappy_bird/browser-entry/playback/background/README.md +277 -0
- package/test/examples/flappy_bird/browser-entry/playback/background/ground-grid/README.md +770 -0
- package/test/examples/flappy_bird/browser-entry/playback/background/ground-grid/playback.background.ground-grid.cache.services.ts +178 -0
- package/test/examples/flappy_bird/browser-entry/playback/background/ground-grid/playback.background.ground-grid.constants.ts +107 -0
- package/test/examples/flappy_bird/browser-entry/playback/background/ground-grid/playback.background.ground-grid.geometry.utils.ts +518 -0
- package/test/examples/flappy_bird/browser-entry/playback/background/ground-grid/playback.background.ground-grid.math.utils.ts +117 -0
- package/test/examples/flappy_bird/browser-entry/playback/background/ground-grid/playback.background.ground-grid.pulse.utils.ts +233 -0
- package/test/examples/flappy_bird/browser-entry/playback/background/ground-grid/playback.background.ground-grid.services.ts +211 -0
- package/test/examples/flappy_bird/browser-entry/playback/background/ground-grid/playback.background.ground-grid.ts +48 -0
- package/test/examples/flappy_bird/browser-entry/playback/background/ground-grid/playback.background.ground-grid.types.ts +212 -0
- package/test/examples/flappy_bird/browser-entry/playback/background/ground-grid/playback.background.ground-grid.utils.ts +81 -0
- package/test/examples/flappy_bird/browser-entry/playback/background/playback.background.cache.services.ts +96 -0
- package/test/examples/flappy_bird/browser-entry/playback/background/playback.background.constants.ts +62 -0
- package/test/examples/flappy_bird/browser-entry/playback/background/playback.background.services.ts +244 -0
- package/test/examples/flappy_bird/browser-entry/playback/background/playback.background.ts +53 -0
- package/test/examples/flappy_bird/browser-entry/playback/background/playback.background.types.ts +68 -0
- package/test/examples/flappy_bird/browser-entry/playback/background/playback.background.utils.ts +100 -0
- package/test/examples/flappy_bird/browser-entry/playback/frame-render/README.md +310 -0
- package/test/examples/flappy_bird/browser-entry/playback/frame-render/playback.frame-render.service.ts +92 -0
- package/test/examples/flappy_bird/browser-entry/playback/frame-render/playback.frame-render.services.ts +272 -0
- package/test/examples/flappy_bird/browser-entry/playback/frame-render/playback.frame-render.types.ts +39 -0
- package/test/examples/flappy_bird/browser-entry/playback/frame-render/playback.frame-render.utils.ts +493 -0
- package/test/examples/flappy_bird/browser-entry/playback/playback.constants.ts +1 -1
- package/test/examples/flappy_bird/browser-entry/playback/playback.frame-render.service.ts +4 -0
- package/test/examples/flappy_bird/browser-entry/playback/playback.snapshot.utils.ts +44 -0
- package/test/examples/flappy_bird/browser-entry/playback/playback.starfield.service.ts +39 -122
- package/test/examples/flappy_bird/browser-entry/playback/playback.starfield.services.ts +272 -0
- package/test/examples/flappy_bird/browser-entry/playback/playback.starfield.types.ts +62 -0
- package/test/examples/flappy_bird/browser-entry/playback/playback.starfield.utils.ts +11 -4
- package/test/examples/flappy_bird/browser-entry/playback/playback.ts +409 -8
- package/test/examples/flappy_bird/browser-entry/playback/playback.types.ts +4 -12
- package/test/examples/flappy_bird/browser-entry/runtime/README.md +235 -0
- package/test/examples/flappy_bird/browser-entry/runtime/runtime.evolution-launch.service.ts +45 -0
- package/test/examples/flappy_bird/browser-entry/runtime/runtime.lifecycle.service.ts +81 -0
- package/test/examples/flappy_bird/browser-entry/runtime/runtime.startup.service.ts +74 -0
- package/test/examples/flappy_bird/browser-entry/runtime/runtime.ts +31 -121
- package/test/examples/flappy_bird/browser-entry/runtime/runtime.types.ts +36 -0
- package/test/examples/flappy_bird/browser-entry/visualization/README.md +557 -0
- package/test/examples/flappy_bird/browser-entry/visualization/visualization.constants.ts +110 -0
- package/test/examples/flappy_bird/browser-entry/visualization/visualization.draw.service.ts +957 -19
- package/test/examples/flappy_bird/browser-entry/visualization/visualization.legend.utils.ts +138 -3
- package/test/examples/flappy_bird/browser-entry/visualization/visualization.topology.utils.ts +3 -27
- package/test/examples/flappy_bird/browser-entry/visualization/visualization.ts +1 -23
- package/test/examples/flappy_bird/browser-entry/worker-channel/README.md +156 -0
- package/test/examples/flappy_bird/constants/README.md +1179 -0
- package/test/examples/flappy_bird/constants/constants.network-view.ts +24 -0
- package/test/examples/flappy_bird/constants/constants.palette.ts +7 -0
- package/test/examples/flappy_bird/constants/constants.starfield.ts +78 -3
- package/test/examples/flappy_bird/environment/README.md +143 -0
- package/test/examples/flappy_bird/environment/environment.observation.utils.ts +1 -19
- package/test/examples/flappy_bird/environment/environment.step.service.ts +3 -66
- package/test/examples/flappy_bird/evaluation/README.md +130 -0
- package/test/examples/flappy_bird/evaluation/evaluation.fitness.utils.ts +1 -1
- package/test/examples/flappy_bird/evaluation/evaluation.rollout.service.ts +5 -375
- package/test/examples/flappy_bird/evaluation/rollout/README.md +291 -0
- package/test/examples/flappy_bird/evaluation/rollout/evaluation.rollout.constants.ts +30 -0
- package/test/examples/flappy_bird/evaluation/rollout/evaluation.rollout.service.ts +58 -0
- package/test/examples/flappy_bird/evaluation/rollout/evaluation.rollout.services.ts +310 -0
- package/test/examples/flappy_bird/evaluation/rollout/evaluation.rollout.types.ts +56 -0
- package/test/examples/flappy_bird/evaluation/rollout/evaluation.rollout.utils.ts +368 -0
- package/test/examples/flappy_bird/flappy-evolution-worker/README.md +618 -0
- package/test/examples/flappy_bird/flappy-evolution-worker/flappy-evolution-worker.playback.service.ts +7 -7
- package/test/examples/flappy_bird/flappy-evolution-worker/flappy-evolution-worker.simulation.frame.service.ts +364 -0
- package/test/examples/flappy_bird/flappy-evolution-worker/flappy-evolution-worker.simulation.types.ts +14 -0
- package/test/examples/flappy_bird/flappy-evolution-worker/flappy-evolution-worker.simulation.utils.ts +4 -201
- package/test/examples/flappy_bird/flappy-evolution-worker/flappy-evolution-worker.ts +184 -345
- package/test/examples/flappy_bird/flappy-evolution-worker/flappy-evolution-worker.warm-start.service.ts +291 -0
- package/test/examples/flappy_bird/flappy.simulation.shared.utils.ts +5 -0
- package/test/examples/flappy_bird/simulation-shared/README.md +417 -0
- package/test/examples/flappy_bird/simulation-shared/observation/README.md +183 -0
- package/test/examples/flappy_bird/simulation-shared/observation/observation.features.utils.ts +301 -0
- package/test/examples/flappy_bird/simulation-shared/observation/observation.ts +9 -0
- package/test/examples/flappy_bird/simulation-shared/observation/observation.vector.utils.ts +59 -0
- package/test/examples/flappy_bird/simulation-shared/simulation-shared.observation.utils.ts +5 -403
- package/test/examples/flappy_bird/simulation-shared/simulation-shared.spawn.utils.ts +20 -6
- package/test/examples/flappy_bird/{evaluation/evaluation.statistics.utils.ts → simulation-shared/simulation-shared.statistics.utils.ts} +23 -8
- package/test/examples/flappy_bird/trainer/README.md +563 -0
- package/test/examples/flappy_bird/trainer/evaluation/README.md +199 -0
- package/test/examples/flappy_bird/trainer/evaluation/trainer.evaluation.service.constants.ts +9 -0
- package/test/examples/flappy_bird/trainer/evaluation/trainer.evaluation.service.services.ts +73 -0
- package/test/examples/flappy_bird/trainer/evaluation/trainer.evaluation.service.ts +165 -0
- package/test/examples/flappy_bird/trainer/evaluation/trainer.evaluation.service.types.ts +25 -0
- package/test/examples/flappy_bird/trainer/evaluation/trainer.evaluation.service.utils.ts +161 -0
- package/test/examples/flappy_bird/trainer/trainer.evaluation.service.ts +13 -0
- package/test/examples/flappy_bird/trainer/trainer.report.service.services.ts +181 -0
- package/test/examples/flappy_bird/trainer/trainer.report.service.ts +126 -0
- package/test/examples/flappy_bird/trainer/trainer.selection.utils.ts +89 -0
- package/test/examples/flappy_bird/trainer/trainer.ts +11 -553
- package/test/examples/flappy_bird/browser-entry/browser-entry.utils.ts +0 -12
- package/test/examples/flappy_bird/environment/environment.ts +0 -7
- package/test/examples/flappy_bird/evaluation/evaluation.ts +0 -7
- package/test/examples/flappy_bird/simulation-shared/simulation-shared.ts +0 -15
- package/test/examples/flappy_bird/trainer/trainer.statistics.utils.ts +0 -78
|
@@ -0,0 +1,399 @@
|
|
|
1
|
+
# browser-entry/network-view
|
|
2
|
+
|
|
3
|
+
## browser-entry/network-view/network-view.types.ts
|
|
4
|
+
|
|
5
|
+
### network-view.types
|
|
6
|
+
|
|
7
|
+
Input-group label band geometry and style contract.
|
|
8
|
+
|
|
9
|
+
### InputGroupLabelBand
|
|
10
|
+
|
|
11
|
+
Input-group label band geometry and style contract.
|
|
12
|
+
|
|
13
|
+
## browser-entry/network-view/network-view.ts
|
|
14
|
+
|
|
15
|
+
### clampRecommendedNetworkHeightPx
|
|
16
|
+
|
|
17
|
+
`(recommendedHeightPx: number) => number`
|
|
18
|
+
|
|
19
|
+
Clamps a recommended network height into the configured panel range.
|
|
20
|
+
|
|
21
|
+
Parameters:
|
|
22
|
+
|
|
23
|
+
- `recommendedHeightPx` - - Recommended panel height.
|
|
24
|
+
|
|
25
|
+
Returns: Clamped panel height.
|
|
26
|
+
|
|
27
|
+
### createPositionByNodeIndex
|
|
28
|
+
|
|
29
|
+
`(centeredPositionedNodes: import("test/examples/flappy_bird/browser-entry/browser-entry.visualization.types").PositionedNetworkNodeLike[]) => Map<number, import("test/examples/flappy_bird/browser-entry/browser-entry.visualization.types").PositionedNetworkNodeLike>`
|
|
30
|
+
|
|
31
|
+
Builds a node-index lookup map for resolved positioned nodes.
|
|
32
|
+
|
|
33
|
+
Parameters:
|
|
34
|
+
|
|
35
|
+
- `centeredPositionedNodes` - - Positioned nodes after centering.
|
|
36
|
+
|
|
37
|
+
Returns: Map keyed by node index.
|
|
38
|
+
|
|
39
|
+
### drawNetworkVisualization
|
|
40
|
+
|
|
41
|
+
`(context: CanvasRenderingContext2D, network: import("src/architecture/network").default | undefined, inputSize: number, outputSize: number) => void`
|
|
42
|
+
|
|
43
|
+
Draws a complete, layer-based visualization of the active network.
|
|
44
|
+
|
|
45
|
+
Parameters:
|
|
46
|
+
|
|
47
|
+
- `context` - - Canvas 2D drawing context.
|
|
48
|
+
- `network` - - Network to visualize.
|
|
49
|
+
- `inputSize` - - Input-layer size.
|
|
50
|
+
- `outputSize` - - Output-layer size.
|
|
51
|
+
|
|
52
|
+
Returns: Nothing.
|
|
53
|
+
|
|
54
|
+
### drawPositionedNetworkGraph
|
|
55
|
+
|
|
56
|
+
`(context: CanvasRenderingContext2D, networkVisualizationScene: NetworkVisualizationScene, positionedNetworkGraphScene: PositionedNetworkGraphScene) => void`
|
|
57
|
+
|
|
58
|
+
Draws the positioned graph layers and optional guide overlays.
|
|
59
|
+
|
|
60
|
+
Parameters:
|
|
61
|
+
|
|
62
|
+
- `context` - - Canvas 2D drawing context.
|
|
63
|
+
- `networkVisualizationScene` - - Frame scene context.
|
|
64
|
+
- `positionedNetworkGraphScene` - - Positioned graph scene.
|
|
65
|
+
|
|
66
|
+
Returns: Nothing.
|
|
67
|
+
|
|
68
|
+
### formatArchitectureLabel
|
|
69
|
+
|
|
70
|
+
`(architectureInputSize: number, hiddenLayersLabel: string, architectureOutputSize: number, totalNodeCount: number, totalConnectionCount: number) => string`
|
|
71
|
+
|
|
72
|
+
Formats the two-line architecture label used by the header and legend.
|
|
73
|
+
|
|
74
|
+
Parameters:
|
|
75
|
+
|
|
76
|
+
- `architectureInputSize` - - Input layer size.
|
|
77
|
+
- `hiddenLayersLabel` - - Hidden-layer description.
|
|
78
|
+
- `architectureOutputSize` - - Output layer size.
|
|
79
|
+
- `totalNodeCount` - - Total node count.
|
|
80
|
+
- `totalConnectionCount` - - Total connection count.
|
|
81
|
+
|
|
82
|
+
Returns: Formatted architecture label.
|
|
83
|
+
|
|
84
|
+
### paintNetworkVisualizationCanvasBase
|
|
85
|
+
|
|
86
|
+
`(context: CanvasRenderingContext2D, networkVisualizationScene: NetworkVisualizationScene) => void`
|
|
87
|
+
|
|
88
|
+
Paints the base network visualization canvas background.
|
|
89
|
+
|
|
90
|
+
Parameters:
|
|
91
|
+
|
|
92
|
+
- `context` - - Canvas 2D drawing context.
|
|
93
|
+
- `networkVisualizationScene` - - Frame scene context.
|
|
94
|
+
|
|
95
|
+
Returns: Nothing.
|
|
96
|
+
|
|
97
|
+
### resolveAdjustedGraphPaddingContext
|
|
98
|
+
|
|
99
|
+
`(context: CanvasRenderingContext2D, network: import("src/architecture/network").default | undefined, canvasWidthPx: number, hideNetworkOverlays: boolean, graphPaddingContext: NetworkGraphPaddingContext) => Pick<NetworkGraphPaddingContext, "graphLeftPaddingPx" | "graphRightPaddingPx">`
|
|
100
|
+
|
|
101
|
+
Adjusts graph-side padding to keep the floating legend from overlapping nodes.
|
|
102
|
+
|
|
103
|
+
Parameters:
|
|
104
|
+
|
|
105
|
+
- `context` - - Canvas 2D drawing context.
|
|
106
|
+
- `network` - - Network to visualize.
|
|
107
|
+
- `canvasWidthPx` - - Canvas width.
|
|
108
|
+
- `hideNetworkOverlays` - - Whether overlays are hidden.
|
|
109
|
+
- `graphPaddingContext` - - Base graph padding context.
|
|
110
|
+
|
|
111
|
+
Returns: Adjusted graph padding context.
|
|
112
|
+
|
|
113
|
+
### resolveBaseGraphPaddingContext
|
|
114
|
+
|
|
115
|
+
`() => NetworkGraphPaddingContext`
|
|
116
|
+
|
|
117
|
+
Resolves the base graph padding before legend-aware adjustments are applied.
|
|
118
|
+
|
|
119
|
+
Returns: Base graph padding context.
|
|
120
|
+
|
|
121
|
+
### resolveHiddenLayersLabel
|
|
122
|
+
|
|
123
|
+
`(hiddenLayerSizes: number[], architectureSource: "layer-metadata" | "graph-topology" | "inferred") => string`
|
|
124
|
+
|
|
125
|
+
Resolves the hidden-layer portion of the compact architecture label.
|
|
126
|
+
|
|
127
|
+
Parameters:
|
|
128
|
+
|
|
129
|
+
- `hiddenLayerSizes` - - Hidden-layer sizes.
|
|
130
|
+
- `architectureSource` - - Architecture source metadata.
|
|
131
|
+
|
|
132
|
+
Returns: Hidden-layer label.
|
|
133
|
+
|
|
134
|
+
### resolveNetworkArchitectureLabel
|
|
135
|
+
|
|
136
|
+
`(network: import("src/architecture/network").default | undefined, inputSize: number, outputSize: number) => string`
|
|
137
|
+
|
|
138
|
+
Resolves compact architecture label text for headers and HUD rows.
|
|
139
|
+
|
|
140
|
+
Parameters:
|
|
141
|
+
|
|
142
|
+
- `network` - - Network to describe.
|
|
143
|
+
- `inputSize` - - Configured input size.
|
|
144
|
+
- `outputSize` - - Configured output size.
|
|
145
|
+
|
|
146
|
+
Returns: Readable architecture label.
|
|
147
|
+
|
|
148
|
+
### resolveNetworkDrawableArea
|
|
149
|
+
|
|
150
|
+
`(networkVisualizationScene: NetworkVisualizationScene) => NetworkDrawableArea`
|
|
151
|
+
|
|
152
|
+
Resolves the drawable graph area after scene padding is applied.
|
|
153
|
+
|
|
154
|
+
Parameters:
|
|
155
|
+
|
|
156
|
+
- `networkVisualizationScene` - - Frame scene context.
|
|
157
|
+
|
|
158
|
+
Returns: Drawable area dimensions.
|
|
159
|
+
|
|
160
|
+
### resolveNetworkNodeDimensions
|
|
161
|
+
|
|
162
|
+
`(network: import("src/architecture/network").default | undefined, inputSize: number, outputSize: number, drawableWidthPx: number, drawableHeightPx: number) => import("test/examples/flappy_bird/browser-entry/browser-entry.visualization.types").NetworkNodeDimensionsLike`
|
|
163
|
+
|
|
164
|
+
Resolves node rectangle dimensions from topology density and drawable bounds.
|
|
165
|
+
|
|
166
|
+
Parameters:
|
|
167
|
+
|
|
168
|
+
- `network` - - Network to visualize.
|
|
169
|
+
- `inputSize` - - Input-layer size.
|
|
170
|
+
- `outputSize` - - Output-layer size.
|
|
171
|
+
- `drawableWidthPx` - - Drawable graph width.
|
|
172
|
+
- `drawableHeightPx` - - Drawable graph height.
|
|
173
|
+
|
|
174
|
+
Returns: Node dimensions.
|
|
175
|
+
|
|
176
|
+
### resolveNetworkNodeDimensionsFromTopologySummary
|
|
177
|
+
|
|
178
|
+
`(networkTopologySummary: NetworkTopologySummary, drawableWidthPx: number, drawableHeightPx: number) => import("test/examples/flappy_bird/browser-entry/browser-entry.visualization.types").NetworkNodeDimensionsLike`
|
|
179
|
+
|
|
180
|
+
Resolves node rectangle dimensions from topology density and drawable bounds.
|
|
181
|
+
|
|
182
|
+
Parameters:
|
|
183
|
+
|
|
184
|
+
- `networkTopologySummary` - - Topology summary.
|
|
185
|
+
- `drawableWidthPx` - - Drawable graph width.
|
|
186
|
+
- `drawableHeightPx` - - Drawable graph height.
|
|
187
|
+
|
|
188
|
+
Returns: Node dimensions.
|
|
189
|
+
|
|
190
|
+
### resolveNetworkTopologySummary
|
|
191
|
+
|
|
192
|
+
`(network: import("src/architecture/network").default | undefined, inputSize: number, outputSize: number) => NetworkTopologySummary`
|
|
193
|
+
|
|
194
|
+
Resolves a reusable topology summary for layout and sizing helpers.
|
|
195
|
+
|
|
196
|
+
Parameters:
|
|
197
|
+
|
|
198
|
+
- `network` - - Network to visualize.
|
|
199
|
+
- `inputSize` - - Input-layer size.
|
|
200
|
+
- `outputSize` - - Output-layer size.
|
|
201
|
+
|
|
202
|
+
Returns: Topology summary.
|
|
203
|
+
|
|
204
|
+
### resolveNetworkVisualizationHeightPx
|
|
205
|
+
|
|
206
|
+
`(network: import("src/architecture/network").default | undefined, inputSize: number, outputSize: number) => number`
|
|
207
|
+
|
|
208
|
+
Resolves responsive visualization canvas height from network shape.
|
|
209
|
+
|
|
210
|
+
Parameters:
|
|
211
|
+
|
|
212
|
+
- `network` - - Network to visualize.
|
|
213
|
+
- `inputSize` - - Input-layer size.
|
|
214
|
+
- `outputSize` - - Output-layer size.
|
|
215
|
+
|
|
216
|
+
Returns: Recommended height in pixels.
|
|
217
|
+
|
|
218
|
+
### resolveNetworkVisualizationScene
|
|
219
|
+
|
|
220
|
+
`(context: CanvasRenderingContext2D, network: import("src/architecture/network").default | undefined, inputSize: number, outputSize: number) => NetworkVisualizationScene`
|
|
221
|
+
|
|
222
|
+
Resolves all non-topology canvas state needed to draw the network view.
|
|
223
|
+
|
|
224
|
+
Parameters:
|
|
225
|
+
|
|
226
|
+
- `context` - - Canvas 2D drawing context.
|
|
227
|
+
- `network` - - Network to visualize.
|
|
228
|
+
- `inputSize` - - Input-layer size.
|
|
229
|
+
- `outputSize` - - Output-layer size.
|
|
230
|
+
|
|
231
|
+
Returns: Scene context for the current frame.
|
|
232
|
+
|
|
233
|
+
### resolvePositionedNetworkGraphScene
|
|
234
|
+
|
|
235
|
+
`(networkVisualizationScene: NetworkVisualizationScene, network: import("src/architecture/network").default | undefined, inputSize: number, outputSize: number) => PositionedNetworkGraphScene`
|
|
236
|
+
|
|
237
|
+
Resolves positioned nodes, connection lookup state, and shared node dimensions.
|
|
238
|
+
|
|
239
|
+
Parameters:
|
|
240
|
+
|
|
241
|
+
- `networkVisualizationScene` - - Frame scene context.
|
|
242
|
+
- `network` - - Network to visualize.
|
|
243
|
+
- `inputSize` - - Input-layer size.
|
|
244
|
+
- `outputSize` - - Output-layer size.
|
|
245
|
+
|
|
246
|
+
Returns: Positioned graph scene.
|
|
247
|
+
|
|
248
|
+
### resolveRecommendedNetworkHeightPx
|
|
249
|
+
|
|
250
|
+
`(networkTopologySummary: NetworkTopologySummary, topologyDrivenHeightPx: number) => number`
|
|
251
|
+
|
|
252
|
+
Resolves the recommended panel height from topology and density adjustments.
|
|
253
|
+
|
|
254
|
+
Parameters:
|
|
255
|
+
|
|
256
|
+
- `networkTopologySummary` - - Topology summary.
|
|
257
|
+
- `topologyDrivenHeightPx` - - Minimum readable topology height.
|
|
258
|
+
|
|
259
|
+
Returns: Recommended panel height.
|
|
260
|
+
|
|
261
|
+
### resolveRuntimeConnections
|
|
262
|
+
|
|
263
|
+
`(network: import("src/architecture/network").default | undefined) => import("test/examples/flappy_bird/browser-entry/browser-entry.visualization.types").VisualNetworkConnectionLike[]`
|
|
264
|
+
|
|
265
|
+
Resolves the runtime connection array from the active network.
|
|
266
|
+
|
|
267
|
+
Parameters:
|
|
268
|
+
|
|
269
|
+
- `network` - - Network to visualize.
|
|
270
|
+
|
|
271
|
+
Returns: Runtime connection list.
|
|
272
|
+
|
|
273
|
+
### resolveTopologyDrivenHeightPx
|
|
274
|
+
|
|
275
|
+
`(networkTopologySummary: NetworkTopologySummary) => number`
|
|
276
|
+
|
|
277
|
+
Resolves the topology-driven minimum readable height.
|
|
278
|
+
|
|
279
|
+
Parameters:
|
|
280
|
+
|
|
281
|
+
- `networkTopologySummary` - - Topology summary.
|
|
282
|
+
|
|
283
|
+
Returns: Minimum readable height in pixels.
|
|
284
|
+
|
|
285
|
+
### shouldHideNetworkOverlays
|
|
286
|
+
|
|
287
|
+
`(context: CanvasRenderingContext2D, fallbackViewportWidthPx: number) => boolean`
|
|
288
|
+
|
|
289
|
+
Determines whether responsive rules hide auxiliary network overlays.
|
|
290
|
+
|
|
291
|
+
Parameters:
|
|
292
|
+
|
|
293
|
+
- `context` - - Canvas 2D drawing context.
|
|
294
|
+
- `fallbackViewportWidthPx` - - Fallback viewport width.
|
|
295
|
+
|
|
296
|
+
Returns: True when overlays should be hidden.
|
|
297
|
+
|
|
298
|
+
## browser-entry/network-view/network-view.constants.ts
|
|
299
|
+
|
|
300
|
+
### network-view.constants
|
|
301
|
+
|
|
302
|
+
Ordered labels for grouped Flappy network input bands.
|
|
303
|
+
|
|
304
|
+
### FLAPPY_INPUT_GROUP_LABELS
|
|
305
|
+
|
|
306
|
+
## browser-entry/network-view/network-view.draw.service.ts
|
|
307
|
+
|
|
308
|
+
### drawInputGroupLabelBands
|
|
309
|
+
|
|
310
|
+
`(context: CanvasRenderingContext2D, positionedNodes: import("test/examples/flappy_bird/browser-entry/browser-entry.visualization.types").PositionedNetworkNodeLike[], nodeDimensions: import("test/examples/flappy_bird/browser-entry/browser-entry.visualization.types").NetworkNodeDimensionsLike) => void`
|
|
311
|
+
|
|
312
|
+
Draws vertical neon bands that label semantic groups in the input layer.
|
|
313
|
+
|
|
314
|
+
Parameters:
|
|
315
|
+
|
|
316
|
+
- `context` - - Canvas 2D rendering context.
|
|
317
|
+
- `positionedNodes` - - Positioned nodes in graph coordinates.
|
|
318
|
+
- `nodeDimensions` - - Resolved node dimensions.
|
|
319
|
+
|
|
320
|
+
Returns: Nothing.
|
|
321
|
+
|
|
322
|
+
### drawRoundedRect
|
|
323
|
+
|
|
324
|
+
`(context: CanvasRenderingContext2D, leftXPx: number, topYPx: number, widthPx: number, heightPx: number, radiusPx: number, fillColor: string) => void`
|
|
325
|
+
|
|
326
|
+
Draws a filled rounded rectangle path.
|
|
327
|
+
|
|
328
|
+
## browser-entry/network-view/network-view.labels.utils.ts
|
|
329
|
+
|
|
330
|
+
### resolveInputGroupLabelBands
|
|
331
|
+
|
|
332
|
+
`(inputNodeCount: number) => import("test/examples/flappy_bird/browser-entry/network-view/network-view.types").InputGroupLabelBand[]`
|
|
333
|
+
|
|
334
|
+
Resolves input-layer semantic label bands for Flappy temporal observation channels.
|
|
335
|
+
|
|
336
|
+
Parameters:
|
|
337
|
+
|
|
338
|
+
- `inputNodeCount` - - Input-layer node count.
|
|
339
|
+
|
|
340
|
+
Returns: Group label ranges with band colors.
|
|
341
|
+
|
|
342
|
+
## browser-entry/network-view/network-view.layout.utils.ts
|
|
343
|
+
|
|
344
|
+
### centerPositionedNodesInDrawableArea
|
|
345
|
+
|
|
346
|
+
`(positionedNodes: import("test/examples/flappy_bird/browser-entry/browser-entry.visualization.types").PositionedNetworkNodeLike[], leftPaddingPx: number, topPaddingPx: number, drawableWidthPx: number, drawableHeightPx: number, nodeLayoutPaddingPx: number, nodeDimensions: import("test/examples/flappy_bird/browser-entry/browser-entry.visualization.types").NetworkNodeDimensionsLike) => import("test/examples/flappy_bird/browser-entry/browser-entry.visualization.types").PositionedNetworkNodeLike[]`
|
|
347
|
+
|
|
348
|
+
Centers positioned nodes within the drawable graph area.
|
|
349
|
+
|
|
350
|
+
Parameters:
|
|
351
|
+
|
|
352
|
+
- `positionedNodes` - - Positioned nodes before centering.
|
|
353
|
+
- `leftPaddingPx` - - Left graph padding.
|
|
354
|
+
- `topPaddingPx` - - Top graph padding.
|
|
355
|
+
- `drawableWidthPx` - - Drawable graph width.
|
|
356
|
+
- `drawableHeightPx` - - Drawable graph height.
|
|
357
|
+
- `nodeLayoutPaddingPx` - - Inner graph padding.
|
|
358
|
+
- `nodeDimensions` - - Node dimensions.
|
|
359
|
+
|
|
360
|
+
Returns: Center-aligned positioned nodes.
|
|
361
|
+
|
|
362
|
+
### positionNetworkNodes
|
|
363
|
+
|
|
364
|
+
`(networkLayers: import("test/examples/flappy_bird/browser-entry/browser-entry.visualization.types").VisualNetworkNodeLike[][], leftPaddingPx: number, topPaddingPx: number, drawableWidthPx: number, drawableHeightPx: number, nodeLayoutPaddingPx: number, nodeDimensions: import("test/examples/flappy_bird/browser-entry/browser-entry.visualization.types").NetworkNodeDimensionsLike) => import("test/examples/flappy_bird/browser-entry/browser-entry.visualization.types").PositionedNetworkNodeLike[]`
|
|
365
|
+
|
|
366
|
+
Positions network nodes into drawable canvas coordinates.
|
|
367
|
+
|
|
368
|
+
Parameters:
|
|
369
|
+
|
|
370
|
+
- `networkLayers` - - Resolved network layers.
|
|
371
|
+
- `leftPaddingPx` - - Left graph padding.
|
|
372
|
+
- `topPaddingPx` - - Top graph padding.
|
|
373
|
+
- `drawableWidthPx` - - Drawable graph width.
|
|
374
|
+
- `drawableHeightPx` - - Drawable graph height.
|
|
375
|
+
- `nodeLayoutPaddingPx` - - Inner graph padding.
|
|
376
|
+
- `nodeDimensions` - - Node dimensions.
|
|
377
|
+
|
|
378
|
+
Returns: Positioned nodes.
|
|
379
|
+
|
|
380
|
+
## browser-entry/network-view/network-view.topology.utils.ts
|
|
381
|
+
|
|
382
|
+
### resolveNetworkVisualizationLayers
|
|
383
|
+
|
|
384
|
+
`(network: import("src/architecture/network").default | undefined, inputSize: number, outputSize: number) => import("test/examples/flappy_bird/browser-entry/browser-entry.visualization.types").VisualNetworkNodeLike[][]`
|
|
385
|
+
|
|
386
|
+
Resolves layered node groups for network-view layout and rendering.
|
|
387
|
+
|
|
388
|
+
Educational note:
|
|
389
|
+
Layer grouping is a network-view concern because it drives sizing, node
|
|
390
|
+
placement, and architecture presentation. Visualization code can still reuse
|
|
391
|
+
the result, but this helper now lives with the module that owns layout.
|
|
392
|
+
|
|
393
|
+
Parameters:
|
|
394
|
+
|
|
395
|
+
- `network` - - Runtime network instance.
|
|
396
|
+
- `inputSize` - - Input count fallback.
|
|
397
|
+
- `outputSize` - - Output count fallback.
|
|
398
|
+
|
|
399
|
+
Returns: Layered nodes for rendering.
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
import Network from '../../../../../src/architecture/network';
|
|
2
|
+
import type {
|
|
3
|
+
VisualNetworkConnectionLike,
|
|
4
|
+
VisualNetworkNodeLike,
|
|
5
|
+
} from '../browser-entry.types';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Resolves layered node groups for network-view layout and rendering.
|
|
9
|
+
*
|
|
10
|
+
* Educational note:
|
|
11
|
+
* Layer grouping is a network-view concern because it drives sizing, node
|
|
12
|
+
* placement, and architecture presentation. Visualization code can still reuse
|
|
13
|
+
* the result, but this helper now lives with the module that owns layout.
|
|
14
|
+
*
|
|
15
|
+
* @param network - Runtime network instance.
|
|
16
|
+
* @param inputSize - Input count fallback.
|
|
17
|
+
* @param outputSize - Output count fallback.
|
|
18
|
+
* @returns Layered nodes for rendering.
|
|
19
|
+
*/
|
|
20
|
+
export function resolveNetworkVisualizationLayers(
|
|
21
|
+
network: Network | undefined,
|
|
22
|
+
inputSize: number,
|
|
23
|
+
outputSize: number,
|
|
24
|
+
): VisualNetworkNodeLike[][] {
|
|
25
|
+
// Step 1: Build fallback layers when no runtime network is available.
|
|
26
|
+
if (!network) {
|
|
27
|
+
return [
|
|
28
|
+
Array.from({ length: inputSize }, (_unusedValue, inputNodeIndex) => ({
|
|
29
|
+
index: inputNodeIndex,
|
|
30
|
+
type: 'input',
|
|
31
|
+
bias: 0,
|
|
32
|
+
})),
|
|
33
|
+
Array.from({ length: outputSize }, (_unusedValue, outputNodeIndex) => ({
|
|
34
|
+
index: inputSize + outputNodeIndex,
|
|
35
|
+
type: 'output',
|
|
36
|
+
bias: 0,
|
|
37
|
+
})),
|
|
38
|
+
];
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Step 2: Normalize runtime node records into the view-layer shape.
|
|
42
|
+
const runtimeNodes = (
|
|
43
|
+
(network.nodes ?? []) as Array<{
|
|
44
|
+
index?: number;
|
|
45
|
+
type?: string;
|
|
46
|
+
bias?: number;
|
|
47
|
+
layer?: number;
|
|
48
|
+
}>
|
|
49
|
+
).map((runtimeNode, fallbackNodeIndex) => ({
|
|
50
|
+
index:
|
|
51
|
+
typeof runtimeNode.index === 'number'
|
|
52
|
+
? runtimeNode.index
|
|
53
|
+
: fallbackNodeIndex,
|
|
54
|
+
type: runtimeNode.type ?? 'hidden',
|
|
55
|
+
bias: runtimeNode.bias ?? 0,
|
|
56
|
+
layer: runtimeNode.layer,
|
|
57
|
+
}));
|
|
58
|
+
|
|
59
|
+
// Step 3: Resolve input, hidden, and output partitions.
|
|
60
|
+
const inputAndConstantNodes = runtimeNodes
|
|
61
|
+
.filter(
|
|
62
|
+
(runtimeNode) =>
|
|
63
|
+
runtimeNode.type === 'input' || runtimeNode.type === 'constant',
|
|
64
|
+
)
|
|
65
|
+
.toSorted((leftNode, rightNode) => leftNode.index - rightNode.index);
|
|
66
|
+
const outputNodes = runtimeNodes
|
|
67
|
+
.filter((runtimeNode) => runtimeNode.type === 'output')
|
|
68
|
+
.toSorted((leftNode, rightNode) => leftNode.index - rightNode.index);
|
|
69
|
+
const hiddenNodes = runtimeNodes.filter(
|
|
70
|
+
(runtimeNode) =>
|
|
71
|
+
runtimeNode.type !== 'input' &&
|
|
72
|
+
runtimeNode.type !== 'constant' &&
|
|
73
|
+
runtimeNode.type !== 'output',
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
// Step 4: Prefer layer metadata, then fall back to topology-derived depth.
|
|
77
|
+
const hiddenLayersByMetadata = groupHiddenNodesByLayerMetadata(hiddenNodes);
|
|
78
|
+
const hiddenLayers =
|
|
79
|
+
hiddenLayersByMetadata.length > 0
|
|
80
|
+
? hiddenLayersByMetadata
|
|
81
|
+
: groupHiddenNodesByTopology(network, runtimeNodes, hiddenNodes);
|
|
82
|
+
const layeredNodes = [
|
|
83
|
+
inputAndConstantNodes,
|
|
84
|
+
...hiddenLayers,
|
|
85
|
+
outputNodes,
|
|
86
|
+
].filter((layerNodes) => layerNodes.length > 0);
|
|
87
|
+
|
|
88
|
+
return layeredNodes.length > 0 ? layeredNodes : [runtimeNodes];
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function groupHiddenNodesByLayerMetadata(
|
|
92
|
+
hiddenNodes: VisualNetworkNodeLike[],
|
|
93
|
+
): VisualNetworkNodeLike[][] {
|
|
94
|
+
const hiddenNodesWithLayer = hiddenNodes.filter(
|
|
95
|
+
(hiddenNode) => typeof hiddenNode.layer === 'number',
|
|
96
|
+
);
|
|
97
|
+
if (hiddenNodesWithLayer.length === 0) {
|
|
98
|
+
return [];
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const nodesByLayer = new Map<number, VisualNetworkNodeLike[]>();
|
|
102
|
+
hiddenNodesWithLayer.forEach((hiddenNode) => {
|
|
103
|
+
const layerIndex = hiddenNode.layer as number;
|
|
104
|
+
const existingLayerNodes = nodesByLayer.get(layerIndex) ?? [];
|
|
105
|
+
existingLayerNodes.push(hiddenNode);
|
|
106
|
+
nodesByLayer.set(layerIndex, existingLayerNodes);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
return [...nodesByLayer.entries()]
|
|
110
|
+
.toSorted(
|
|
111
|
+
(leftLayerEntry, rightLayerEntry) =>
|
|
112
|
+
leftLayerEntry[0] - rightLayerEntry[0],
|
|
113
|
+
)
|
|
114
|
+
.map((layerEntry) =>
|
|
115
|
+
layerEntry[1].toSorted(
|
|
116
|
+
(leftNode, rightNode) => leftNode.index - rightNode.index,
|
|
117
|
+
),
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function groupHiddenNodesByTopology(
|
|
122
|
+
network: Network,
|
|
123
|
+
runtimeNodes: VisualNetworkNodeLike[],
|
|
124
|
+
hiddenNodes: VisualNetworkNodeLike[],
|
|
125
|
+
): VisualNetworkNodeLike[][] {
|
|
126
|
+
if (hiddenNodes.length === 0) {
|
|
127
|
+
return [];
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const hiddenDepthByNodeIndex = resolveHiddenNodeDepthByTopology(
|
|
131
|
+
runtimeNodes,
|
|
132
|
+
(network.connections ?? []) as VisualNetworkConnectionLike[],
|
|
133
|
+
);
|
|
134
|
+
const nodesByDepth = new Map<number, VisualNetworkNodeLike[]>();
|
|
135
|
+
|
|
136
|
+
hiddenNodes.forEach((hiddenNode) => {
|
|
137
|
+
const depth = hiddenDepthByNodeIndex.get(hiddenNode.index) ?? 1;
|
|
138
|
+
const existingDepthNodes = nodesByDepth.get(depth) ?? [];
|
|
139
|
+
existingDepthNodes.push(hiddenNode);
|
|
140
|
+
nodesByDepth.set(depth, existingDepthNodes);
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
return [...nodesByDepth.entries()]
|
|
144
|
+
.toSorted(
|
|
145
|
+
(leftDepthEntry, rightDepthEntry) =>
|
|
146
|
+
leftDepthEntry[0] - rightDepthEntry[0],
|
|
147
|
+
)
|
|
148
|
+
.map((depthEntry) =>
|
|
149
|
+
depthEntry[1].toSorted(
|
|
150
|
+
(leftNode, rightNode) => leftNode.index - rightNode.index,
|
|
151
|
+
),
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function resolveHiddenNodeDepthByTopology(
|
|
156
|
+
runtimeNodes: VisualNetworkNodeLike[],
|
|
157
|
+
runtimeConnections: VisualNetworkConnectionLike[],
|
|
158
|
+
): Map<number, number> {
|
|
159
|
+
const nodeByIndex = new Map<number, VisualNetworkNodeLike>(
|
|
160
|
+
runtimeNodes.map((runtimeNode) => [runtimeNode.index, runtimeNode]),
|
|
161
|
+
);
|
|
162
|
+
const outgoingTargetsByNode = new Map<number, number[]>();
|
|
163
|
+
const incomingEdgeCountByNode = new Map<number, number>();
|
|
164
|
+
|
|
165
|
+
nodeByIndex.forEach((_runtimeNode, runtimeNodeIndex) => {
|
|
166
|
+
outgoingTargetsByNode.set(runtimeNodeIndex, []);
|
|
167
|
+
incomingEdgeCountByNode.set(runtimeNodeIndex, 0);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
runtimeConnections.forEach((runtimeConnection) => {
|
|
171
|
+
if (runtimeConnection.enabled === false) {
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const fromNodeIndex = runtimeConnection.from?.index;
|
|
176
|
+
const toNodeIndex = runtimeConnection.to?.index;
|
|
177
|
+
if (
|
|
178
|
+
typeof fromNodeIndex !== 'number' ||
|
|
179
|
+
typeof toNodeIndex !== 'number' ||
|
|
180
|
+
!nodeByIndex.has(fromNodeIndex) ||
|
|
181
|
+
!nodeByIndex.has(toNodeIndex) ||
|
|
182
|
+
fromNodeIndex === toNodeIndex
|
|
183
|
+
) {
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
const outgoingTargets = outgoingTargetsByNode.get(fromNodeIndex) ?? [];
|
|
188
|
+
outgoingTargets.push(toNodeIndex);
|
|
189
|
+
outgoingTargetsByNode.set(fromNodeIndex, outgoingTargets);
|
|
190
|
+
incomingEdgeCountByNode.set(
|
|
191
|
+
toNodeIndex,
|
|
192
|
+
(incomingEdgeCountByNode.get(toNodeIndex) ?? 0) + 1,
|
|
193
|
+
);
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
const topologicalQueue = [...incomingEdgeCountByNode.entries()]
|
|
197
|
+
.filter((incomingEntry) => incomingEntry[1] === 0)
|
|
198
|
+
.map((incomingEntry) => incomingEntry[0]);
|
|
199
|
+
const topologicalOrder: number[] = [];
|
|
200
|
+
|
|
201
|
+
while (topologicalQueue.length > 0) {
|
|
202
|
+
const currentNodeIndex = topologicalQueue.shift();
|
|
203
|
+
if (typeof currentNodeIndex !== 'number') {
|
|
204
|
+
continue;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
topologicalOrder.push(currentNodeIndex);
|
|
208
|
+
|
|
209
|
+
const outgoingTargets = outgoingTargetsByNode.get(currentNodeIndex) ?? [];
|
|
210
|
+
outgoingTargets.forEach((targetNodeIndex) => {
|
|
211
|
+
const remainingIncomingCount =
|
|
212
|
+
(incomingEdgeCountByNode.get(targetNodeIndex) ?? 0) - 1;
|
|
213
|
+
incomingEdgeCountByNode.set(targetNodeIndex, remainingIncomingCount);
|
|
214
|
+
if (remainingIncomingCount === 0) {
|
|
215
|
+
topologicalQueue.push(targetNodeIndex);
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
if (topologicalOrder.length !== nodeByIndex.size) {
|
|
221
|
+
return new Map<number, number>(
|
|
222
|
+
runtimeNodes
|
|
223
|
+
.filter((runtimeNode) => runtimeNode.type === 'hidden')
|
|
224
|
+
.map((runtimeNode) => [runtimeNode.index, 1]),
|
|
225
|
+
);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
const depthByNodeIndex = new Map<number, number>();
|
|
229
|
+
runtimeNodes.forEach((runtimeNode) => {
|
|
230
|
+
const baseDepth =
|
|
231
|
+
runtimeNode.type === 'input' || runtimeNode.type === 'constant' ? 0 : 1;
|
|
232
|
+
depthByNodeIndex.set(runtimeNode.index, baseDepth);
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
topologicalOrder.forEach((fromNodeIndex) => {
|
|
236
|
+
const fromDepth = depthByNodeIndex.get(fromNodeIndex) ?? 0;
|
|
237
|
+
const outgoingTargets = outgoingTargetsByNode.get(fromNodeIndex) ?? [];
|
|
238
|
+
outgoingTargets.forEach((toNodeIndex) => {
|
|
239
|
+
const nextDepth = Math.max(
|
|
240
|
+
depthByNodeIndex.get(toNodeIndex) ?? 1,
|
|
241
|
+
fromDepth + 1,
|
|
242
|
+
);
|
|
243
|
+
depthByNodeIndex.set(toNodeIndex, nextDepth);
|
|
244
|
+
});
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
return new Map<number, number>(
|
|
248
|
+
runtimeNodes
|
|
249
|
+
.filter((runtimeNode) => runtimeNode.type === 'hidden')
|
|
250
|
+
.map((runtimeNode) => [
|
|
251
|
+
runtimeNode.index,
|
|
252
|
+
depthByNodeIndex.get(runtimeNode.index) ?? 1,
|
|
253
|
+
]),
|
|
254
|
+
);
|
|
255
|
+
}
|