@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,7 +1,48 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Shared ASCII Maze contracts plus compatibility re-exports for the Step 5 type split.
|
|
3
|
+
*
|
|
4
|
+
* The ownership of run/configuration contracts now lives in `evolutionEngine/`
|
|
5
|
+
* and fitness evaluation contracts now live in `fitness.types.ts`. This file
|
|
6
|
+
* intentionally keeps only the genuinely cross-cutting network, result, and
|
|
7
|
+
* terminal-oriented shapes while re-exporting the moved contracts to preserve
|
|
8
|
+
* the established public import surface.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type { NeatInstance } from './evolutionEngine/evolutionEngine.types';
|
|
12
|
+
|
|
13
|
+
export type {
|
|
14
|
+
DistanceMap,
|
|
15
|
+
EncodedMaze,
|
|
16
|
+
EncodedMazeData,
|
|
17
|
+
EvolutionHelpers,
|
|
18
|
+
EvolutionLoopHelpers,
|
|
19
|
+
EvolutionOptions,
|
|
20
|
+
FileSystem,
|
|
21
|
+
IAgentSimulationConfig,
|
|
22
|
+
IEvolutionAlgorithmConfig,
|
|
23
|
+
IMazeConfig,
|
|
24
|
+
IReportingConfig,
|
|
25
|
+
IRunMazeEvolutionOptions,
|
|
26
|
+
LogitsRingState,
|
|
27
|
+
LoopHelpers,
|
|
28
|
+
MazeDistanceMap,
|
|
29
|
+
MazePosition,
|
|
30
|
+
NeatInstance,
|
|
31
|
+
NetworkConnection,
|
|
32
|
+
NetworkInstance,
|
|
33
|
+
NetworkNode,
|
|
34
|
+
PathModule,
|
|
35
|
+
Position,
|
|
36
|
+
ProfilingAccumulators,
|
|
37
|
+
ScratchBundle,
|
|
38
|
+
SimulationResult,
|
|
39
|
+
SnapshotEntry,
|
|
40
|
+
TrainingConstants,
|
|
41
|
+
} from './evolutionEngine/evolutionEngine.types';
|
|
42
|
+
export type {
|
|
43
|
+
FitnessEvaluatorFn,
|
|
44
|
+
IFitnessEvaluationContext,
|
|
45
|
+
} from './fitness.types';
|
|
5
46
|
|
|
6
47
|
/**
|
|
7
48
|
* Interface for dashboard manager abstraction.
|
|
@@ -11,153 +52,29 @@ export interface IDashboardManager {
|
|
|
11
52
|
/**
|
|
12
53
|
* Update the dashboard with the latest simulation/evolution state.
|
|
13
54
|
*
|
|
14
|
-
* Callers:
|
|
15
|
-
* - Evolution loop: supplies a snapshot after each generation or on important
|
|
16
|
-
* events (e.g., when a solution is found).
|
|
17
|
-
*
|
|
18
|
-
* Responsibilities:
|
|
19
|
-
* 1. Present a human-readable maze layout (maze array) and agent outcome.
|
|
20
|
-
* 2. Optionally visualise or serialize the supplied network structure.
|
|
21
|
-
* 3. Optionally use neatInstance for richer telemetry (population stats,
|
|
22
|
-
* training snapshots), but implementations should not mutate neatInstance.
|
|
23
|
-
*
|
|
24
55
|
* @param maze - The current maze layout represented as an array of ASCII strings.
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
* @param
|
|
28
|
-
*
|
|
29
|
-
* should treat this as read-only.
|
|
30
|
-
* @param network - The network instance used for the run. Implementations may
|
|
31
|
-
* inspect its nodes/connections for visualization but must
|
|
32
|
-
* not assume any concrete runtime shape beyond the INetwork
|
|
33
|
-
* interface.
|
|
34
|
-
* @param generation - The current generation number (0-based or 1-based as
|
|
35
|
-
* used by the caller). Display purposes only.
|
|
36
|
-
* @param neatInstance - Optional reference to the overall evolutionary engine
|
|
37
|
-
* instance (may be undefined in headless modes). Use for
|
|
38
|
-
* advanced telemetry only; do not mutate the engine.
|
|
39
|
-
* @returns void
|
|
40
|
-
*
|
|
41
|
-
* Notes:
|
|
42
|
-
* - Implementations should avoid heavy synchronous work: if rendering is
|
|
43
|
-
* expensive consider batching or yielding (requestAnimationFrame) in UI contexts.
|
|
44
|
-
* - For tests, a minimal implementation is a no-op or a simple recorder:
|
|
45
|
-
* { lastUpdate: null, update(maze, result, network, generation) { this.lastUpdate = {maze,result,network,generation} } }
|
|
56
|
+
* @param result - Result object produced by the agent run.
|
|
57
|
+
* @param network - The network instance used for the run.
|
|
58
|
+
* @param generation - The current generation number.
|
|
59
|
+
* @param neatInstance - Optional NEAT instance for advanced telemetry display.
|
|
46
60
|
*/
|
|
47
61
|
update(
|
|
48
62
|
maze: string[],
|
|
49
63
|
result: IMazeRunResult | undefined,
|
|
50
64
|
network: INetwork | null,
|
|
51
65
|
generation: number,
|
|
52
|
-
neatInstance?: NeatInstance,
|
|
66
|
+
neatInstance?: NeatInstance,
|
|
53
67
|
): void;
|
|
54
68
|
|
|
55
|
-
/** Optional log function for dashboard messages */
|
|
69
|
+
/** Optional log function for dashboard messages. */
|
|
56
70
|
logFunction?: (msg: string) => void;
|
|
57
71
|
|
|
58
|
-
/** Allow additional properties for extensibility */
|
|
72
|
+
/** Allow additional properties for extensibility. */
|
|
59
73
|
[key: string]: unknown;
|
|
60
74
|
}
|
|
61
75
|
|
|
62
76
|
/**
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
* Purpose
|
|
66
|
-
* - Provide a minimal, serialisable description of a 2D maze suitable for
|
|
67
|
-
* human-editable examples, automated tests, and demo pages.
|
|
68
|
-
*
|
|
69
|
-
* Semantics
|
|
70
|
-
* - The maze is represented as an array of strings; each string is one row.
|
|
71
|
-
* - All strings should have the same length (rows aligned). Rows are read from
|
|
72
|
-
* top (index 0) to bottom (last index).
|
|
73
|
-
* - Typical characters used by examples:
|
|
74
|
-
* - '#' or 'X' : wall / obstacle
|
|
75
|
-
* - ' ' (space) or '.' : open floor
|
|
76
|
-
* - 'S' : start position (first occurrence often used)
|
|
77
|
-
* - 'E' or 'X' : exit / goal (first occurrence used)
|
|
78
|
-
* - other characters may be interpreted by custom fitness evaluators
|
|
79
|
-
*
|
|
80
|
-
* Validation notes
|
|
81
|
-
* - Implementations should validate row length consistency and presence of a
|
|
82
|
-
* start/exit pair when running experiments that require them.
|
|
83
|
-
* - For headless tests, a minimal maze can be a 1×N/ N×1 open corridor.
|
|
84
|
-
*
|
|
85
|
-
* Example
|
|
86
|
-
* const sample: IMazeConfig = {
|
|
87
|
-
* maze: [
|
|
88
|
-
* "#########",
|
|
89
|
-
* "#S . E#",
|
|
90
|
-
* "# # #",
|
|
91
|
-
* "#########"
|
|
92
|
-
* ]
|
|
93
|
-
* };
|
|
94
|
-
*
|
|
95
|
-
* @remarks
|
|
96
|
-
* - This shape intentionally remains small and textual so learners can edit
|
|
97
|
-
* mazes inline in examples and tests without needing binary formats.
|
|
98
|
-
*/
|
|
99
|
-
export interface IMazeConfig {
|
|
100
|
-
/**
|
|
101
|
-
* The maze layout, each element is a row string. Rows should be equal length.
|
|
102
|
-
*
|
|
103
|
-
* @example
|
|
104
|
-
* ["#####",
|
|
105
|
-
* "#S E#",
|
|
106
|
-
* "#####"]
|
|
107
|
-
*/
|
|
108
|
-
maze: string[];
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* Agent simulation configuration.
|
|
113
|
-
*
|
|
114
|
-
* Purpose
|
|
115
|
-
* - Configure per-episode simulation parameters used by the maze runner and
|
|
116
|
-
* fitness evaluators. This small surface lets examples/tests control episode
|
|
117
|
-
* length, determinism, and other runtime constraints without modifying the
|
|
118
|
-
* simulation engine.
|
|
119
|
-
*
|
|
120
|
-
* Semantics
|
|
121
|
-
* - Settings apply to a single agent episode/run (not global evolution state).
|
|
122
|
-
* - Runners should honour these values deterministically when possible so tests
|
|
123
|
-
* remain reproducible.
|
|
124
|
-
*
|
|
125
|
-
* Typical usage
|
|
126
|
-
* - For short smoke tests use small maxSteps (e.g. 50).
|
|
127
|
-
* - For harder mazes or thorough evaluation increase maxSteps to allow longer
|
|
128
|
-
* trajectories before timing out (e.g. 500–2000).
|
|
129
|
-
*
|
|
130
|
-
* Example
|
|
131
|
-
* const simCfg: IAgentSimulationConfig = { maxSteps: 200 };
|
|
132
|
-
*
|
|
133
|
-
* @remarks
|
|
134
|
-
* - Implementations may provide additional optional fields later (e.g. stepTimeout,
|
|
135
|
-
* deterministicActionNoise) but this interface focuses on the minimal set
|
|
136
|
-
* required by educational examples.
|
|
137
|
-
*/
|
|
138
|
-
export interface IAgentSimulationConfig {
|
|
139
|
-
/**
|
|
140
|
-
* Maximum number of discrete steps the agent is allowed to take in a single
|
|
141
|
-
* episode before the runner terminates the simulation and returns a timeout
|
|
142
|
-
* / failure result.
|
|
143
|
-
*
|
|
144
|
-
* Runners should:
|
|
145
|
-
* 1. Count only environment steps that change agent state (do not double-count internal bookkeeping).
|
|
146
|
-
* 2. Terminate the episode when this limit is reached and report progress/fitness.
|
|
147
|
-
*
|
|
148
|
-
* @example
|
|
149
|
-
* // allow up to 500 steps for a difficult maze
|
|
150
|
-
* { maxSteps: 500 }
|
|
151
|
-
*/
|
|
152
|
-
maxSteps: number;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* Result structure returned by the maze simulation/evolution helpers.
|
|
157
|
-
*
|
|
158
|
-
* Contains the key telemetry fields consumed by dashboards, visualisers and
|
|
159
|
-
* fitness evaluators while remaining permissive via an index signature for
|
|
160
|
-
* additional diagnostics.
|
|
77
|
+
* Result structure returned by the maze simulation and evolution helpers.
|
|
161
78
|
*/
|
|
162
79
|
export interface IMazeRunResult {
|
|
163
80
|
/** Whether the agent solved the maze during this run. */
|
|
@@ -166,7 +83,7 @@ export interface IMazeRunResult {
|
|
|
166
83
|
steps: number;
|
|
167
84
|
/** Materialised path as [x, y] coordinates visited sequentially. */
|
|
168
85
|
path: Array<[number, number]>;
|
|
169
|
-
/** Scalar fitness assigned to the run
|
|
86
|
+
/** Scalar fitness assigned to the run. */
|
|
170
87
|
fitness: number;
|
|
171
88
|
/** Progress metric (usually 0-100) representing completion percentage. */
|
|
172
89
|
progress: number;
|
|
@@ -181,661 +98,50 @@ export interface IMazeRunResult {
|
|
|
181
98
|
}
|
|
182
99
|
|
|
183
100
|
/**
|
|
184
|
-
*
|
|
185
|
-
*
|
|
186
|
-
* Purpose
|
|
187
|
-
* - Collect tunable parameters that control population, stopping criteria,
|
|
188
|
-
* optional refinement phases, telemetry, and persistence. This object is
|
|
189
|
-
* passed to the evolution runner so examples, demos and tests can customise
|
|
190
|
-
* behaviour without touching algorithm code.
|
|
191
|
-
*
|
|
192
|
-
* Design notes
|
|
193
|
-
* - Keep sensible defaults in the runner; consumers should override only the
|
|
194
|
-
* values they need for experiments.
|
|
195
|
-
* - Booleans toggle optional features (Baldwinian/Lamarckian refinements,
|
|
196
|
-
* deterministic RNG, telemetry), numeric options tune population/termination.
|
|
197
|
-
*
|
|
198
|
-
* Typical workflow
|
|
199
|
-
* 1. For quick experiments use small popSize (e.g. 50) and low maxGenerations (e.g. 200).
|
|
200
|
-
* 2. For reproducible comparisons set randomSeed and deterministic=true.
|
|
201
|
-
* 3. Enable persistEvery/persistTopK to snapshot progress for later analysis.
|
|
202
|
-
*
|
|
203
|
-
* Example
|
|
204
|
-
* const cfg: IEvolutionAlgorithmConfig = {
|
|
205
|
-
* popSize: 150,
|
|
206
|
-
* allowRecurrent: true,
|
|
207
|
-
* lamarckianIterations: 10,
|
|
208
|
-
* deterministic: true,
|
|
209
|
-
* persistEvery: 50,
|
|
210
|
-
* maxGenerations: 1000
|
|
211
|
-
* };
|
|
212
|
-
*
|
|
213
|
-
* @remarks
|
|
214
|
-
* - This interface is intentionally descriptive to help learners understand
|
|
215
|
-
* what each toggle means and to encourage reproducible experiments.
|
|
216
|
-
*/
|
|
217
|
-
export interface IEvolutionAlgorithmConfig {
|
|
218
|
-
/** Allow recurrent connections in genomes (networks may be stateful). */
|
|
219
|
-
allowRecurrent?: boolean;
|
|
220
|
-
/** Population size used each generation. Larger values increase search breadth but cost CPU. */
|
|
221
|
-
popSize?: number;
|
|
222
|
-
/** Maximum number of generations without improvement before considering stagnation. */
|
|
223
|
-
maxStagnantGenerations?: number;
|
|
224
|
-
/** Minimum measurable progress (fitness delta) required to count as improvement. */
|
|
225
|
-
minProgressToPass?: number;
|
|
226
|
-
/** Safety cap on total generations. Set to limit wall-clock runs in demos/tests. */
|
|
227
|
-
maxGenerations?: number;
|
|
228
|
-
/**
|
|
229
|
-
* If true, ignore stagnation/generation caps and only stop when the agent
|
|
230
|
-
* actually solves the maze (success flag true and progress threshold met).
|
|
231
|
-
*/
|
|
232
|
-
stopOnlyOnSolve?: boolean;
|
|
233
|
-
/**
|
|
234
|
-
* If true (default historically), the engine sets window.asciiMazePaused=true
|
|
235
|
-
* after a solution is found. Browser demos may disable this to continue runs.
|
|
236
|
-
*/
|
|
237
|
-
autoPauseOnSolve?: boolean;
|
|
238
|
-
/** Optional numeric seed for RNG. Use with deterministic=true for reproducible runs. */
|
|
239
|
-
randomSeed?: number;
|
|
240
|
-
/** Optionally provide an initial population of networks instead of random seeding. */
|
|
241
|
-
initialPopulation?: INetwork[];
|
|
242
|
-
/** Optionally supply a known-good starting network (copied/cloned by the engine). */
|
|
243
|
-
initialBestNetwork?: INetwork | Network;
|
|
244
|
-
/** Per-individual local refinement iterations (Baldwinian/Lamarckian style). */
|
|
245
|
-
lamarckianIterations?: number;
|
|
246
|
-
/** Subsample size used for refinement training patterns to speed up Lamarckian steps. */
|
|
247
|
-
lamarckianSampleSize?: number;
|
|
248
|
-
// Adaptive simplify/pruning phase triggers
|
|
249
|
-
/** Generations of low improvement that trigger simplify/prune mode. */
|
|
250
|
-
plateauGenerations?: number;
|
|
251
|
-
/** Minimum fitness delta to consider a generation an improvement (default ~1e-6). */
|
|
252
|
-
plateauImprovementThreshold?: number;
|
|
253
|
-
/** Number of generations to remain in simplify/prune mode once triggered. */
|
|
254
|
-
simplifyDuration?: number;
|
|
255
|
-
/**
|
|
256
|
-
* Fraction (0-1) of the weakest connections to prune each simplify generation.
|
|
257
|
-
* Use small values (0.01–0.1) to avoid destabilising behaviour.
|
|
258
|
-
*/
|
|
259
|
-
simplifyPruneFraction?: number;
|
|
260
|
-
/** Pruning heuristic: 'weakWeight' or prefer pruning recurrent links first. */
|
|
261
|
-
simplifyStrategy?: 'weakWeight' | 'weakRecurrentPreferred';
|
|
262
|
-
// Persistence
|
|
263
|
-
/** Save a snapshot every N generations (set to undefined to disable). */
|
|
264
|
-
persistEvery?: number;
|
|
265
|
-
/** Directory path where snapshots will be saved (demo/runtime provided). */
|
|
266
|
-
persistDir?: string;
|
|
267
|
-
/** Number of top genomes to persist when saving snapshots. */
|
|
268
|
-
persistTopK?: number;
|
|
269
|
-
// Dynamic population growth controls
|
|
270
|
-
/** If true, allow the engine to expand population size dynamically on plateaus. */
|
|
271
|
-
dynamicPopEnabled?: boolean;
|
|
272
|
-
/** Upper bound for dynamically expanded population. */
|
|
273
|
-
dynamicPopMax?: number;
|
|
274
|
-
/** Interval (generations) between population expansion events when enabled. */
|
|
275
|
-
dynamicPopExpandInterval?: number;
|
|
276
|
-
/** Multiplicative factor to expand the population when a growth event occurs. */
|
|
277
|
-
dynamicPopExpandFactor?: number;
|
|
278
|
-
/** Slack (fitness) tolerance used to decide when plateau-driven expansion should kick in. */
|
|
279
|
-
dynamicPopPlateauSlack?: number;
|
|
280
|
-
/**
|
|
281
|
-
* If true, enables deterministic RNG seeding. If randomSeed is omitted a fixed
|
|
282
|
-
* fallback seed will be used so runs are reproducible.
|
|
283
|
-
*/
|
|
284
|
-
deterministic?: boolean;
|
|
285
|
-
/**
|
|
286
|
-
* Optional generation interval to trigger memory compaction (removal of
|
|
287
|
-
* disabled connections). Default value is handled by the engine.
|
|
288
|
-
*/
|
|
289
|
-
memoryCompactionInterval?: number;
|
|
290
|
-
/** If true, reduce telemetry math to lower CPU usage (skip kurtosis, higher moments). */
|
|
291
|
-
telemetryReduceStats?: boolean;
|
|
292
|
-
/** If true, disable higher-cost per-generation telemetry (entropy, diversity, etc.). */
|
|
293
|
-
telemetryMinimal?: boolean;
|
|
294
|
-
/** If true, skip Baldwinian refinement phase (extra training on the fittest). */
|
|
295
|
-
disableBaldwinianRefinement?: boolean;
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
/**
|
|
299
|
-
* Context passed to a fitness evaluator when scoring a network on a maze.
|
|
300
|
-
*
|
|
301
|
-
* Purpose
|
|
302
|
-
* - Provide all derived and raw information needed to deterministically evaluate
|
|
303
|
-
* a single agent episode in a maze so fitness functions can be simple and
|
|
304
|
-
* focused (no hidden IO or global state required).
|
|
305
|
-
*
|
|
306
|
-
* Semantics & conventions
|
|
307
|
-
* - Coordinate system: row-major arrays with origin at the top-left of the maze.
|
|
308
|
-
* Positions are expressed as a readonly tuple [rowIndex, colIndex] where both
|
|
309
|
-
* indices are zero-based.
|
|
310
|
-
* - Encodings: the numeric encoding of cells (encodedMaze) is intentionally
|
|
311
|
-
* engine-specific. Common encoders map open floor to 0 and walls/obstacles to 1,
|
|
312
|
-
* but evaluators must consult the caller's encoder or accept common defaults.
|
|
313
|
-
* - Determinism: values in this context should not be mutated by evaluators.
|
|
314
|
-
*
|
|
315
|
-
* Typical responsibilities of a fitness evaluator using this context
|
|
316
|
-
* 1. Use encodedMaze and distanceMap (when present) to compute heuristics such as
|
|
317
|
-
* distance-to-goal, reachable area, or dead-ends.
|
|
318
|
-
* 2. Simulate or replay agent steps (using agentSimConfig limits) and combine
|
|
319
|
-
* behavioural metrics into a single scalar fitness score.
|
|
320
|
-
* 3. Prefer read-only access; when caching is required produce ephemeral copies.
|
|
321
|
-
*
|
|
322
|
-
* @example
|
|
323
|
-
* // Example shape of a simple context:
|
|
324
|
-
* const ctx: IFitnessEvaluationContext = {
|
|
325
|
-
* encodedMaze: [
|
|
326
|
-
* [1,1,1,1,1],
|
|
327
|
-
* [1,0,0,0,1],
|
|
328
|
-
* [1,0,1,0,1],
|
|
329
|
-
* [1,0,0,2,1],
|
|
330
|
-
* [1,1,1,1,1]
|
|
331
|
-
* ],
|
|
332
|
-
* startPosition: [1,1],
|
|
333
|
-
* exitPosition: [3,3],
|
|
334
|
-
* agentSimConfig: { maxSteps: 200 },
|
|
335
|
-
* // distanceMap optional: same dimensions as encodedMaze; distance in steps to exit
|
|
336
|
-
* };
|
|
337
|
-
*
|
|
338
|
-
* @remarks
|
|
339
|
-
* - This interface is tailored for educational examples: keep data small and
|
|
340
|
-
* explicit so learners can inspect values while debugging fitness functions.
|
|
341
|
-
*/
|
|
342
|
-
export interface IFitnessEvaluationContext {
|
|
343
|
-
/**
|
|
344
|
-
* Row-major numeric representation of the maze.
|
|
345
|
-
*
|
|
346
|
-
* - Shape: encodedMaze.length === number of rows; encodedMaze[0].length === number of columns.
|
|
347
|
-
* - Cell codes: encoding is chosen by the maze encoder. Common conventions:
|
|
348
|
-
* - 0: open/traversable
|
|
349
|
-
* - 1: wall/obstacle
|
|
350
|
-
* - 2: goal/exit (optional if exitPosition is provided separately)
|
|
351
|
-
*
|
|
352
|
-
* Use-case tips:
|
|
353
|
-
* - Iteration order is [row][col] (y, x). When mapping to x/y visuals swap indices as needed.
|
|
354
|
-
*/
|
|
355
|
-
encodedMaze: number[][];
|
|
356
|
-
|
|
357
|
-
/**
|
|
358
|
-
* Start position for the agent as a readonly tuple [rowIndex, colIndex].
|
|
359
|
-
*
|
|
360
|
-
* - First element: row (0 = top).
|
|
361
|
-
* - Second element: column (0 = left).
|
|
362
|
-
*
|
|
363
|
-
* Example: [2, 4] means third row, fifth column.
|
|
364
|
-
*/
|
|
365
|
-
startPosition: readonly [number, number];
|
|
366
|
-
|
|
367
|
-
/**
|
|
368
|
-
* Exit/goal position for the episode as a readonly tuple [rowIndex, colIndex].
|
|
369
|
-
*
|
|
370
|
-
* - Evaluators commonly compute Manhattan or shortest-path distance between
|
|
371
|
-
* the agent and this coordinate when deriving progress-based fitness.
|
|
372
|
-
*/
|
|
373
|
-
exitPosition: readonly [number, number];
|
|
374
|
-
|
|
375
|
-
/**
|
|
376
|
-
* Simulation controls for a single agent episode.
|
|
377
|
-
*
|
|
378
|
-
* - Provides deterministic limits such as maxSteps so evaluators and runners
|
|
379
|
-
* behave reproducibly in tests and examples.
|
|
380
|
-
* - Evaluators should respect maxSteps when simulating trajectories.
|
|
381
|
-
*/
|
|
382
|
-
agentSimConfig: IAgentSimulationConfig;
|
|
383
|
-
|
|
384
|
-
/**
|
|
385
|
-
* Optional cached distance map (same dimensions as encodedMaze).
|
|
386
|
-
*
|
|
387
|
-
* - Typical content: non-negative step counts indicating the shortest-path
|
|
388
|
-
* distance from each cell to the exitPosition. Unreachable cells may be
|
|
389
|
-
* represented by Infinity or a large sentinel value.
|
|
390
|
-
* - Purpose: supply fast heuristics (e.g., progress-to-goal) without recomputing
|
|
391
|
-
* an expensive BFS on every fitness evaluation. Consumers must treat this
|
|
392
|
-
* as read-only.
|
|
393
|
-
*
|
|
394
|
-
* Example usage:
|
|
395
|
-
* const dist = context.distanceMap?.[agentRow]?.[agentCol] ?? Infinity;
|
|
396
|
-
*/
|
|
397
|
-
distanceMap?: number[][]; // optional cached distance map for performance
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
/**
|
|
401
|
-
* Signature for a fitness evaluator used to score a network on a single maze episode.
|
|
402
|
-
*
|
|
403
|
-
* Purpose
|
|
404
|
-
* - Provide a deterministic, side-effect-free function that maps a network's
|
|
405
|
-
* behaviour (when run in a given environment context) to a single numeric
|
|
406
|
-
* fitness value used by evolutionary algorithms.
|
|
407
|
-
*
|
|
408
|
-
* Responsibilities & conventions
|
|
409
|
-
* 1. Determinism: for the same `network` state and `context` inputs the function
|
|
410
|
-
* should return the same numeric score. If stochasticity is needed, it must
|
|
411
|
-
* be driven by values inside `context` (so tests/experiments can reproduce runs).
|
|
412
|
-
* 2. Read-only: evaluators must not mutate `network` or `context`. If temporary
|
|
413
|
-
* changes are required (e.g. calling `network.clear()`), operate on a clone
|
|
414
|
-
* or ensure the original is restored before returning.
|
|
415
|
-
* 3. Scalar meaning: higher numbers typically denote better performance unless
|
|
416
|
-
* the caller documents otherwise. The evaluator should document its range
|
|
417
|
-
* and interpretation (e.g., [0..1], arbitrary positive rewards, penalties).
|
|
418
|
-
*
|
|
419
|
-
* Implementation tips
|
|
420
|
-
* - Use `context.distanceMap` when available to compute progress-to-goal quickly.
|
|
421
|
-
* - Combine multiple signals (distance-to-goal, steps-used, collisions) into a
|
|
422
|
-
* single scalar using a consistent weighting scheme and document it.
|
|
423
|
-
* - Keep fitness values numerically stable (avoid huge magnitudes) so aggregation
|
|
424
|
-
* statistics remain meaningful to telemetry code.
|
|
425
|
-
*
|
|
426
|
-
* @returns {number} A finite numeric fitness score. By default larger values indicate better performance;
|
|
427
|
-
* concrete evaluators should document score range and interpretation.
|
|
428
|
-
*
|
|
429
|
-
* @example
|
|
430
|
-
* // Minimal evaluator structure:
|
|
431
|
-
* const evaluator: FitnessEvaluatorFn = (network, context) => {
|
|
432
|
-
* // 1) use context to build inputs
|
|
433
|
-
* // 2) run network.activate(inputs) to get actions
|
|
434
|
-
* // 3) simulate agent up to context.agentSimConfig.maxSteps
|
|
435
|
-
* // 4) compute and return a single numeric score
|
|
436
|
-
* return 0; // replace with real computation
|
|
437
|
-
* };
|
|
438
|
-
*/
|
|
439
|
-
export type FitnessEvaluatorFn = (
|
|
440
|
-
/** Read-only episode context (see IFitnessEvaluationContext). */
|
|
441
|
-
network: INetwork,
|
|
442
|
-
/**
|
|
443
|
-
* The candidate network to evaluate.
|
|
444
|
-
* Expected contract:
|
|
445
|
-
* - Call network.activate(inputs) for inference; do not assume concrete internals.
|
|
446
|
-
* - Optional helpers: network.clear(), network.clone(), network.propagate() may exist --
|
|
447
|
-
* if used, operate on a clone or restore state to avoid mutating the original.
|
|
448
|
-
*/
|
|
449
|
-
context: IFitnessEvaluationContext,
|
|
450
|
-
) => number;
|
|
451
|
-
|
|
452
|
-
/**
|
|
453
|
-
* Reporting configuration used to control logging, dashboard updates and UI pacing
|
|
454
|
-
* for an evolution run.
|
|
455
|
-
*
|
|
456
|
-
* Purpose:
|
|
457
|
-
* - Give experiment authors a small, well-documented surface to control
|
|
458
|
-
* telemetry frequency, the dashboard implementation and an optional label
|
|
459
|
-
* so runs can be identified in logs or persisted snapshots.
|
|
460
|
-
*
|
|
461
|
-
* Design notes:
|
|
462
|
-
* - Documentation is intentionally explicit so IDEs (VSCode) surface property
|
|
463
|
-
* descriptions inline while composing experiments, helping learners understand
|
|
464
|
-
* intent without reading library source.
|
|
465
|
-
*
|
|
466
|
-
* @example
|
|
467
|
-
* const reporting: IReportingConfig = {
|
|
468
|
-
* logEvery: 10,
|
|
469
|
-
* dashboardManager: myDashboard,
|
|
470
|
-
* label: "small-experiment",
|
|
471
|
-
* paceEveryGeneration: true
|
|
472
|
-
* };
|
|
473
|
-
*/
|
|
474
|
-
export interface IReportingConfig {
|
|
475
|
-
/**
|
|
476
|
-
* How frequently (in generations) to emit logs or telemetry updates.
|
|
477
|
-
*
|
|
478
|
-
* Behaviour:
|
|
479
|
-
* - If undefined, the runner may fall back to a sensible default (for example: 1).
|
|
480
|
-
* - When set to N > 0 the runner should produce a log/telemetry entry every Nth generation.
|
|
481
|
-
*
|
|
482
|
-
* @example
|
|
483
|
-
* // Log every 5 generations
|
|
484
|
-
* { logEvery: 5 }
|
|
485
|
-
*/
|
|
486
|
-
logEvery?: number;
|
|
487
|
-
|
|
488
|
-
/**
|
|
489
|
-
* Dashboard manager instance responsible for receiving per-generation updates.
|
|
490
|
-
*
|
|
491
|
-
* Responsibilities of implementations:
|
|
492
|
-
* 1. Display a human-readable maze and the agent result snapshot.
|
|
493
|
-
* 2. Optionally visualise or serialize the network structure (read-only).
|
|
494
|
-
* 3. Avoid mutating the supplied objects and avoid expensive synchronous work.
|
|
495
|
-
*
|
|
496
|
-
* The runner will call `dashboardManager.update(maze, result, network, generation, neatInstance?)`
|
|
497
|
-
* with a snapshot for presentation or recording.
|
|
498
|
-
*/
|
|
499
|
-
dashboardManager: IDashboardManager;
|
|
500
|
-
|
|
501
|
-
/**
|
|
502
|
-
* Optional human-readable label identifying this run in logs, snapshot files
|
|
503
|
-
* and UI elements.
|
|
504
|
-
*
|
|
505
|
-
* Use-cases:
|
|
506
|
-
* - Distinguish runs when persisting multiple experiments to the same directory.
|
|
507
|
-
* - Tag telemetry streams for easier filtering in dashboards.
|
|
508
|
-
*
|
|
509
|
-
* @example
|
|
510
|
-
* { label: "pop150_seed42" }
|
|
511
|
-
*/
|
|
512
|
-
label?: string;
|
|
513
|
-
|
|
514
|
-
/**
|
|
515
|
-
* When true, the evolution loop yields control to the browser after each
|
|
516
|
-
* generation (for example via requestAnimationFrame) to keep the UI
|
|
517
|
-
* responsive during long-running experiments.
|
|
518
|
-
*
|
|
519
|
-
* Notes:
|
|
520
|
-
* - Default may be false in headless or CI environments.
|
|
521
|
-
* - Enabling this will affect wall-clock timing of runs and should be used
|
|
522
|
-
* primarily for interactive demos.
|
|
523
|
-
*/
|
|
524
|
-
paceEveryGeneration?: boolean;
|
|
525
|
-
}
|
|
526
|
-
|
|
527
|
-
/**
|
|
528
|
-
* Main options for running a single maze-evolution experiment.
|
|
529
|
-
*
|
|
530
|
-
* Purpose:
|
|
531
|
-
* - Aggregate all tunable inputs required to configure one run of the ASCII
|
|
532
|
-
* maze evolutionary system (maze, simulation limits, algorithm hyper-parameters,
|
|
533
|
-
* reporting and optional evaluator hooks).
|
|
534
|
-
*
|
|
535
|
-
* Design notes:
|
|
536
|
-
* - This object is intentionally explicit and documented so learners can adjust
|
|
537
|
-
* experiments from examples or IDE autocompletion without reading implementation code.
|
|
538
|
-
* - Fields that are optional may be left undefined to use sensible defaults provided by the runner.
|
|
539
|
-
*
|
|
540
|
-
* Example:
|
|
541
|
-
* const opts: IRunMazeEvolutionOptions = {
|
|
542
|
-
* mazeConfig: { maze: ["#####", "#S E#", "#####"] },
|
|
543
|
-
* agentSimConfig: { maxSteps: 200 },
|
|
544
|
-
* evolutionAlgorithmConfig: { popSize: 100, maxGenerations: 500, deterministic: true },
|
|
545
|
-
* reportingConfig: { logEvery: 5, dashboardManager: myDashboard, paceEveryGeneration: true },
|
|
546
|
-
* fitnessEvaluator: myEvaluator,
|
|
547
|
-
* cancellation: { isCancelled: () => false }
|
|
548
|
-
* };
|
|
549
|
-
*/
|
|
550
|
-
export interface IRunMazeEvolutionOptions {
|
|
551
|
-
/**
|
|
552
|
-
* Minimal, human-editable maze definition used for the experiment.
|
|
553
|
-
*
|
|
554
|
-
* - Provides the ASCII layout used for every episode/evaluation in the run.
|
|
555
|
-
* - Runners should validate row lengths and presence of start/exit when required.
|
|
556
|
-
*/
|
|
557
|
-
mazeConfig: IMazeConfig;
|
|
558
|
-
|
|
559
|
-
/**
|
|
560
|
-
* Per-episode simulation controls.
|
|
561
|
-
*
|
|
562
|
-
* - Controls deterministic limits such as maxSteps so single-episode behaviour
|
|
563
|
-
* is reproducible for tests and examples.
|
|
564
|
-
* - The runner must honour these limits when simulating agents for fitness evaluation.
|
|
565
|
-
*/
|
|
566
|
-
agentSimConfig: IAgentSimulationConfig;
|
|
567
|
-
|
|
568
|
-
/**
|
|
569
|
-
* All tunable hyper-parameters and behavioural flags for the evolutionary algorithm.
|
|
570
|
-
*
|
|
571
|
-
* - Controls population size, stopping criteria, determinism, refinement iterations,
|
|
572
|
-
* persistence settings and other algorithm-level options.
|
|
573
|
-
* - Use the runner defaults for any omitted optional fields.
|
|
574
|
-
*/
|
|
575
|
-
evolutionAlgorithmConfig: IEvolutionAlgorithmConfig;
|
|
576
|
-
|
|
577
|
-
/**
|
|
578
|
-
* Reporting and telemetry configuration.
|
|
579
|
-
*
|
|
580
|
-
* - Controls logging cadence, dashboard wiring and optional UI pacing.
|
|
581
|
-
* - The dashboardManager will receive per-generation snapshots for presentation or recording.
|
|
582
|
-
*/
|
|
583
|
-
reportingConfig: IReportingConfig;
|
|
584
|
-
|
|
585
|
-
/**
|
|
586
|
-
* Optional fitness evaluator function used to score candidate networks on the maze.
|
|
587
|
-
*
|
|
588
|
-
* - If omitted the runner may fall back to a library-provided default evaluator.
|
|
589
|
-
* - When provided the function must be deterministic for given inputs and must not mutate
|
|
590
|
-
* the provided network or context objects (operate on clones if necessary).
|
|
591
|
-
*
|
|
592
|
-
* @example
|
|
593
|
-
* // A small evaluator that prefers shorter path-to-goal and fewer collisions
|
|
594
|
-
* const fn: FitnessEvaluatorFn = (network, context) => { return score; };
|
|
595
|
-
*/
|
|
596
|
-
fitnessEvaluator?: FitnessEvaluatorFn;
|
|
597
|
-
|
|
598
|
-
/**
|
|
599
|
-
* Optional cooperative cancellation token.
|
|
600
|
-
*
|
|
601
|
-
* - Runner should periodically call `cancellation.isCancelled()` and exit early
|
|
602
|
-
* (returning the best-so-far result) when it returns true.
|
|
603
|
-
* - This is a lightweight, platform-agnostic cancellation protocol useful in tests.
|
|
604
|
-
*/
|
|
605
|
-
cancellation?: { isCancelled: () => boolean };
|
|
606
|
-
|
|
607
|
-
/**
|
|
608
|
-
* Optional standard AbortSignal (Web/DOM-style).
|
|
609
|
-
*
|
|
610
|
-
* - When provided the runner should periodically inspect `signal.aborted` and
|
|
611
|
-
* terminate gracefully, returning partial results if applicable.
|
|
612
|
-
* - This is the modern, standardized cancellation primitive for browser/node environments.
|
|
613
|
-
*/
|
|
614
|
-
signal?: AbortSignal;
|
|
615
|
-
}
|
|
616
|
-
|
|
617
|
-
/**
|
|
618
|
-
* Visualization node used by ASCII/graph renderers to present a network node.
|
|
619
|
-
*
|
|
620
|
-
* Purpose:
|
|
621
|
-
* - Provide a compact, editor-friendly descriptor for a single neuron/node so
|
|
622
|
-
* UI components and examples can show topology, activations and simple stats.
|
|
623
|
-
*
|
|
624
|
-
* Design notes:
|
|
625
|
-
* - Fields are intentionally small and descriptive so learners can inspect nodes
|
|
626
|
-
* in tooltips or serialized snapshots without needing the full Network object.
|
|
627
|
-
*
|
|
628
|
-
* @example
|
|
629
|
-
* const node: IVisualizationNode = {
|
|
630
|
-
* uuid: "node-123",
|
|
631
|
-
* id: 0,
|
|
632
|
-
* type: "input",
|
|
633
|
-
* activation: 0.0,
|
|
634
|
-
* bias: 0.1,
|
|
635
|
-
* label: "x0"
|
|
636
|
-
* };
|
|
101
|
+
* Visualization node used by ASCII and graph renderers to present a network node.
|
|
637
102
|
*/
|
|
638
103
|
export interface IVisualizationNode {
|
|
639
|
-
/**
|
|
640
|
-
* Stable identifier for this visualization node (unique within the visualisation).
|
|
641
|
-
*
|
|
642
|
-
* - Use a string UUID or any unique string that ties back to the network's node.
|
|
643
|
-
* - Useful for diffing frames or matching gater/connection endpoints.
|
|
644
|
-
*/
|
|
645
104
|
uuid: string;
|
|
646
|
-
|
|
647
|
-
/**
|
|
648
|
-
* Numeric index useful for compact lookups or ordering in arrays.
|
|
649
|
-
*
|
|
650
|
-
* - Not required to be globally unique across different networks; unique within this network snapshot is sufficient.
|
|
651
|
-
*/
|
|
652
105
|
id: number;
|
|
653
|
-
|
|
654
|
-
/**
|
|
655
|
-
* Semantic type of the node (for example: "input" | "hidden" | "output" | "constant").
|
|
656
|
-
*
|
|
657
|
-
* - Visualisers can use this to apply different styling or grouping.
|
|
658
|
-
*/
|
|
659
106
|
type: string;
|
|
660
|
-
|
|
661
|
-
/**
|
|
662
|
-
* Current activation value produced by the node (post-squash).
|
|
663
|
-
*
|
|
664
|
-
* - Range depends on the node's activation function. Visualisers commonly
|
|
665
|
-
* map this value to color/height in charts.
|
|
666
|
-
*/
|
|
667
107
|
activation: number;
|
|
668
|
-
|
|
669
|
-
/**
|
|
670
|
-
* Optional bias term associated with the node (if available).
|
|
671
|
-
*
|
|
672
|
-
* - Visualisers may render this as a small numeric badge or tooltip detail.
|
|
673
|
-
* - When undefined the node has no reported bias in this snapshot.
|
|
674
|
-
*/
|
|
675
108
|
bias?: number;
|
|
676
|
-
|
|
677
|
-
/**
|
|
678
|
-
* When true, this node represents an averaged/aggregate node (for visual summaries).
|
|
679
|
-
*
|
|
680
|
-
* - Example: showing mean activations across an ensemble or a temporal average.
|
|
681
|
-
* - Visualisers may draw these nodes differently (dashed outline, faded color).
|
|
682
|
-
*/
|
|
683
109
|
isAverage?: boolean;
|
|
684
|
-
|
|
685
|
-
/**
|
|
686
|
-
* Number of samples included in the averaged value when `isAverage` is true.
|
|
687
|
-
*
|
|
688
|
-
* - Helps consumers interpret how many underlying values were combined.
|
|
689
|
-
* - Undefined when `isAverage` is false or when not applicable.
|
|
690
|
-
*/
|
|
691
110
|
avgCount?: number;
|
|
692
|
-
|
|
693
|
-
/**
|
|
694
|
-
* Optional short human-readable label for the node (e.g. "x0", "hidden-2").
|
|
695
|
-
*
|
|
696
|
-
* - Primarily used in tooltips and exported diagrams to make topology understandable.
|
|
697
|
-
*/
|
|
698
111
|
label?: string;
|
|
699
112
|
}
|
|
700
113
|
|
|
701
114
|
/**
|
|
702
|
-
* Visualization connection used by ASCII
|
|
703
|
-
*
|
|
704
|
-
* Purpose:
|
|
705
|
-
* - Provide a compact, editor-friendly descriptor for a network connection so UI components
|
|
706
|
-
* and examples can show topology, weights and gating information.
|
|
707
|
-
*
|
|
708
|
-
* Design notes:
|
|
709
|
-
* - Fields intentionally mirror the minimal information needed by visualisers: endpoints,
|
|
710
|
-
* optional gater, numeric weight and enabled state. This keeps snapshots small while
|
|
711
|
-
* providing useful tooltip content in IDEs and UIs.
|
|
712
|
-
*
|
|
713
|
-
* @example
|
|
714
|
-
* const conn: IVisualizationConnection = {
|
|
715
|
-
* fromUUID: "node-1",
|
|
716
|
-
* toUUID: "node-2",
|
|
717
|
-
* gaterUUID: null,
|
|
718
|
-
* weight: -0.42,
|
|
719
|
-
* enabled: true
|
|
720
|
-
* };
|
|
115
|
+
* Visualization connection used by ASCII and graph renderers to present an edge between two nodes.
|
|
721
116
|
*/
|
|
722
117
|
export interface IVisualizationConnection {
|
|
723
|
-
/**
|
|
724
|
-
* UUID of the source node for this connection (matches IVisualizationNode.uuid).
|
|
725
|
-
*
|
|
726
|
-
* - Used to map the connection to its visual source endpoint.
|
|
727
|
-
*/
|
|
728
118
|
fromUUID: string;
|
|
729
|
-
|
|
730
|
-
/**
|
|
731
|
-
* UUID of the destination node for this connection (matches IVisualizationNode.uuid).
|
|
732
|
-
*
|
|
733
|
-
* - Used to map the connection to its visual target endpoint.
|
|
734
|
-
*/
|
|
735
119
|
toUUID: string;
|
|
736
|
-
|
|
737
|
-
/**
|
|
738
|
-
* Optional UUID of a gater node that modulates this connection, or null when none.
|
|
739
|
-
*
|
|
740
|
-
* - When present the gater's activation is typically used to scale or gate the connection.
|
|
741
|
-
* - Visualisers can highlight gated connections or show the gater relationship in tooltips.
|
|
742
|
-
*/
|
|
743
120
|
gaterUUID?: string | null;
|
|
744
|
-
|
|
745
|
-
/**
|
|
746
|
-
* Numeric weight of the connection.
|
|
747
|
-
*
|
|
748
|
-
* - Sign indicates excitatory (positive) or inhibitory (negative) influence.
|
|
749
|
-
* - Magnitude can be visualised as line thickness; visualisers should clamp/scale values for display.
|
|
750
|
-
*/
|
|
751
121
|
weight: number;
|
|
752
|
-
|
|
753
|
-
/**
|
|
754
|
-
* Whether this connection is currently enabled (active) in the network topology.
|
|
755
|
-
*
|
|
756
|
-
* - Disabled connections are typically drawn faded, dashed, or omitted.
|
|
757
|
-
*/
|
|
758
122
|
enabled: boolean;
|
|
759
123
|
}
|
|
760
124
|
|
|
761
|
-
/**
|
|
762
|
-
* Structural connection descriptor referencing resolved node structures.
|
|
763
|
-
*
|
|
764
|
-
* Purpose:
|
|
765
|
-
* - Provide a lightweight, serialisable view over a connection while preserving
|
|
766
|
-
* the node references expected by visualisation helpers.
|
|
767
|
-
* - Allow callers to attach additional metadata (innovation ids, traces) via
|
|
768
|
-
* the index signature without breaking type safety for known properties.
|
|
769
|
-
*
|
|
770
|
-
* Typical contents:
|
|
771
|
-
* - `from` and `to` node references (may be null for partially constructed graphs).
|
|
772
|
-
* - Optional `gater` node when using gated connections.
|
|
773
|
-
* - Optional `weight` and `enabled` flags mirroring the runtime connection.
|
|
774
|
-
*/
|
|
125
|
+
/** Structural connection descriptor referencing resolved node structures. */
|
|
775
126
|
export interface IConnectionWithStructRefs {
|
|
776
|
-
/** Source node reference for the connection (null when unresolved). */
|
|
777
127
|
from?: INodeStruct | null;
|
|
778
|
-
/** Destination node reference for the connection (null when unresolved). */
|
|
779
128
|
to?: INodeStruct | null;
|
|
780
|
-
/** Optional gater node reference (null or undefined when ungated). */
|
|
781
129
|
gater?: INodeStruct | null;
|
|
782
|
-
/** Optional numeric weight associated with the connection. */
|
|
783
130
|
weight?: number;
|
|
784
|
-
/** Whether the connection is currently enabled. */
|
|
785
131
|
enabled?: boolean;
|
|
786
|
-
/** Additional metadata supplied by concrete implementations. */
|
|
787
132
|
[key: string]: unknown;
|
|
788
133
|
}
|
|
789
134
|
|
|
790
|
-
/**
|
|
791
|
-
* Aggregates incoming/outgoing link arrays for a node snapshot.
|
|
792
|
-
*
|
|
793
|
-
* Callers may omit arrays that are not relevant for a given snapshot to keep
|
|
794
|
-
* serialised structures compact. Visualisation helpers should treat missing
|
|
795
|
-
* arrays as empty collections.
|
|
796
|
-
*/
|
|
135
|
+
/** Aggregates incoming and outgoing link arrays for a node snapshot. */
|
|
797
136
|
export interface INodeConnectionRegistry {
|
|
798
|
-
/** Incoming connections terminating at the node. */
|
|
799
137
|
in?: IConnectionWithStructRefs[];
|
|
800
|
-
/** Outgoing connections sourced from the node. */
|
|
801
138
|
out?: IConnectionWithStructRefs[];
|
|
802
|
-
/** Connections gated by the node. */
|
|
803
139
|
gated?: IConnectionWithStructRefs[];
|
|
804
|
-
/** Self/recurrent connection descriptors. */
|
|
805
140
|
self?: IConnectionWithStructRefs[];
|
|
806
|
-
/** Extension point for engine-specific registries. */
|
|
807
141
|
[key: string]: unknown;
|
|
808
142
|
}
|
|
809
143
|
|
|
810
|
-
/**
|
|
811
|
-
* Type representing a node activation (squash) function with optional metadata.
|
|
812
|
-
*
|
|
813
|
-
* Purpose:
|
|
814
|
-
* - Document the runtime contract for activation functions used by network nodes
|
|
815
|
-
* and provide optional human-friendly metadata that UI/tooling can surface.
|
|
816
|
-
*
|
|
817
|
-
* Call signature:
|
|
818
|
-
* - (input: number, derivate?: boolean) => number
|
|
819
|
-
* - `input`: numeric input to the activation function.
|
|
820
|
-
* - `derivate` (optional): when true the function should return the derivative
|
|
821
|
-
* of the activation with respect to `input`. Implementations may ignore
|
|
822
|
-
* this parameter if derivatives are not supported.
|
|
823
|
-
*
|
|
824
|
-
* Semantics:
|
|
825
|
-
* - When `derivate` is omitted or false the function returns the activated value.
|
|
826
|
-
* - When `derivate` is true the function returns the derivative value (useful for backpropagation).
|
|
827
|
-
* - Implementations should return finite numbers and avoid throwing for typical numeric inputs.
|
|
828
|
-
*
|
|
829
|
-
* Optional metadata properties:
|
|
830
|
-
* - `name?: string` - a short human-friendly label for UI/tooling (e.g. "tanh", "relu").
|
|
831
|
-
* - `originalName?: string` - canonical/original identifier (useful for serialization or debugging).
|
|
832
|
-
*
|
|
833
|
-
* Example:
|
|
834
|
-
* const relu: ActivationFunctionWithName = (x, derivate = false) =>
|
|
835
|
-
* derivate ? (x > 0 ? 1 : 0) : Math.max(0, x);
|
|
836
|
-
* relu.name = "relu";
|
|
837
|
-
* relu.originalName = "ReLU";
|
|
838
|
-
*/
|
|
144
|
+
/** Type representing a node activation (squash) function with optional metadata. */
|
|
839
145
|
export type ActivationFunctionWithName = ((
|
|
840
146
|
input: number,
|
|
841
147
|
derivate?: boolean,
|
|
@@ -844,202 +150,36 @@ export type ActivationFunctionWithName = ((
|
|
|
844
150
|
originalName?: string;
|
|
845
151
|
};
|
|
846
152
|
|
|
847
|
-
/**
|
|
848
|
-
* Structure describing a single network node for visualization, serialization and tooling.
|
|
849
|
-
*
|
|
850
|
-
* Purpose:
|
|
851
|
-
* - Provide a compact, self-documenting snapshot of a node's static and runtime
|
|
852
|
-
* metadata so examples, visualisers and tests can inspect networks without
|
|
853
|
-
* depending on a concrete Network class.
|
|
854
|
-
*
|
|
855
|
-
* Key ideas:
|
|
856
|
-
* - Keep shape small and serialisable: useful for JSON snapshots, tooltips and diagrams.
|
|
857
|
-
* - Distinguish static descriptors (type, name, index) from runtime values (activation).
|
|
858
|
-
*
|
|
859
|
-
* Example:
|
|
860
|
-
* const node: INodeStruct = {
|
|
861
|
-
* type: "hidden",
|
|
862
|
-
* bias: -0.1,
|
|
863
|
-
* squash: tanhFunction,
|
|
864
|
-
* activation: 0.234,
|
|
865
|
-
* name: "hidden-3",
|
|
866
|
-
* index: 12
|
|
867
|
-
* };
|
|
868
|
-
*/
|
|
153
|
+
/** Structure describing a single network node for visualization, serialization and tooling. */
|
|
869
154
|
export interface INodeStruct {
|
|
870
|
-
/**
|
|
871
|
-
* Semantic node type. Typical values: 'input', 'hidden', 'output', 'constant'.
|
|
872
|
-
*
|
|
873
|
-
* - Visualisers and serialization code can use this to group or style nodes.
|
|
874
|
-
*/
|
|
875
155
|
type: string;
|
|
876
|
-
|
|
877
|
-
/**
|
|
878
|
-
* Optional numeric bias term applied at the node's aggregation stage.
|
|
879
|
-
*
|
|
880
|
-
* - When omitted the node is treated as having no explicit bias in this snapshot.
|
|
881
|
-
*/
|
|
882
156
|
bias?: number;
|
|
883
|
-
|
|
884
|
-
/**
|
|
885
|
-
* Optional activation (squash) function used by this node.
|
|
886
|
-
*
|
|
887
|
-
* - Provides a callable used for inference/visualisation and optional name metadata.
|
|
888
|
-
* - May be undefined for lightweight snapshots where function references are not serialised.
|
|
889
|
-
*/
|
|
890
157
|
squash?: ActivationFunctionWithName;
|
|
891
|
-
|
|
892
|
-
/**
|
|
893
|
-
* Runtime activation value produced by the node (post-squash).
|
|
894
|
-
*
|
|
895
|
-
* - Useful for visualisers, debugging and test assertions that inspect network behaviour.
|
|
896
|
-
* - Range depends on the chosen activation function.
|
|
897
|
-
*/
|
|
898
158
|
activation?: number;
|
|
899
|
-
|
|
900
|
-
/**
|
|
901
|
-
* Optional human-friendly label for the node (e.g. "x0", "hidden-2").
|
|
902
|
-
*
|
|
903
|
-
* - Used in tooltips, exported diagrams and debug logs to make topology easier to read.
|
|
904
|
-
*/
|
|
905
159
|
name?: string;
|
|
906
|
-
|
|
907
|
-
/**
|
|
908
|
-
* Optional numeric index for compact lookups or ordering.
|
|
909
|
-
*
|
|
910
|
-
* - Conventionally unique within a single network snapshot; not necessarily globally unique.
|
|
911
|
-
* - Useful when mapping connections that refer to numeric indices rather than uuids.
|
|
912
|
-
*/
|
|
913
160
|
index?: number;
|
|
914
|
-
|
|
915
|
-
/**
|
|
916
|
-
* Catch-all for implementation-specific extras.
|
|
917
|
-
*
|
|
918
|
-
* - Allows concrete Network implementations to expose additional fields without
|
|
919
|
-
* breaking the generic interface. Prefer explicit properties where feasible.
|
|
920
|
-
*/
|
|
921
161
|
[key: string]: unknown;
|
|
922
162
|
}
|
|
923
163
|
|
|
924
|
-
/**
|
|
925
|
-
* Extended node snapshot including connection registries for visualisation utilities.
|
|
926
|
-
*
|
|
927
|
-
* Purpose:
|
|
928
|
-
* - Preserve the lightweight structural fields from {@link INodeStruct} while adding
|
|
929
|
-
* optional connection arrays used by network visualisation helpers.
|
|
930
|
-
* - Allow demos/tests to pass concrete `Network` nodes directly without cloning
|
|
931
|
-
* as long as they satisfy the shape of this interface.
|
|
932
|
-
*/
|
|
164
|
+
/** Extended node snapshot including connection registries for visualisation utilities. */
|
|
933
165
|
export interface INodeWithConnectionInfo extends INodeStruct {
|
|
934
|
-
/** Optional connection registry describing incoming/outgoing/gated links. */
|
|
935
166
|
connections?: INodeConnectionRegistry;
|
|
936
167
|
}
|
|
937
168
|
|
|
938
169
|
/**
|
|
939
|
-
* Lightweight
|
|
940
|
-
* Maze examples. This interface is intentionally permissive so it can describe
|
|
941
|
-
* multiple concrete implementations (the library's Network class, clones,
|
|
942
|
-
* simplified mocks for tests, or externally serialized networks).
|
|
943
|
-
*
|
|
944
|
-
* The goal of these comments is to make it easy for learners to:
|
|
945
|
-
* - see the minimal runtime surface required by the maze demos,
|
|
946
|
-
* - understand typical semantics of each member (inputs/outputs, side-effects),
|
|
947
|
-
* - know which methods are optional for simple inference vs. training/debugging.
|
|
948
|
-
*
|
|
949
|
-
* Typical usage:
|
|
950
|
-
* - For inference only: implement activate(inputs) -> outputs.
|
|
951
|
-
* - For training/refinement: also implement propagate(...) and optionally clone().
|
|
952
|
-
* - For visualization/analysis: provide nodes/connections arrays and input/output descriptors.
|
|
170
|
+
* Lightweight neural-network abstraction used across the ASCII Maze example.
|
|
953
171
|
*/
|
|
954
172
|
export interface INetwork {
|
|
955
|
-
/**
|
|
956
|
-
* Performs a forward pass of the network using the provided input values and
|
|
957
|
-
* returns the resulting output values.
|
|
958
|
-
*
|
|
959
|
-
* Semantics:
|
|
960
|
-
* - inputs: an array of numbers matching the network's expected input size.
|
|
961
|
-
* - returns: an array of numbers representing the network's outputs (one or more).
|
|
962
|
-
*
|
|
963
|
-
* Typical responsibilities:
|
|
964
|
-
* - apply input values to input nodes,
|
|
965
|
-
* - propagate activations through layers/recurrent links according to the
|
|
966
|
-
* network's topology and activation functions,
|
|
967
|
-
* - return the values produced by the output nodes.
|
|
968
|
-
*
|
|
969
|
-
* This method must be synchronous and pure with respect to its return value
|
|
970
|
-
* (side-effects like internal state updates are allowed but callers expect
|
|
971
|
-
* a deterministic output for the same inputs unless stateful recurrence exists).
|
|
972
|
-
*/
|
|
973
173
|
activate: (inputs: number[]) => number[];
|
|
974
|
-
|
|
975
|
-
/**
|
|
976
|
-
* Optional supervised-learning update method (backpropagation style).
|
|
977
|
-
*
|
|
978
|
-
* Parameters:
|
|
979
|
-
* - rate: learning rate (how large weight updates should be),
|
|
980
|
-
* - momentum: momentum term for weight updates (typical 0.0 - 1.0),
|
|
981
|
-
* - update: if true, actually apply weight updates; if false, compute but do not apply,
|
|
982
|
-
* - target: array of expected output values used to compute output-layer errors.
|
|
983
|
-
*
|
|
984
|
-
* Implementations:
|
|
985
|
-
* - Concrete Network classes may implement this to support gradient-based
|
|
986
|
-
* refinement (Baldwinian/Lamarckian steps in evolution).
|
|
987
|
-
* - Optional on the interface because many evolutionary workflows only need
|
|
988
|
-
* activation (inference).
|
|
989
|
-
*/
|
|
990
174
|
propagate?: (
|
|
991
175
|
rate: number,
|
|
992
176
|
momentum: number,
|
|
993
177
|
update: boolean,
|
|
994
178
|
target: number[],
|
|
995
179
|
) => void;
|
|
996
|
-
|
|
997
|
-
/**
|
|
998
|
-
* Optional: clears internal dynamic state such as recurrent activations or
|
|
999
|
-
* transient caches so the network behaves as if it's freshly initialised.
|
|
1000
|
-
*
|
|
1001
|
-
* Use when running sequences or episodic environments to avoid state leakage
|
|
1002
|
-
* between episodes.
|
|
1003
|
-
*/
|
|
1004
180
|
clear?: () => void;
|
|
1005
|
-
|
|
1006
|
-
/**
|
|
1007
|
-
* Optional: produce a deep copy of the network object.
|
|
1008
|
-
*
|
|
1009
|
-
* Semantics:
|
|
1010
|
-
* - The clone should be independent: mutations to the clone must not affect the original.
|
|
1011
|
-
* - Clones are useful for experimentation, evaluation, or storing snapshots.
|
|
1012
|
-
*/
|
|
1013
181
|
clone?: () => INetwork;
|
|
1014
|
-
|
|
1015
|
-
/**
|
|
1016
|
-
* Optional structural description of the network's nodes.
|
|
1017
|
-
*
|
|
1018
|
-
* Typical contents:
|
|
1019
|
-
* - Each node entry describes its type ('input'|'hidden'|'output'|'constant'),
|
|
1020
|
-
* bias, activation function reference (squash), and runtime activation value.
|
|
1021
|
-
* - Useful for visualization, introspection, and deterministic reproducible
|
|
1022
|
-
* comparisons between networks.
|
|
1023
|
-
*
|
|
1024
|
-
* Note: implementations may omit nodes to save memory; visualisers should
|
|
1025
|
-
* handle missing or partial descriptions.
|
|
1026
|
-
*/
|
|
1027
182
|
nodes?: INodeStruct[];
|
|
1028
|
-
|
|
1029
|
-
/**
|
|
1030
|
-
* Optional structural description of the network's connections.
|
|
1031
|
-
*
|
|
1032
|
-
* Each connection typically contains:
|
|
1033
|
-
* - from/to: references to INodeStruct describing the endpoints,
|
|
1034
|
-
* - weight: numeric weight applied during activation propagation,
|
|
1035
|
-
* - gater: optional node that gates this connection (null when unused),
|
|
1036
|
-
* - enabled: whether this connection is currently active.
|
|
1037
|
-
*
|
|
1038
|
-
* Use-cases:
|
|
1039
|
-
* - visualization of topology and weights,
|
|
1040
|
-
* - pruning or serialization routines that iterate connections,
|
|
1041
|
-
* - analysis of recurrent links vs feed-forward paths.
|
|
1042
|
-
*/
|
|
1043
183
|
connections?: {
|
|
1044
184
|
from: INodeStruct;
|
|
1045
185
|
to: INodeStruct;
|
|
@@ -1048,445 +188,17 @@ export interface INetwork {
|
|
|
1048
188
|
enabled?: boolean;
|
|
1049
189
|
[key: string]: unknown;
|
|
1050
190
|
}[];
|
|
1051
|
-
|
|
1052
|
-
/**
|
|
1053
|
-
* Optional description of the input "layer".
|
|
1054
|
-
*
|
|
1055
|
-
* Can be either:
|
|
1056
|
-
* - a number: the expected size of the input (used for validation/documentation),
|
|
1057
|
-
* - an array of INodeStruct describing input nodes (used by visualisers or low-level code).
|
|
1058
|
-
*/
|
|
1059
191
|
input?: number | INodeStruct[];
|
|
1060
|
-
|
|
1061
|
-
/**
|
|
1062
|
-
* Optional description of the output "layer".
|
|
1063
|
-
*
|
|
1064
|
-
* Same conventions as `input`.
|
|
1065
|
-
*/
|
|
1066
192
|
output?: number | INodeStruct[];
|
|
1067
|
-
|
|
1068
|
-
// Add any other methods/properties from the concrete Network class that are used by the asciiMaze example
|
|
1069
193
|
}
|
|
1070
194
|
|
|
1071
|
-
/**
|
|
1072
|
-
* Represents the outcome of a single logical step, phase or checkpoint in the evolution process.
|
|
1073
|
-
*
|
|
1074
|
-
* Purpose:
|
|
1075
|
-
* - Provide a small, stable shape that runners and reporters can use to communicate
|
|
1076
|
-
* incremental results (for example per-generation or per-refinement-phase snapshots).
|
|
1077
|
-
*
|
|
1078
|
-
* Semantics:
|
|
1079
|
-
* - `success` is a boolean flag indicating whether the step achieved its primary goal
|
|
1080
|
-
* (for example: a candidate solved the maze or a phase completed without error).
|
|
1081
|
-
* - `progress` is a numeric measure of improvement or completion. Its exact scale is
|
|
1082
|
-
* context-dependent (for example: normalized [0..1], raw fitness delta, number of improved individuals).
|
|
1083
|
-
* Consumers should consult the caller's conventions; treat the field as monotonic within a phase when possible.
|
|
1084
|
-
*
|
|
1085
|
-
* Usage notes:
|
|
1086
|
-
* - Reporters and dashboards can use `success` to highlight terminal events and `progress`
|
|
1087
|
-
* to render progress bars or compute trend lines.
|
|
1088
|
-
* - When `success` is true, `progress` typically represents the achieved score; when false it may be a relative improvement metric.
|
|
1089
|
-
*
|
|
1090
|
-
* @example
|
|
1091
|
-
* // A generation that produced an improved best individual:
|
|
1092
|
-
* const step: IEvolutionStepResult = { success: false, progress: 0.034 };
|
|
1093
|
-
*/
|
|
195
|
+
/** Represents the outcome of a single logical step or checkpoint in the evolution process. */
|
|
1094
196
|
export interface IEvolutionStepResult {
|
|
1095
|
-
/**
|
|
1096
|
-
* True when the reported step achieved its primary success condition.
|
|
1097
|
-
*
|
|
1098
|
-
* - Example meanings: a solution was found, a refinement phase completed successfully, or a save completed.
|
|
1099
|
-
*/
|
|
1100
197
|
success: boolean;
|
|
1101
|
-
|
|
1102
|
-
/**
|
|
1103
|
-
* Numeric progress indicator associated with the step.
|
|
1104
|
-
*
|
|
1105
|
-
* - Interpretation depends on the caller: commonly a positive fitness value, a relative delta, or a normalized fraction [0..1].
|
|
1106
|
-
* - Should be finite (not NaN/Infinity); use caller conventions to interpret magnitude/sign.
|
|
1107
|
-
*/
|
|
1108
198
|
progress: number;
|
|
1109
199
|
}
|
|
1110
200
|
|
|
1111
|
-
/**
|
|
1112
|
-
* Represents the overall result of an evolution function call.
|
|
1113
|
-
*
|
|
1114
|
-
* Purpose:
|
|
1115
|
-
* - Provide a small, explicit container that callers receive when an evolution
|
|
1116
|
-
* run completes or is terminated. This wrapper makes it clear which step
|
|
1117
|
-
* result represents the final/returned summary so reporters and callers can
|
|
1118
|
-
* consistently read outcome data.
|
|
1119
|
-
*
|
|
1120
|
-
* Semantics:
|
|
1121
|
-
* - `finalResult` typically holds the best-known IEvolutionStepResult at the
|
|
1122
|
-
* time the run finished (normal completion, early stop, or cancellation).
|
|
1123
|
-
* - Runners should populate `finalResult` with a succinct summary that is safe
|
|
1124
|
-
* to serialize and display (do not embed large transient structures).
|
|
1125
|
-
*
|
|
1126
|
-
* Interpretation notes:
|
|
1127
|
-
* - Consumers can use `finalResult.success` to decide whether the run met its
|
|
1128
|
-
* main goal (for example: a solution was found).
|
|
1129
|
-
* - `finalResult.progress` contains the numeric progress/score according to
|
|
1130
|
-
* the experiment's convention (see IEvolutionStepResult). Its scale may be
|
|
1131
|
-
* normalized ([0..1]) or raw fitness/metric values depending on the runner.
|
|
1132
|
-
*
|
|
1133
|
-
* Example:
|
|
1134
|
-
* const result: IEvolutionFunctionResult = {
|
|
1135
|
-
* finalResult: { success: true, progress: 0.987 }
|
|
1136
|
-
* };
|
|
1137
|
-
*/
|
|
201
|
+
/** Represents the overall result of an evolution function call. */
|
|
1138
202
|
export interface IEvolutionFunctionResult {
|
|
1139
|
-
/**
|
|
1140
|
-
* The final summary step result produced by the evolution run.
|
|
1141
|
-
*
|
|
1142
|
-
* - Should be set by the runner to reflect the best/terminal IEvolutionStepResult.
|
|
1143
|
-
* - Useful for UI, logging, persistence and programmatic checks after the run returns.
|
|
1144
|
-
*/
|
|
1145
203
|
finalResult: IEvolutionStepResult;
|
|
1146
204
|
}
|
|
1147
|
-
|
|
1148
|
-
/**
|
|
1149
|
-
* Runtime types for evolution engine internals
|
|
1150
|
-
* These types represent dynamic structures used throughout the evolution system
|
|
1151
|
-
*/
|
|
1152
|
-
|
|
1153
|
-
/** Type for Neat class instance from neataptic library */
|
|
1154
|
-
export type NeatInstance = import('../../../src/neat').default;
|
|
1155
|
-
|
|
1156
|
-
/** Type for Network class instance from neataptic library */
|
|
1157
|
-
export type NetworkInstance =
|
|
1158
|
-
import('../../../src/architecture/network').default;
|
|
1159
|
-
|
|
1160
|
-
/** Encoded maze representation with cell values */
|
|
1161
|
-
export interface EncodedMaze {
|
|
1162
|
-
/** Width of the maze */
|
|
1163
|
-
width: number;
|
|
1164
|
-
/** Height of the maze */
|
|
1165
|
-
height: number;
|
|
1166
|
-
/** Flattened array of cell values */
|
|
1167
|
-
cells: number[];
|
|
1168
|
-
/** Original maze strings */
|
|
1169
|
-
maze: string[];
|
|
1170
|
-
}
|
|
1171
|
-
|
|
1172
|
-
/** 2D position in maze coordinates */
|
|
1173
|
-
export interface Position {
|
|
1174
|
-
/** X coordinate (column) */
|
|
1175
|
-
x: number;
|
|
1176
|
-
/** Y coordinate (row) */
|
|
1177
|
-
y: number;
|
|
1178
|
-
}
|
|
1179
|
-
|
|
1180
|
-
/** Distance map for maze navigation */
|
|
1181
|
-
export interface DistanceMap {
|
|
1182
|
-
/** Width of the map */
|
|
1183
|
-
width: number;
|
|
1184
|
-
/** Height of the map */
|
|
1185
|
-
height: number;
|
|
1186
|
-
/** Flattened array of distances from exit */
|
|
1187
|
-
distances: number[];
|
|
1188
|
-
}
|
|
1189
|
-
|
|
1190
|
-
/** Options object passed to evolution functions */
|
|
1191
|
-
export interface EvolutionOptions {
|
|
1192
|
-
/** Optional cancellation controller */
|
|
1193
|
-
cancellation?: {
|
|
1194
|
-
/** Check if cancellation is requested (legacy API) */
|
|
1195
|
-
isCancelled?: () => boolean;
|
|
1196
|
-
/** Check if cancellation is requested */
|
|
1197
|
-
isCancellationRequested?: () => boolean;
|
|
1198
|
-
/** Reason for cancellation */
|
|
1199
|
-
reason?: string;
|
|
1200
|
-
};
|
|
1201
|
-
/** Optional AbortSignal for cooperative cancellation */
|
|
1202
|
-
signal?: AbortSignal;
|
|
1203
|
-
/** Maximum number of generations to run */
|
|
1204
|
-
maxGenerations?: number;
|
|
1205
|
-
/** Maximum number of stagnant generations before stopping */
|
|
1206
|
-
maxStagnantGenerations?: number;
|
|
1207
|
-
/** Minimum progress value to consider maze solved */
|
|
1208
|
-
minProgressToPass?: number;
|
|
1209
|
-
/** Log telemetry every N generations */
|
|
1210
|
-
logEvery?: number;
|
|
1211
|
-
/** Enable profiling */
|
|
1212
|
-
enableProfiling?: boolean;
|
|
1213
|
-
/** Directory for persistence */
|
|
1214
|
-
persistDir?: string;
|
|
1215
|
-
/** Number of top networks to persist */
|
|
1216
|
-
persistTopK?: number;
|
|
1217
|
-
/** Persist every N generations */
|
|
1218
|
-
persistEvery?: number;
|
|
1219
|
-
/** Optional flush function for UI updates */
|
|
1220
|
-
flushToFrame?: () => Promise<void>;
|
|
1221
|
-
/** Reporting configuration */
|
|
1222
|
-
reportingConfig?: {
|
|
1223
|
-
/** Dashboard manager instance */
|
|
1224
|
-
dashboardManager?: IDashboardManager;
|
|
1225
|
-
/** Log every N generations */
|
|
1226
|
-
logEvery?: number;
|
|
1227
|
-
/** Pace every generation (yield to UI) */
|
|
1228
|
-
paceEveryGeneration?: boolean;
|
|
1229
|
-
/** Additional reporting options */
|
|
1230
|
-
[key: string]: unknown;
|
|
1231
|
-
};
|
|
1232
|
-
/** Maze configuration */
|
|
1233
|
-
mazeConfig: {
|
|
1234
|
-
/** Maze strings array */
|
|
1235
|
-
maze: string[];
|
|
1236
|
-
/** Additional maze config */
|
|
1237
|
-
[key: string]: unknown;
|
|
1238
|
-
};
|
|
1239
|
-
/** Agent simulation configuration */
|
|
1240
|
-
agentSimConfig?: {
|
|
1241
|
-
/** Maximum steps for agent simulation */
|
|
1242
|
-
maxSteps: number;
|
|
1243
|
-
/** Additional simulation options */
|
|
1244
|
-
[key: string]: unknown;
|
|
1245
|
-
};
|
|
1246
|
-
/** Lamarckian training iterations */
|
|
1247
|
-
lamarckianIterations?: number;
|
|
1248
|
-
/** Lamarckian sample size */
|
|
1249
|
-
lamarckianSampleSize?: number;
|
|
1250
|
-
/** Enable dynamic population growth */
|
|
1251
|
-
dynamicPopEnabled?: boolean;
|
|
1252
|
-
/** Maximum dynamic population size */
|
|
1253
|
-
dynamicPopMax?: number;
|
|
1254
|
-
/** Plateau generations threshold */
|
|
1255
|
-
plateauGenerations?: number;
|
|
1256
|
-
/** Dynamic population expand interval */
|
|
1257
|
-
dynamicPopExpandInterval?: number;
|
|
1258
|
-
/** Dynamic population expand factor */
|
|
1259
|
-
dynamicPopExpandFactor?: number;
|
|
1260
|
-
/** Dynamic population plateau slack */
|
|
1261
|
-
dynamicPopPlateauSlack?: number;
|
|
1262
|
-
/** Plateau improvement threshold */
|
|
1263
|
-
plateauImprovementThreshold?: number;
|
|
1264
|
-
/** Simplify duration in generations */
|
|
1265
|
-
simplifyDuration?: number;
|
|
1266
|
-
/** Simplify strategy */
|
|
1267
|
-
simplifyStrategy?: 'weakWeight' | 'weakRecurrentPreferred';
|
|
1268
|
-
/** Simplify prune fraction */
|
|
1269
|
-
simplifyPruneFraction?: number;
|
|
1270
|
-
/** Memory compaction interval */
|
|
1271
|
-
memoryCompactionInterval?: number;
|
|
1272
|
-
/** Auto-pause on solve flag */
|
|
1273
|
-
autoPauseOnSolve?: boolean;
|
|
1274
|
-
/** Stop only on solve (ignore stagnation) */
|
|
1275
|
-
stopOnlyOnSolve?: boolean;
|
|
1276
|
-
/** Initial best network */
|
|
1277
|
-
initialBestNetwork?: unknown;
|
|
1278
|
-
/** Additional dynamic options */
|
|
1279
|
-
[key: string]: unknown;
|
|
1280
|
-
}
|
|
1281
|
-
|
|
1282
|
-
/** Helper functions object passed to evolution loop */
|
|
1283
|
-
export interface EvolutionHelpers {
|
|
1284
|
-
/** Write function for logging */
|
|
1285
|
-
write: (msg: string) => void;
|
|
1286
|
-
/** Check if profiling details are enabled */
|
|
1287
|
-
isProfilingDetailsEnabled: (state: unknown) => boolean;
|
|
1288
|
-
/** Get profiling accumulators */
|
|
1289
|
-
getProfilingAccumulators: (state: unknown) => ProfilingAccumulators;
|
|
1290
|
-
}
|
|
1291
|
-
|
|
1292
|
-
/** Profiling accumulator structure */
|
|
1293
|
-
export interface ProfilingAccumulators {
|
|
1294
|
-
/** Total evolution time in milliseconds */
|
|
1295
|
-
totalEvolveMs?: number;
|
|
1296
|
-
/** Total Lamarckian training time in milliseconds */
|
|
1297
|
-
totalLamarckMs?: number;
|
|
1298
|
-
/** Total simulation time in milliseconds */
|
|
1299
|
-
totalSimMs?: number;
|
|
1300
|
-
/** Mutation time */
|
|
1301
|
-
mutate?: number;
|
|
1302
|
-
/** Crossover time */
|
|
1303
|
-
crossover?: number;
|
|
1304
|
-
/** Selection time */
|
|
1305
|
-
select?: number;
|
|
1306
|
-
/** Snapshot time */
|
|
1307
|
-
snapshot?: number;
|
|
1308
|
-
/** Telemetry time */
|
|
1309
|
-
telemetry?: number;
|
|
1310
|
-
/** Simplify time */
|
|
1311
|
-
simplify?: number;
|
|
1312
|
-
/** Prune time */
|
|
1313
|
-
prune?: number;
|
|
1314
|
-
/** Additional profiling metrics */
|
|
1315
|
-
[key: string]: number | undefined;
|
|
1316
|
-
}
|
|
1317
|
-
|
|
1318
|
-
/** Node.js fs module type for file operations */
|
|
1319
|
-
export interface FileSystem {
|
|
1320
|
-
/** Write file synchronously */
|
|
1321
|
-
writeFileSync: (path: string, data: string) => void;
|
|
1322
|
-
/** Read file synchronously */
|
|
1323
|
-
readFileSync: (path: string, encoding: string) => string;
|
|
1324
|
-
/** Check if file exists */
|
|
1325
|
-
existsSync: (path: string) => boolean;
|
|
1326
|
-
/** Make directory */
|
|
1327
|
-
mkdirSync: (path: string, options?: { recursive?: boolean }) => void;
|
|
1328
|
-
}
|
|
1329
|
-
|
|
1330
|
-
/** Node.js path module type */
|
|
1331
|
-
export interface PathModule {
|
|
1332
|
-
/** Join path segments */
|
|
1333
|
-
join: (...paths: string[]) => string;
|
|
1334
|
-
/** Resolve absolute path */
|
|
1335
|
-
resolve: (...paths: string[]) => string;
|
|
1336
|
-
/** Get directory name */
|
|
1337
|
-
dirname: (path: string) => string;
|
|
1338
|
-
}
|
|
1339
|
-
|
|
1340
|
-
/** Loop helpers returned by prepareLoopHelpers */
|
|
1341
|
-
export interface LoopHelpers {
|
|
1342
|
-
/** Async function to yield to browser frame */
|
|
1343
|
-
flushToFrame: () => Promise<void>;
|
|
1344
|
-
/** Node.js fs module (may be null in browser) - uses setupHelpers.FilesystemModule */
|
|
1345
|
-
fs: unknown;
|
|
1346
|
-
/** Node.js path module (may be null in browser) - uses setupHelpers.PathModule */
|
|
1347
|
-
path: unknown;
|
|
1348
|
-
/** Safe write function for logging */
|
|
1349
|
-
safeWrite: (msg: string) => void;
|
|
1350
|
-
}
|
|
1351
|
-
|
|
1352
|
-
/** Scratch bundle containing reusable buffers */
|
|
1353
|
-
export interface ScratchBundle {
|
|
1354
|
-
/** Pooled sample array */
|
|
1355
|
-
samplePool?: unknown[];
|
|
1356
|
-
/** Profiling scratch buffer */
|
|
1357
|
-
profilingScratch?: Float64Array;
|
|
1358
|
-
/** Exponential scratch buffer */
|
|
1359
|
-
exps?: Float64Array;
|
|
1360
|
-
/** Additional scratch buffers */
|
|
1361
|
-
[key: string]: unknown;
|
|
1362
|
-
}
|
|
1363
|
-
|
|
1364
|
-
/** Snapshot entry for persistence */
|
|
1365
|
-
export interface SnapshotEntry {
|
|
1366
|
-
/** Index in population */
|
|
1367
|
-
idx?: number;
|
|
1368
|
-
/** JSON serialization of network */
|
|
1369
|
-
json?: string;
|
|
1370
|
-
/** Score */
|
|
1371
|
-
score?: number;
|
|
1372
|
-
/** Number of nodes */
|
|
1373
|
-
nodes?: number;
|
|
1374
|
-
/** Number of connections */
|
|
1375
|
-
connections?: number;
|
|
1376
|
-
/** Additional snapshot data */
|
|
1377
|
-
[key: string]: unknown;
|
|
1378
|
-
}
|
|
1379
|
-
|
|
1380
|
-
/** Training constants */
|
|
1381
|
-
export interface TrainingConstants {
|
|
1382
|
-
/** Default training error threshold */
|
|
1383
|
-
DEFAULT_TRAIN_ERROR: number;
|
|
1384
|
-
/** Default training learning rate */
|
|
1385
|
-
DEFAULT_TRAIN_RATE: number;
|
|
1386
|
-
/** Default training momentum */
|
|
1387
|
-
DEFAULT_TRAIN_MOMENTUM: number;
|
|
1388
|
-
/** Default small batch size */
|
|
1389
|
-
DEFAULT_TRAIN_BATCH_SMALL: number;
|
|
1390
|
-
/** Default small standard deviation */
|
|
1391
|
-
DEFAULT_STD_SMALL: number;
|
|
1392
|
-
/** Default standard deviation adjustment multiplier */
|
|
1393
|
-
DEFAULT_STD_ADJUST_MULT: number;
|
|
1394
|
-
}
|
|
1395
|
-
|
|
1396
|
-
/** Helper functions for evolution */
|
|
1397
|
-
export interface EvolutionLoopHelpers {
|
|
1398
|
-
/** Get node indices by type */
|
|
1399
|
-
getNodeIndicesByType: (nodes: NetworkNode[], type: string) => number;
|
|
1400
|
-
/** Collect hidden-to-output connections */
|
|
1401
|
-
collectHiddenToOutputConns: (
|
|
1402
|
-
hiddenNode: NetworkNode,
|
|
1403
|
-
nodes: NetworkNode[],
|
|
1404
|
-
outputCount: number,
|
|
1405
|
-
) => NetworkConnection[];
|
|
1406
|
-
}
|
|
1407
|
-
|
|
1408
|
-
/** Network node representation */
|
|
1409
|
-
export interface NetworkNode {
|
|
1410
|
-
/** Node type (input/output/hidden) */
|
|
1411
|
-
type?: string;
|
|
1412
|
-
/** Node bias */
|
|
1413
|
-
bias?: number;
|
|
1414
|
-
/** Node activation function */
|
|
1415
|
-
squash?:
|
|
1416
|
-
| string
|
|
1417
|
-
| { name?: string }
|
|
1418
|
-
| ((x: number, derivate?: boolean) => number);
|
|
1419
|
-
/** Incoming connections */
|
|
1420
|
-
connections?: {
|
|
1421
|
-
in?: NetworkConnection[];
|
|
1422
|
-
out?: NetworkConnection[];
|
|
1423
|
-
};
|
|
1424
|
-
/** Additional node properties */
|
|
1425
|
-
[key: string]: unknown;
|
|
1426
|
-
}
|
|
1427
|
-
|
|
1428
|
-
/** Network connection representation */
|
|
1429
|
-
export interface NetworkConnection {
|
|
1430
|
-
/** Source node */
|
|
1431
|
-
from?: NetworkNode;
|
|
1432
|
-
/** Target node */
|
|
1433
|
-
to?: NetworkNode;
|
|
1434
|
-
/** Connection weight */
|
|
1435
|
-
weight?: number;
|
|
1436
|
-
/** Connection gain */
|
|
1437
|
-
gain?: number;
|
|
1438
|
-
/** Additional connection properties */
|
|
1439
|
-
[key: string]: unknown;
|
|
1440
|
-
}
|
|
1441
|
-
|
|
1442
|
-
/** Encoded maze for simulation */
|
|
1443
|
-
export interface EncodedMazeData {
|
|
1444
|
-
/** Maze width */
|
|
1445
|
-
width: number;
|
|
1446
|
-
/** Maze height */
|
|
1447
|
-
height: number;
|
|
1448
|
-
/** Flattened cell data */
|
|
1449
|
-
cells: number[];
|
|
1450
|
-
/** Original maze strings */
|
|
1451
|
-
maze?: string[];
|
|
1452
|
-
/** Additional maze metadata */
|
|
1453
|
-
[key: string]: unknown;
|
|
1454
|
-
}
|
|
1455
|
-
|
|
1456
|
-
/** Position in maze */
|
|
1457
|
-
export interface MazePosition {
|
|
1458
|
-
/** X coordinate */
|
|
1459
|
-
x: number;
|
|
1460
|
-
/** Y coordinate */
|
|
1461
|
-
y: number;
|
|
1462
|
-
}
|
|
1463
|
-
|
|
1464
|
-
/** Distance map for pathfinding */
|
|
1465
|
-
export interface MazeDistanceMap {
|
|
1466
|
-
/** Map width */
|
|
1467
|
-
width: number;
|
|
1468
|
-
/** Map height */
|
|
1469
|
-
height: number;
|
|
1470
|
-
/** Flattened distance values */
|
|
1471
|
-
distances: number[];
|
|
1472
|
-
}
|
|
1473
|
-
|
|
1474
|
-
/** Ring state for logits tracking */
|
|
1475
|
-
export interface LogitsRingState {
|
|
1476
|
-
/** Current ring capacity */
|
|
1477
|
-
logitsRingCap: number;
|
|
1478
|
-
/** Whether ring is shared */
|
|
1479
|
-
logitsRingShared: boolean;
|
|
1480
|
-
/** Ring write pointer */
|
|
1481
|
-
scratchLogitsRingW: number;
|
|
1482
|
-
}
|
|
1483
|
-
|
|
1484
|
-
/** Simulation result */
|
|
1485
|
-
export interface SimulationResult {
|
|
1486
|
-
/** Generation result data */
|
|
1487
|
-
generationResult: IMazeRunResult;
|
|
1488
|
-
/** Simulation time in milliseconds */
|
|
1489
|
-
simTime: number;
|
|
1490
|
-
/** Updated ring state */
|
|
1491
|
-
updatedRingState: LogitsRingState;
|
|
1492
|
-
}
|