@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
|
@@ -1,6 +1,126 @@
|
|
|
1
1
|
import Network from '../../../../../src/architecture/network';
|
|
2
|
-
import
|
|
3
|
-
|
|
2
|
+
import {
|
|
3
|
+
FLAPPY_NETWORK_LEGEND_BOTTOM_PADDING_PX,
|
|
4
|
+
FLAPPY_NETWORK_LEGEND_COMPACT_HEIGHT_THRESHOLD_PX,
|
|
5
|
+
FLAPPY_NETWORK_LEGEND_COMPACT_ROW_HEIGHT_PX,
|
|
6
|
+
FLAPPY_NETWORK_LEGEND_COMPACT_SECTION_GAP_PX,
|
|
7
|
+
FLAPPY_NETWORK_LEGEND_COMPACT_SECTION_TITLE_HEIGHT_PX,
|
|
8
|
+
FLAPPY_NETWORK_LEGEND_COMPACT_WIDTH_PX,
|
|
9
|
+
FLAPPY_NETWORK_LEGEND_COMPACT_WIDTH_THRESHOLD_PX,
|
|
10
|
+
FLAPPY_NETWORK_LEGEND_HEADER_HEIGHT_PX,
|
|
11
|
+
FLAPPY_NETWORK_LEGEND_MARGIN_PX,
|
|
12
|
+
FLAPPY_NETWORK_LEGEND_MIN_TOP_PX,
|
|
13
|
+
FLAPPY_NETWORK_LEGEND_REGULAR_ROW_HEIGHT_PX,
|
|
14
|
+
FLAPPY_NETWORK_LEGEND_REGULAR_SECTION_GAP_PX,
|
|
15
|
+
FLAPPY_NETWORK_LEGEND_REGULAR_SECTION_TITLE_HEIGHT_PX,
|
|
16
|
+
FLAPPY_NETWORK_LEGEND_REGULAR_WIDTH_PX,
|
|
17
|
+
FLAPPY_NETWORK_LEGEND_TARGET_TOP_PX,
|
|
18
|
+
FLAPPY_NETWORK_LEGEND_TOP_LEFT_THRESHOLD_PX,
|
|
19
|
+
} from '../../constants/constants';
|
|
20
|
+
import { clamp } from '../browser-entry.math.utils';
|
|
21
|
+
import type {
|
|
22
|
+
ColorLegendRow,
|
|
23
|
+
NetworkLegendLayout,
|
|
24
|
+
} from '../browser-entry.types';
|
|
25
|
+
import { assertFiniteLegendBound } from './visualization.errors';
|
|
26
|
+
import { resolveNetworkVisualizationColorScales } from './visualization.colors.utils';
|
|
27
|
+
import type { DynamicColorScale } from './visualization.types';
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Creates legend rows from ordered tiers.
|
|
31
|
+
*
|
|
32
|
+
* @param scale - Dynamic color scale containing bounds, tiers, and overflow color.
|
|
33
|
+
* @param symbol - Label symbol.
|
|
34
|
+
* @returns Legend rows.
|
|
35
|
+
*/
|
|
36
|
+
export function createColorLegendRows(
|
|
37
|
+
scale: DynamicColorScale,
|
|
38
|
+
symbol: 'w' | 'b',
|
|
39
|
+
): ColorLegendRow[] {
|
|
40
|
+
return scale.tiers.map((tier, tierIndex) => {
|
|
41
|
+
const lowerBound =
|
|
42
|
+
tierIndex === 0
|
|
43
|
+
? scale.minimumValue
|
|
44
|
+
: scale.tiers[tierIndex - 1].upperBound;
|
|
45
|
+
return {
|
|
46
|
+
label: `${formatLegendBound(lowerBound)} <= ${symbol} <= ${formatLegendBound(tier.upperBound)}`,
|
|
47
|
+
color: tier.color,
|
|
48
|
+
minimumValue: lowerBound,
|
|
49
|
+
maximumValue: tier.upperBound,
|
|
50
|
+
};
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Resolves network legend layout from canvas constraints.
|
|
56
|
+
*
|
|
57
|
+
* @param context - Render context.
|
|
58
|
+
* @param connectionLegendRows - Connection legend rows.
|
|
59
|
+
* @param biasLegendRows - Bias legend rows.
|
|
60
|
+
* @returns Computed legend layout.
|
|
61
|
+
*/
|
|
62
|
+
export function resolveNetworkLegendLayout(
|
|
63
|
+
context: CanvasRenderingContext2D,
|
|
64
|
+
connectionLegendRows: ColorLegendRow[],
|
|
65
|
+
biasLegendRows: ColorLegendRow[],
|
|
66
|
+
): NetworkLegendLayout {
|
|
67
|
+
const compactLegend =
|
|
68
|
+
context.canvas.width < FLAPPY_NETWORK_LEGEND_COMPACT_WIDTH_THRESHOLD_PX ||
|
|
69
|
+
context.canvas.height < FLAPPY_NETWORK_LEGEND_COMPACT_HEIGHT_THRESHOLD_PX;
|
|
70
|
+
const legendWidthPx = compactLegend
|
|
71
|
+
? FLAPPY_NETWORK_LEGEND_COMPACT_WIDTH_PX
|
|
72
|
+
: FLAPPY_NETWORK_LEGEND_REGULAR_WIDTH_PX;
|
|
73
|
+
const legendHeaderHeightPx = FLAPPY_NETWORK_LEGEND_HEADER_HEIGHT_PX;
|
|
74
|
+
const legendSectionTitleHeightPx = compactLegend
|
|
75
|
+
? FLAPPY_NETWORK_LEGEND_COMPACT_SECTION_TITLE_HEIGHT_PX
|
|
76
|
+
: FLAPPY_NETWORK_LEGEND_REGULAR_SECTION_TITLE_HEIGHT_PX;
|
|
77
|
+
const legendRowHeightPx = compactLegend
|
|
78
|
+
? FLAPPY_NETWORK_LEGEND_COMPACT_ROW_HEIGHT_PX
|
|
79
|
+
: FLAPPY_NETWORK_LEGEND_REGULAR_ROW_HEIGHT_PX;
|
|
80
|
+
const legendSectionGapPx = compactLegend
|
|
81
|
+
? FLAPPY_NETWORK_LEGEND_COMPACT_SECTION_GAP_PX
|
|
82
|
+
: FLAPPY_NETWORK_LEGEND_REGULAR_SECTION_GAP_PX;
|
|
83
|
+
const legendHeightPx =
|
|
84
|
+
legendHeaderHeightPx +
|
|
85
|
+
legendSectionTitleHeightPx +
|
|
86
|
+
connectionLegendRows.length * legendRowHeightPx +
|
|
87
|
+
legendSectionGapPx +
|
|
88
|
+
legendSectionTitleHeightPx +
|
|
89
|
+
biasLegendRows.length * legendRowHeightPx +
|
|
90
|
+
FLAPPY_NETWORK_LEGEND_BOTTOM_PADDING_PX;
|
|
91
|
+
const legendMarginPx = FLAPPY_NETWORK_LEGEND_MARGIN_PX;
|
|
92
|
+
const preferTopLeft =
|
|
93
|
+
context.canvas.width < FLAPPY_NETWORK_LEGEND_TOP_LEFT_THRESHOLD_PX;
|
|
94
|
+
|
|
95
|
+
const maximumLeftPx = Math.max(
|
|
96
|
+
legendMarginPx,
|
|
97
|
+
context.canvas.width - legendWidthPx - legendMarginPx,
|
|
98
|
+
);
|
|
99
|
+
const legendLeftPx = preferTopLeft ? legendMarginPx : maximumLeftPx;
|
|
100
|
+
|
|
101
|
+
const maximumTopPx = Math.max(
|
|
102
|
+
legendMarginPx,
|
|
103
|
+
context.canvas.height - legendHeightPx - legendMarginPx,
|
|
104
|
+
);
|
|
105
|
+
const minimumTopPx = Math.min(FLAPPY_NETWORK_LEGEND_MIN_TOP_PX, maximumTopPx);
|
|
106
|
+
const legendTopPx = clamp(
|
|
107
|
+
FLAPPY_NETWORK_LEGEND_TARGET_TOP_PX,
|
|
108
|
+
minimumTopPx,
|
|
109
|
+
maximumTopPx,
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
return {
|
|
113
|
+
compactLegend,
|
|
114
|
+
legendLeftPx,
|
|
115
|
+
legendTopPx,
|
|
116
|
+
legendWidthPx,
|
|
117
|
+
legendHeightPx,
|
|
118
|
+
legendHeaderHeightPx,
|
|
119
|
+
legendSectionTitleHeightPx,
|
|
120
|
+
legendRowHeightPx,
|
|
121
|
+
legendSectionGapPx,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
4
124
|
|
|
5
125
|
/**
|
|
6
126
|
* Resolves default legend layout from internal tier definitions.
|
|
@@ -13,5 +133,20 @@ export function resolveDefaultNetworkLegendLayout(
|
|
|
13
133
|
context: CanvasRenderingContext2D,
|
|
14
134
|
network: Network | undefined,
|
|
15
135
|
): NetworkLegendLayout {
|
|
16
|
-
|
|
136
|
+
const colorScales = resolveNetworkVisualizationColorScales(network);
|
|
137
|
+
const connectionLegendRows = createColorLegendRows(
|
|
138
|
+
colorScales.connectionScale,
|
|
139
|
+
'w',
|
|
140
|
+
);
|
|
141
|
+
const biasLegendRows = createColorLegendRows(colorScales.biasScale, 'b');
|
|
142
|
+
return resolveNetworkLegendLayout(
|
|
143
|
+
context,
|
|
144
|
+
connectionLegendRows,
|
|
145
|
+
biasLegendRows,
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function formatLegendBound(value: number): string {
|
|
150
|
+
assertFiniteLegendBound(value);
|
|
151
|
+
return value.toFixed(2);
|
|
17
152
|
}
|
package/test/examples/flappy_bird/browser-entry/visualization/visualization.topology.utils.ts
CHANGED
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import type { VisualNetworkNodeLike } from '../browser-entry.types';
|
|
3
|
-
import {
|
|
4
|
-
formatNodeBiasLabelInternal,
|
|
5
|
-
resolveNetworkVisualizationLayersInternal,
|
|
6
|
-
} from '../browser-entry.visualization.utils';
|
|
1
|
+
export { resolveNetworkVisualizationLayers } from '../network-view/network-view.topology.utils';
|
|
7
2
|
|
|
8
3
|
/**
|
|
9
4
|
* Formats node bias labels with fixed sign and precision.
|
|
@@ -12,25 +7,6 @@ import {
|
|
|
12
7
|
* @returns Label text.
|
|
13
8
|
*/
|
|
14
9
|
export function formatNodeBiasLabel(nodeBias: number): string {
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Resolves layered node groups for visualization.
|
|
20
|
-
*
|
|
21
|
-
* @param network - Runtime network instance.
|
|
22
|
-
* @param inputSize - Input count fallback.
|
|
23
|
-
* @param outputSize - Output count fallback.
|
|
24
|
-
* @returns Layered nodes for rendering.
|
|
25
|
-
*/
|
|
26
|
-
export function resolveNetworkVisualizationLayers(
|
|
27
|
-
network: Network | undefined,
|
|
28
|
-
inputSize: number,
|
|
29
|
-
outputSize: number,
|
|
30
|
-
): VisualNetworkNodeLike[][] {
|
|
31
|
-
return resolveNetworkVisualizationLayersInternal(
|
|
32
|
-
network,
|
|
33
|
-
inputSize,
|
|
34
|
-
outputSize,
|
|
35
|
-
);
|
|
10
|
+
const roundedBias = Number.isFinite(nodeBias) ? nodeBias : 0;
|
|
11
|
+
return `${roundedBias >= 0 ? '+' : ''}${roundedBias.toFixed(2)}`;
|
|
36
12
|
}
|
|
@@ -1,23 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import type { VisualNetworkNodeLike } from '../browser-entry.types';
|
|
3
|
-
import { resolveNetworkVisualizationLayers as resolveNetworkVisualizationLayersFromTopology } from './visualization.topology.utils';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Public visualization entry for resolving layered network node groups.
|
|
7
|
-
*
|
|
8
|
-
* @param network - Runtime network instance.
|
|
9
|
-
* @param inputSize - Input count fallback.
|
|
10
|
-
* @param outputSize - Output count fallback.
|
|
11
|
-
* @returns Layered nodes for rendering.
|
|
12
|
-
*/
|
|
13
|
-
export function resolveNetworkVisualizationLayers(
|
|
14
|
-
network: Network | undefined,
|
|
15
|
-
inputSize: number,
|
|
16
|
-
outputSize: number,
|
|
17
|
-
): VisualNetworkNodeLike[][] {
|
|
18
|
-
return resolveNetworkVisualizationLayersFromTopology(
|
|
19
|
-
network,
|
|
20
|
-
inputSize,
|
|
21
|
-
outputSize,
|
|
22
|
-
);
|
|
23
|
-
}
|
|
1
|
+
export { resolveNetworkVisualizationLayers } from '../network-view/network-view.topology.utils';
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
# browser-entry/worker-channel
|
|
2
|
+
|
|
3
|
+
## browser-entry/worker-channel/worker-channel.types.ts
|
|
4
|
+
|
|
5
|
+
### WorkerChannelGenerationPayload
|
|
6
|
+
|
|
7
|
+
Aliases the generation payload contract returned by the worker.
|
|
8
|
+
|
|
9
|
+
### WorkerChannelMessage
|
|
10
|
+
|
|
11
|
+
Aliases the shared worker message union for worker-channel modules.
|
|
12
|
+
|
|
13
|
+
### WorkerChannelPlaybackStepPayload
|
|
14
|
+
|
|
15
|
+
Aliases the playback-step payload contract returned by the worker.
|
|
16
|
+
|
|
17
|
+
### WorkerChannelPlaybackStepRequest
|
|
18
|
+
|
|
19
|
+
Request payload sent when asking the worker to advance playback simulation.
|
|
20
|
+
|
|
21
|
+
## browser-entry/worker-channel/worker-channel.ts
|
|
22
|
+
|
|
23
|
+
### createEvolutionWorker
|
|
24
|
+
|
|
25
|
+
`() => Worker`
|
|
26
|
+
|
|
27
|
+
Creates the evolution worker used to keep heavy NEAT compute off the UI thread.
|
|
28
|
+
|
|
29
|
+
Returns: Initialized worker instance.
|
|
30
|
+
|
|
31
|
+
### requestWorkerGeneration
|
|
32
|
+
|
|
33
|
+
`(evolutionWorker: Worker) => Promise<import("test/examples/flappy_bird/browser-entry/browser-entry.worker.types").EvolutionGenerationPayload>`
|
|
34
|
+
|
|
35
|
+
Waits for the next generation payload emitted by the evolution worker.
|
|
36
|
+
|
|
37
|
+
Parameters:
|
|
38
|
+
|
|
39
|
+
- `evolutionWorker` - - Worker emitting generation-ready messages.
|
|
40
|
+
|
|
41
|
+
Returns: Next generation payload.
|
|
42
|
+
|
|
43
|
+
### requestWorkerPlaybackStep
|
|
44
|
+
|
|
45
|
+
`(evolutionWorker: Worker, playbackStepRequest: import("test/examples/flappy_bird/browser-entry/worker-channel/worker-channel.types").WorkerChannelPlaybackStepRequest) => Promise<{ snapshot: import("test/examples/flappy_bird/browser-entry/browser-entry.worker.types").EvolutionPlaybackStepSnapshot; instrumentation?: { activationCallsPerFrame: number; simulationStepsPerRaf: number; } | undefined; done: boolean; averagePipesPassed?: number | undefined; p90FramesSurvived?: number | undefined; winnerPipesPassed?: number | undefined; winnerFramesSurvived?: number | undefined; }>`
|
|
46
|
+
|
|
47
|
+
Requests one playback batch step from the worker.
|
|
48
|
+
|
|
49
|
+
Parameters:
|
|
50
|
+
|
|
51
|
+
- `evolutionWorker` - - Worker that owns playback simulation state.
|
|
52
|
+
- `playbackStepRequest` - - Requested simulation budget and viewport width.
|
|
53
|
+
|
|
54
|
+
Returns: Playback-step payload including snapshot and completion marker.
|
|
55
|
+
|
|
56
|
+
## browser-entry/worker-channel/worker-channel.errors.ts
|
|
57
|
+
|
|
58
|
+
### worker-channel.errors
|
|
59
|
+
|
|
60
|
+
Error raised when the evolution worker responds with an explicit protocol error payload.
|
|
61
|
+
|
|
62
|
+
### createWorkerChannelResponseError
|
|
63
|
+
|
|
64
|
+
`(message: string) => Error`
|
|
65
|
+
|
|
66
|
+
Converts worker protocol error payloads into typed worker-channel errors.
|
|
67
|
+
|
|
68
|
+
Parameters:
|
|
69
|
+
|
|
70
|
+
- `message` - - Message supplied by the worker error payload.
|
|
71
|
+
|
|
72
|
+
Returns: Typed worker-channel protocol error.
|
|
73
|
+
|
|
74
|
+
### resolveWorkerChannelRuntimeError
|
|
75
|
+
|
|
76
|
+
`(errorLike: unknown, fallbackMessage: string) => Error`
|
|
77
|
+
|
|
78
|
+
Resolves a worker `ErrorEvent` into a normalized `Error` instance.
|
|
79
|
+
|
|
80
|
+
Parameters:
|
|
81
|
+
|
|
82
|
+
- `errorLike` - - Optional `event.error` payload.
|
|
83
|
+
- `fallbackMessage` - - Fallback message from `event.message`.
|
|
84
|
+
|
|
85
|
+
Returns: Normalized runtime error.
|
|
86
|
+
|
|
87
|
+
### WorkerChannelResponseError
|
|
88
|
+
|
|
89
|
+
Error raised when the evolution worker responds with an explicit protocol error payload.
|
|
90
|
+
|
|
91
|
+
## browser-entry/worker-channel/worker-channel.url.service.ts
|
|
92
|
+
|
|
93
|
+
### worker-channel.url.service
|
|
94
|
+
|
|
95
|
+
Resolves the evolution worker bundle URL relative to the active browser-entry bundle.
|
|
96
|
+
|
|
97
|
+
@returns Absolute URL string for `flappy-evolution.worker.bundle.js`.
|
|
98
|
+
|
|
99
|
+
### resolveEvolutionWorkerBundleUrl
|
|
100
|
+
|
|
101
|
+
`() => string`
|
|
102
|
+
|
|
103
|
+
Resolves the evolution worker bundle URL relative to the active browser-entry bundle.
|
|
104
|
+
|
|
105
|
+
Returns: Absolute URL string for `flappy-evolution.worker.bundle.js`.
|
|
106
|
+
|
|
107
|
+
## browser-entry/worker-channel/worker-channel.request.service.ts
|
|
108
|
+
|
|
109
|
+
### requestWorkerResponse
|
|
110
|
+
|
|
111
|
+
`(options: import("test/examples/flappy_bird/browser-entry/worker-channel/worker-channel.request.service").WorkerChannelRequestOptions<ResponsePayload>) => Promise<ResponsePayload>`
|
|
112
|
+
|
|
113
|
+
Sends one request to the worker and resolves with the first matching response payload.
|
|
114
|
+
|
|
115
|
+
Parameters:
|
|
116
|
+
|
|
117
|
+
- `options` - - Worker request options and response resolver callback.
|
|
118
|
+
|
|
119
|
+
Returns: Promise resolving with the matched worker response payload.
|
|
120
|
+
|
|
121
|
+
### WorkerChannelRequestMessage
|
|
122
|
+
|
|
123
|
+
Message shape sent to the worker request channel.
|
|
124
|
+
|
|
125
|
+
### WorkerChannelRequestOptions
|
|
126
|
+
|
|
127
|
+
Configuration used for one worker request/response lifecycle.
|
|
128
|
+
|
|
129
|
+
## browser-entry/worker-channel/worker-channel.playback.service.ts
|
|
130
|
+
|
|
131
|
+
### requestWorkerPlaybackStep
|
|
132
|
+
|
|
133
|
+
`(evolutionWorker: Worker, playbackStepRequest: import("test/examples/flappy_bird/browser-entry/worker-channel/worker-channel.types").WorkerChannelPlaybackStepRequest) => Promise<{ snapshot: import("test/examples/flappy_bird/browser-entry/browser-entry.worker.types").EvolutionPlaybackStepSnapshot; instrumentation?: { activationCallsPerFrame: number; simulationStepsPerRaf: number; } | undefined; done: boolean; averagePipesPassed?: number | undefined; p90FramesSurvived?: number | undefined; winnerPipesPassed?: number | undefined; winnerFramesSurvived?: number | undefined; }>`
|
|
134
|
+
|
|
135
|
+
Requests one playback batch step from the worker channel.
|
|
136
|
+
|
|
137
|
+
Parameters:
|
|
138
|
+
|
|
139
|
+
- `evolutionWorker` - - Worker that owns playback simulation state.
|
|
140
|
+
- `playbackStepRequest` - - Requested simulation budget and viewport size.
|
|
141
|
+
|
|
142
|
+
Returns: Playback-step payload including snapshot and completion marker.
|
|
143
|
+
|
|
144
|
+
## browser-entry/worker-channel/worker-channel.generation.service.ts
|
|
145
|
+
|
|
146
|
+
### requestWorkerGeneration
|
|
147
|
+
|
|
148
|
+
`(evolutionWorker: Worker) => Promise<import("test/examples/flappy_bird/browser-entry/browser-entry.worker.types").EvolutionGenerationPayload>`
|
|
149
|
+
|
|
150
|
+
Requests the next evolved generation payload from the worker channel.
|
|
151
|
+
|
|
152
|
+
Parameters:
|
|
153
|
+
|
|
154
|
+
- `evolutionWorker` - - Worker emitting generation-ready messages.
|
|
155
|
+
|
|
156
|
+
Returns: Next generation payload.
|