@reicek/neataptic-ts 0.1.21 → 0.1.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/agents/boundary-mapper.agent.md +29 -0
- package/.github/agents/docs-scout.agent.md +29 -0
- package/.github/agents/plan-scout.agent.md +29 -0
- package/.github/agents/solid-split.agent.md +138 -0
- package/.github/copilot-instructions.md +103 -0
- package/package.json +6 -3
- package/plans/ES2023 migration +13 -8
- package/plans/Evolution_Training_Interoperability_Contracts.md +1 -1
- package/plans/Interactive_Examples_and_Learning_Path.md +10 -2
- package/plans/Memory_Optimization.md +3 -3
- package/plans/README.md +63 -0
- package/plans/Roadmap.md +15 -3
- package/plans/asciiMaze_SOLID_split.done.md +130 -0
- package/plans/flappy_bird_SOLID_split.done.md +67 -0
- package/scripts/assets/theme.css +221 -34
- package/scripts/copy-examples.mjs +9 -5
- package/scripts/export-onnx.mjs +3 -3
- package/scripts/generate-bench-tables.mjs +10 -10
- package/scripts/generate-bench-tables.ts +10 -10
- package/scripts/generate-docs.ts +1415 -449
- package/scripts/render-docs-html.ts +15 -8
- package/src/README.md +101 -223
- package/src/architecture/README.md +57 -185
- package/src/architecture/layer/README.md +38 -38
- package/src/architecture/network/README.md +33 -31
- package/src/architecture/network/activate/README.md +77 -77
- package/src/architecture/network/connect/README.md +15 -13
- package/src/architecture/network/deterministic/README.md +7 -7
- package/src/architecture/network/evolve/README.md +44 -44
- package/src/architecture/network/gating/README.md +20 -20
- package/src/architecture/network/genetic/README.md +51 -51
- package/src/architecture/network/mutate/README.md +97 -97
- package/src/architecture/network/onnx/README.md +264 -264
- package/src/architecture/network/prune/README.md +39 -39
- package/src/architecture/network/remove/README.md +26 -26
- package/src/architecture/network/serialize/README.md +56 -56
- package/src/architecture/network/slab/README.md +61 -61
- package/src/architecture/network/standalone/README.md +24 -24
- package/src/architecture/network/stats/README.md +9 -9
- package/src/architecture/network/topology/README.md +46 -46
- package/src/architecture/network/training/README.md +21 -21
- package/src/methods/README.md +9 -87
- package/src/multithreading/README.md +8 -77
- package/src/multithreading/workers/README.md +2 -2
- package/src/multithreading/workers/browser/README.md +0 -6
- package/src/multithreading/workers/node/README.md +0 -3
- package/src/neat/README.md +562 -568
- package/src/utils/README.md +18 -18
- package/test/examples/asciiMaze/README.md +59 -59
- package/test/examples/asciiMaze/asciiMaze.e2e.test.ts +14 -9
- package/test/examples/asciiMaze/browser-entry/README.md +196 -0
- package/test/examples/asciiMaze/browser-entry/browser-entry.abort.services.ts +95 -0
- package/test/examples/asciiMaze/browser-entry/browser-entry.constants.ts +23 -0
- package/test/examples/asciiMaze/browser-entry/browser-entry.curriculum.services.ts +115 -0
- package/test/examples/asciiMaze/browser-entry/browser-entry.globals.services.ts +106 -0
- package/test/examples/asciiMaze/browser-entry/browser-entry.host.services.ts +157 -0
- package/test/examples/asciiMaze/browser-entry/browser-entry.services.ts +14 -0
- package/test/examples/asciiMaze/browser-entry/browser-entry.ts +129 -0
- package/test/examples/asciiMaze/browser-entry/browser-entry.types.ts +120 -0
- package/test/examples/asciiMaze/browser-entry/browser-entry.utils.ts +98 -0
- package/test/examples/asciiMaze/browser-entry.ts +10 -576
- package/test/examples/asciiMaze/dashboardManager/README.md +276 -0
- package/test/examples/asciiMaze/dashboardManager/archive/README.md +16 -0
- package/test/examples/asciiMaze/dashboardManager/archive/dashboardManager.archive.services.ts +267 -0
- package/test/examples/asciiMaze/dashboardManager/dashboardManager.constants.ts +35 -0
- package/test/examples/asciiMaze/dashboardManager/dashboardManager.services.ts +103 -0
- package/test/examples/asciiMaze/dashboardManager/dashboardManager.ts +181 -0
- package/test/examples/asciiMaze/dashboardManager/dashboardManager.types.ts +267 -0
- package/test/examples/asciiMaze/dashboardManager/dashboardManager.utils.ts +254 -0
- package/test/examples/asciiMaze/dashboardManager/live/README.md +14 -0
- package/test/examples/asciiMaze/dashboardManager/live/dashboardManager.live.services.ts +264 -0
- package/test/examples/asciiMaze/dashboardManager/telemetry/README.md +47 -0
- package/test/examples/asciiMaze/dashboardManager/telemetry/dashboardManager.telemetry.services.ts +513 -0
- package/test/examples/asciiMaze/dashboardManager.ts +13 -2335
- package/test/examples/asciiMaze/evolutionEngine/README.md +1058 -0
- package/test/examples/asciiMaze/evolutionEngine/curriculumPhase.ts +90 -0
- package/test/examples/asciiMaze/evolutionEngine/engineState.constants.ts +36 -0
- package/test/examples/asciiMaze/evolutionEngine/engineState.ts +58 -513
- package/test/examples/asciiMaze/evolutionEngine/engineState.types.ts +212 -0
- package/test/examples/asciiMaze/evolutionEngine/engineState.utils.ts +301 -0
- package/test/examples/asciiMaze/evolutionEngine/evolutionEngine.types.ts +445 -0
- package/test/examples/asciiMaze/evolutionEngine/evolutionLoop.ts +81 -50
- package/test/examples/asciiMaze/evolutionEngine/optionsAndSetup.ts +2 -4
- package/test/examples/asciiMaze/evolutionEngine/populationDynamics.ts +17 -33
- package/test/examples/asciiMaze/evolutionEngine/populationPruning.ts +1 -1
- package/test/examples/asciiMaze/evolutionEngine/rngAndTiming.ts +1 -2
- package/test/examples/asciiMaze/evolutionEngine/sampling.ts +1 -1
- package/test/examples/asciiMaze/evolutionEngine/scratchPools.ts +2 -5
- package/test/examples/asciiMaze/evolutionEngine/setupHelpers.ts +30 -37
- package/test/examples/asciiMaze/evolutionEngine/telemetryMetrics.ts +16 -58
- package/test/examples/asciiMaze/evolutionEngine/trainingWarmStart.ts +2 -2
- package/test/examples/asciiMaze/evolutionEngine.ts +55 -55
- package/test/examples/asciiMaze/fitness.ts +2 -2
- package/test/examples/asciiMaze/fitness.types.ts +65 -0
- package/test/examples/asciiMaze/interfaces.ts +64 -1352
- package/test/examples/asciiMaze/mazeMovement/README.md +356 -0
- package/test/examples/asciiMaze/mazeMovement/finalization/README.md +49 -0
- package/test/examples/asciiMaze/mazeMovement/finalization/mazeMovement.finalization.ts +138 -0
- package/test/examples/asciiMaze/mazeMovement/mazeMovement.constants.ts +101 -0
- package/test/examples/asciiMaze/mazeMovement/mazeMovement.services.ts +230 -0
- package/test/examples/asciiMaze/mazeMovement/mazeMovement.ts +299 -0
- package/test/examples/asciiMaze/mazeMovement/mazeMovement.types.ts +185 -0
- package/test/examples/asciiMaze/mazeMovement/mazeMovement.utils.ts +153 -0
- package/test/examples/asciiMaze/mazeMovement/policy/README.md +91 -0
- package/test/examples/asciiMaze/mazeMovement/policy/mazeMovement.policy.ts +467 -0
- package/test/examples/asciiMaze/mazeMovement/runtime/README.md +95 -0
- package/test/examples/asciiMaze/mazeMovement/runtime/mazeMovement.runtime.ts +354 -0
- package/test/examples/asciiMaze/mazeMovement/shaping/README.md +124 -0
- package/test/examples/asciiMaze/mazeMovement/shaping/mazeMovement.shaping.ts +459 -0
- package/test/examples/asciiMaze/mazeMovement.ts +12 -2978
- package/test/examples/flappy_bird/Trace-20260309T191949.json +24124 -0
- package/test/examples/flappy_bird/browser-entry/README.md +1129 -0
- package/test/examples/flappy_bird/browser-entry/browser-entry.host.utils.ts +4 -324
- package/test/examples/flappy_bird/browser-entry/browser-entry.network-view.utils.ts +6 -399
- package/test/examples/flappy_bird/browser-entry/browser-entry.playback.utils.ts +1 -717
- package/test/examples/flappy_bird/browser-entry/browser-entry.spawn.utils.ts +11 -31
- package/test/examples/flappy_bird/browser-entry/browser-entry.visualization.utils.ts +15 -893
- package/test/examples/flappy_bird/browser-entry/host/README.md +307 -0
- package/test/examples/flappy_bird/browser-entry/host/host.resize.service.ts +1 -295
- package/test/examples/flappy_bird/browser-entry/host/host.ts +562 -6
- package/test/examples/flappy_bird/browser-entry/host/resize/README.md +274 -0
- package/test/examples/flappy_bird/browser-entry/host/resize/host.resize.service.constants.ts +31 -0
- package/test/examples/flappy_bird/browser-entry/host/resize/host.resize.service.services.ts +360 -0
- package/test/examples/flappy_bird/browser-entry/host/resize/host.resize.service.ts +117 -0
- package/test/examples/flappy_bird/browser-entry/host/resize/host.resize.service.types.ts +63 -0
- package/test/examples/flappy_bird/browser-entry/host/resize/host.resize.service.utils.ts +250 -0
- package/test/examples/flappy_bird/browser-entry/network-view/README.md +399 -0
- package/test/examples/flappy_bird/browser-entry/network-view/network-view.topology.utils.ts +255 -0
- package/test/examples/flappy_bird/browser-entry/network-view/network-view.ts +802 -7
- package/test/examples/flappy_bird/browser-entry/playback/README.md +684 -0
- package/test/examples/flappy_bird/browser-entry/playback/background/README.md +277 -0
- package/test/examples/flappy_bird/browser-entry/playback/background/ground-grid/README.md +770 -0
- package/test/examples/flappy_bird/browser-entry/playback/background/ground-grid/playback.background.ground-grid.cache.services.ts +178 -0
- package/test/examples/flappy_bird/browser-entry/playback/background/ground-grid/playback.background.ground-grid.constants.ts +107 -0
- package/test/examples/flappy_bird/browser-entry/playback/background/ground-grid/playback.background.ground-grid.geometry.utils.ts +518 -0
- package/test/examples/flappy_bird/browser-entry/playback/background/ground-grid/playback.background.ground-grid.math.utils.ts +117 -0
- package/test/examples/flappy_bird/browser-entry/playback/background/ground-grid/playback.background.ground-grid.pulse.utils.ts +233 -0
- package/test/examples/flappy_bird/browser-entry/playback/background/ground-grid/playback.background.ground-grid.services.ts +211 -0
- package/test/examples/flappy_bird/browser-entry/playback/background/ground-grid/playback.background.ground-grid.ts +48 -0
- package/test/examples/flappy_bird/browser-entry/playback/background/ground-grid/playback.background.ground-grid.types.ts +212 -0
- package/test/examples/flappy_bird/browser-entry/playback/background/ground-grid/playback.background.ground-grid.utils.ts +81 -0
- package/test/examples/flappy_bird/browser-entry/playback/background/playback.background.cache.services.ts +96 -0
- package/test/examples/flappy_bird/browser-entry/playback/background/playback.background.constants.ts +62 -0
- package/test/examples/flappy_bird/browser-entry/playback/background/playback.background.services.ts +244 -0
- package/test/examples/flappy_bird/browser-entry/playback/background/playback.background.ts +53 -0
- package/test/examples/flappy_bird/browser-entry/playback/background/playback.background.types.ts +68 -0
- package/test/examples/flappy_bird/browser-entry/playback/background/playback.background.utils.ts +100 -0
- package/test/examples/flappy_bird/browser-entry/playback/frame-render/README.md +310 -0
- package/test/examples/flappy_bird/browser-entry/playback/frame-render/playback.frame-render.service.ts +92 -0
- package/test/examples/flappy_bird/browser-entry/playback/frame-render/playback.frame-render.services.ts +272 -0
- package/test/examples/flappy_bird/browser-entry/playback/frame-render/playback.frame-render.types.ts +39 -0
- package/test/examples/flappy_bird/browser-entry/playback/frame-render/playback.frame-render.utils.ts +493 -0
- package/test/examples/flappy_bird/browser-entry/playback/playback.constants.ts +1 -1
- package/test/examples/flappy_bird/browser-entry/playback/playback.frame-render.service.ts +4 -0
- package/test/examples/flappy_bird/browser-entry/playback/playback.snapshot.utils.ts +44 -0
- package/test/examples/flappy_bird/browser-entry/playback/playback.starfield.service.ts +39 -122
- package/test/examples/flappy_bird/browser-entry/playback/playback.starfield.services.ts +272 -0
- package/test/examples/flappy_bird/browser-entry/playback/playback.starfield.types.ts +62 -0
- package/test/examples/flappy_bird/browser-entry/playback/playback.starfield.utils.ts +11 -4
- package/test/examples/flappy_bird/browser-entry/playback/playback.ts +409 -8
- package/test/examples/flappy_bird/browser-entry/playback/playback.types.ts +4 -12
- package/test/examples/flappy_bird/browser-entry/runtime/README.md +235 -0
- package/test/examples/flappy_bird/browser-entry/runtime/runtime.evolution-launch.service.ts +45 -0
- package/test/examples/flappy_bird/browser-entry/runtime/runtime.lifecycle.service.ts +81 -0
- package/test/examples/flappy_bird/browser-entry/runtime/runtime.startup.service.ts +74 -0
- package/test/examples/flappy_bird/browser-entry/runtime/runtime.ts +31 -121
- package/test/examples/flappy_bird/browser-entry/runtime/runtime.types.ts +36 -0
- package/test/examples/flappy_bird/browser-entry/visualization/README.md +557 -0
- package/test/examples/flappy_bird/browser-entry/visualization/visualization.constants.ts +110 -0
- package/test/examples/flappy_bird/browser-entry/visualization/visualization.draw.service.ts +957 -19
- package/test/examples/flappy_bird/browser-entry/visualization/visualization.legend.utils.ts +138 -3
- package/test/examples/flappy_bird/browser-entry/visualization/visualization.topology.utils.ts +3 -27
- package/test/examples/flappy_bird/browser-entry/visualization/visualization.ts +1 -23
- package/test/examples/flappy_bird/browser-entry/worker-channel/README.md +156 -0
- package/test/examples/flappy_bird/constants/README.md +1179 -0
- package/test/examples/flappy_bird/constants/constants.network-view.ts +24 -0
- package/test/examples/flappy_bird/constants/constants.palette.ts +7 -0
- package/test/examples/flappy_bird/constants/constants.starfield.ts +78 -3
- package/test/examples/flappy_bird/environment/README.md +143 -0
- package/test/examples/flappy_bird/environment/environment.observation.utils.ts +1 -19
- package/test/examples/flappy_bird/environment/environment.step.service.ts +3 -66
- package/test/examples/flappy_bird/evaluation/README.md +130 -0
- package/test/examples/flappy_bird/evaluation/evaluation.fitness.utils.ts +1 -1
- package/test/examples/flappy_bird/evaluation/evaluation.rollout.service.ts +5 -375
- package/test/examples/flappy_bird/evaluation/rollout/README.md +291 -0
- package/test/examples/flappy_bird/evaluation/rollout/evaluation.rollout.constants.ts +30 -0
- package/test/examples/flappy_bird/evaluation/rollout/evaluation.rollout.service.ts +58 -0
- package/test/examples/flappy_bird/evaluation/rollout/evaluation.rollout.services.ts +310 -0
- package/test/examples/flappy_bird/evaluation/rollout/evaluation.rollout.types.ts +56 -0
- package/test/examples/flappy_bird/evaluation/rollout/evaluation.rollout.utils.ts +368 -0
- package/test/examples/flappy_bird/flappy-evolution-worker/README.md +618 -0
- package/test/examples/flappy_bird/flappy-evolution-worker/flappy-evolution-worker.playback.service.ts +7 -7
- package/test/examples/flappy_bird/flappy-evolution-worker/flappy-evolution-worker.simulation.frame.service.ts +364 -0
- package/test/examples/flappy_bird/flappy-evolution-worker/flappy-evolution-worker.simulation.types.ts +14 -0
- package/test/examples/flappy_bird/flappy-evolution-worker/flappy-evolution-worker.simulation.utils.ts +4 -201
- package/test/examples/flappy_bird/flappy-evolution-worker/flappy-evolution-worker.ts +184 -345
- package/test/examples/flappy_bird/flappy-evolution-worker/flappy-evolution-worker.warm-start.service.ts +291 -0
- package/test/examples/flappy_bird/flappy.simulation.shared.utils.ts +5 -0
- package/test/examples/flappy_bird/simulation-shared/README.md +417 -0
- package/test/examples/flappy_bird/simulation-shared/observation/README.md +183 -0
- package/test/examples/flappy_bird/simulation-shared/observation/observation.features.utils.ts +301 -0
- package/test/examples/flappy_bird/simulation-shared/observation/observation.ts +9 -0
- package/test/examples/flappy_bird/simulation-shared/observation/observation.vector.utils.ts +59 -0
- package/test/examples/flappy_bird/simulation-shared/simulation-shared.observation.utils.ts +5 -403
- package/test/examples/flappy_bird/simulation-shared/simulation-shared.spawn.utils.ts +20 -6
- package/test/examples/flappy_bird/{evaluation/evaluation.statistics.utils.ts → simulation-shared/simulation-shared.statistics.utils.ts} +23 -8
- package/test/examples/flappy_bird/trainer/README.md +563 -0
- package/test/examples/flappy_bird/trainer/evaluation/README.md +199 -0
- package/test/examples/flappy_bird/trainer/evaluation/trainer.evaluation.service.constants.ts +9 -0
- package/test/examples/flappy_bird/trainer/evaluation/trainer.evaluation.service.services.ts +73 -0
- package/test/examples/flappy_bird/trainer/evaluation/trainer.evaluation.service.ts +165 -0
- package/test/examples/flappy_bird/trainer/evaluation/trainer.evaluation.service.types.ts +25 -0
- package/test/examples/flappy_bird/trainer/evaluation/trainer.evaluation.service.utils.ts +161 -0
- package/test/examples/flappy_bird/trainer/trainer.evaluation.service.ts +13 -0
- package/test/examples/flappy_bird/trainer/trainer.report.service.services.ts +181 -0
- package/test/examples/flappy_bird/trainer/trainer.report.service.ts +126 -0
- package/test/examples/flappy_bird/trainer/trainer.selection.utils.ts +89 -0
- package/test/examples/flappy_bird/trainer/trainer.ts +11 -553
- package/test/examples/flappy_bird/browser-entry/browser-entry.utils.ts +0 -12
- package/test/examples/flappy_bird/environment/environment.ts +0 -7
- package/test/examples/flappy_bird/evaluation/evaluation.ts +0 -7
- package/test/examples/flappy_bird/simulation-shared/simulation-shared.ts +0 -15
- package/test/examples/flappy_bird/trainer/trainer.statistics.utils.ts +0 -78
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
# mazeMovement
|
|
2
|
+
|
|
3
|
+
## mazeMovement/mazeMovement.types.ts
|
|
4
|
+
|
|
5
|
+
### mazeMovement.types
|
|
6
|
+
|
|
7
|
+
Shared type surface for the dedicated mazeMovement module.
|
|
8
|
+
|
|
9
|
+
Step 2 moves internal simulation contracts here first so later helper files
|
|
10
|
+
can depend on one narrow typed surface.
|
|
11
|
+
|
|
12
|
+
### DirectionSelectionStats
|
|
13
|
+
|
|
14
|
+
Diagnostic telemetry produced when selecting a direction from network logits.
|
|
15
|
+
|
|
16
|
+
Encapsulates the chosen direction along with entropy and probability data so
|
|
17
|
+
downstream helpers can apply shaping rewards and penalties without
|
|
18
|
+
rederiving softmax statistics on hot paths.
|
|
19
|
+
|
|
20
|
+
### MazeMovementBufferPools
|
|
21
|
+
|
|
22
|
+
Shared type surface for the dedicated mazeMovement module.
|
|
23
|
+
|
|
24
|
+
Step 2 moves internal simulation contracts here first so later helper files
|
|
25
|
+
can depend on one narrow typed surface.
|
|
26
|
+
|
|
27
|
+
### MazeMovementRunServiceState
|
|
28
|
+
|
|
29
|
+
Mutable run-scoped service state shared by the mazeMovement facade.
|
|
30
|
+
|
|
31
|
+
The dedicated services module owns these counters so later runtime, policy,
|
|
32
|
+
and shaping helpers can depend on one explicit mutable surface instead of
|
|
33
|
+
directly reaching into class-private state.
|
|
34
|
+
|
|
35
|
+
### MazeMovementSimulationResult
|
|
36
|
+
|
|
37
|
+
Result shape returned by `MazeMovement.simulateAgent`.
|
|
38
|
+
|
|
39
|
+
This contract matches the legacy inline return annotation so callers can
|
|
40
|
+
keep depending on the current fields while the dedicated module boundary is
|
|
41
|
+
being extracted.
|
|
42
|
+
|
|
43
|
+
### SimulationState
|
|
44
|
+
|
|
45
|
+
Internal aggregate state used during a single agent simulation run.
|
|
46
|
+
|
|
47
|
+
Purpose:
|
|
48
|
+
- Hold all derived runtime values, counters and diagnostic stats used by the
|
|
49
|
+
MazeMovement simulation helpers. This shape is intentionally rich so tests
|
|
50
|
+
and visualisers can inspect intermediate state when debugging.
|
|
51
|
+
|
|
52
|
+
Notes:
|
|
53
|
+
- This interface remains internal to the mazeMovement module boundary.
|
|
54
|
+
- Property descriptions are explicit to surface helpful tooltips in editors.
|
|
55
|
+
|
|
56
|
+
## mazeMovement/mazeMovement.ts
|
|
57
|
+
|
|
58
|
+
### mazeMovement
|
|
59
|
+
|
|
60
|
+
Public MazeMovement facade for the dedicated mazeMovement module boundary.
|
|
61
|
+
|
|
62
|
+
The folder now owns runtime helpers, policy helpers, shaping helpers, and
|
|
63
|
+
finalization logic. This file keeps the user-facing API in one place while
|
|
64
|
+
the implementation stays split into focused helpers.
|
|
65
|
+
|
|
66
|
+
### MazeMovement
|
|
67
|
+
|
|
68
|
+
Maze movement entry surface used by fitness evaluation and evolution runs.
|
|
69
|
+
|
|
70
|
+
The public API intentionally remains class-based so existing example imports
|
|
71
|
+
do not change while the implementation lives under the dedicated module.
|
|
72
|
+
|
|
73
|
+
#### #COORDINATE_SCRATCH
|
|
74
|
+
|
|
75
|
+
Reused integer coordinate scratch for hot-path movement helpers.
|
|
76
|
+
|
|
77
|
+
#### #hasReachedExit
|
|
78
|
+
|
|
79
|
+
`(simulationState: import("test/examples/asciiMaze/mazeMovement/mazeMovement.types").SimulationState, exitPos: readonly [number, number]) => boolean`
|
|
80
|
+
|
|
81
|
+
Determine whether the current state has reached the maze exit.
|
|
82
|
+
|
|
83
|
+
Parameters:
|
|
84
|
+
- `simulationState` - - Mutable run state for the active episode.
|
|
85
|
+
- `exitPos` - - Exit coordinate for the run.
|
|
86
|
+
|
|
87
|
+
Returns: True when the agent position matches the exit coordinate.
|
|
88
|
+
|
|
89
|
+
#### #processMovementAndShaping
|
|
90
|
+
|
|
91
|
+
`(simulationState: import("test/examples/asciiMaze/mazeMovement/mazeMovement.types").SimulationState, encodedMaze: number[][], distanceMap: number[][] | undefined) => boolean`
|
|
92
|
+
|
|
93
|
+
Execute the selected move, apply post-action shaping, and evaluate stop rules.
|
|
94
|
+
|
|
95
|
+
Parameters:
|
|
96
|
+
- `simulationState` - - Mutable run state for the active episode.
|
|
97
|
+
- `encodedMaze` - - Maze grid used for movement and distance lookup.
|
|
98
|
+
- `distanceMap` - - Optional precomputed distance map.
|
|
99
|
+
|
|
100
|
+
Returns: True when the episode should stop after this step.
|
|
101
|
+
|
|
102
|
+
#### #processPerceptionAndPolicy
|
|
103
|
+
|
|
104
|
+
`(simulationState: import("test/examples/asciiMaze/mazeMovement/mazeMovement.types").SimulationState, network: import("test/examples/asciiMaze/interfaces").INetwork, encodedMaze: number[][], exitPos: readonly [number, number], distanceMap: number[][] | undefined) => void`
|
|
105
|
+
|
|
106
|
+
Refresh visit bookkeeping, perception state, and direction policy.
|
|
107
|
+
|
|
108
|
+
Parameters:
|
|
109
|
+
- `simulationState` - - Mutable run state for the active episode.
|
|
110
|
+
- `network` - - Policy network used for action selection.
|
|
111
|
+
- `encodedMaze` - - Maze grid used for the run.
|
|
112
|
+
- `exitPos` - - Exit coordinate for the run.
|
|
113
|
+
- `distanceMap` - - Optional precomputed distance map.
|
|
114
|
+
|
|
115
|
+
#### moveAgent
|
|
116
|
+
|
|
117
|
+
`(encodedMaze: readonly (readonly number[])[], position: readonly [number, number], direction: number) => [number, number]`
|
|
118
|
+
|
|
119
|
+
Move the agent one step in the requested direction when the target cell is open.
|
|
120
|
+
|
|
121
|
+
Parameters:
|
|
122
|
+
- `encodedMaze` - - Maze grid used for collision checks.
|
|
123
|
+
- `position` - - Current agent position.
|
|
124
|
+
- `direction` - - Direction index in the action space.
|
|
125
|
+
|
|
126
|
+
Returns: New position when the move is valid, otherwise the original position.
|
|
127
|
+
|
|
128
|
+
#### selectDirection
|
|
129
|
+
|
|
130
|
+
`(outputs: number[]) => import("test/examples/asciiMaze/mazeMovement/mazeMovement.types").DirectionSelectionStats`
|
|
131
|
+
|
|
132
|
+
Convert raw network outputs into a chosen action plus diagnostics.
|
|
133
|
+
|
|
134
|
+
Parameters:
|
|
135
|
+
- `outputs` - - Raw action logits for the four maze directions.
|
|
136
|
+
|
|
137
|
+
Returns: Chosen direction plus softmax and entropy diagnostics.
|
|
138
|
+
|
|
139
|
+
#### simulateAgent
|
|
140
|
+
|
|
141
|
+
`(network: import("test/examples/asciiMaze/interfaces").INetwork, encodedMaze: number[][], startPos: readonly [number, number], exitPos: readonly [number, number], distanceMap: number[][] | undefined, maxSteps: number) => import("test/examples/asciiMaze/mazeMovement/mazeMovement.types").MazeMovementSimulationResult`
|
|
142
|
+
|
|
143
|
+
Simulate one full maze episode for a network-controlled agent.
|
|
144
|
+
|
|
145
|
+
Parameters:
|
|
146
|
+
- `network` - - Policy network used to choose actions.
|
|
147
|
+
- `encodedMaze` - - Maze grid for the active episode.
|
|
148
|
+
- `startPos` - - Start coordinate.
|
|
149
|
+
- `exitPos` - - Exit coordinate.
|
|
150
|
+
- `distanceMap` - - Optional precomputed distance map.
|
|
151
|
+
- `maxSteps` - - Maximum allowed step count before termination.
|
|
152
|
+
|
|
153
|
+
Returns: Final simulation result including path, fitness, and progress.
|
|
154
|
+
|
|
155
|
+
## mazeMovement/mazeMovement.services.ts
|
|
156
|
+
|
|
157
|
+
### mazeMovement.services
|
|
158
|
+
|
|
159
|
+
Shared mutable services for the dedicated mazeMovement module.
|
|
160
|
+
|
|
161
|
+
This module owns the pooled buffers, PRNG state, output-history plumbing,
|
|
162
|
+
and shared run-scoped counters used by the legacy MazeMovement facade while
|
|
163
|
+
Step 2 incrementally moves helper categories into the dedicated boundary.
|
|
164
|
+
|
|
165
|
+
### getMazeMovementBufferMetadata
|
|
166
|
+
|
|
167
|
+
`() => { cachedWidth: number; cachedHeight: number; }`
|
|
168
|
+
|
|
169
|
+
Read the currently cached maze dimensions for bounds and index helpers.
|
|
170
|
+
|
|
171
|
+
Returns: Cached width and height for the active pooled buffers.
|
|
172
|
+
|
|
173
|
+
### getMazeMovementRunServiceState
|
|
174
|
+
|
|
175
|
+
`() => import("test/examples/asciiMaze/mazeMovement/mazeMovement.types").MazeMovementRunServiceState`
|
|
176
|
+
|
|
177
|
+
Expose the shared mutable run-scoped state used across helper categories.
|
|
178
|
+
|
|
179
|
+
Returns: The singleton mutable run-state object for the current process.
|
|
180
|
+
|
|
181
|
+
### indexMazeMovementCell
|
|
182
|
+
|
|
183
|
+
`(x: number, y: number) => number`
|
|
184
|
+
|
|
185
|
+
Convert a cell coordinate into the pooled linear grid index.
|
|
186
|
+
|
|
187
|
+
Parameters:
|
|
188
|
+
- `x` - - Zero-based maze column.
|
|
189
|
+
- `y` - - Zero-based maze row.
|
|
190
|
+
|
|
191
|
+
Returns: Linearized index used by pooled grid buffers.
|
|
192
|
+
|
|
193
|
+
### initializeMazeMovementBufferPools
|
|
194
|
+
|
|
195
|
+
`(width: number, height: number, maxSteps: number) => import("test/examples/asciiMaze/mazeMovement/mazeMovement.types").MazeMovementBufferPools`
|
|
196
|
+
|
|
197
|
+
Ensure the pooled grid and path buffers are initialized for a run.
|
|
198
|
+
|
|
199
|
+
Parameters:
|
|
200
|
+
- `width` - - Maze width in cells.
|
|
201
|
+
- `height` - - Maze height in cells.
|
|
202
|
+
- `maxSteps` - - Maximum path length expected for the run.
|
|
203
|
+
|
|
204
|
+
Returns: The initialized pooled buffer surface.
|
|
205
|
+
|
|
206
|
+
### materializeMazeMovementPath
|
|
207
|
+
|
|
208
|
+
`(length: number) => [number, number][]`
|
|
209
|
+
|
|
210
|
+
Materialize the active pooled path buffers into a fresh tuple array.
|
|
211
|
+
|
|
212
|
+
Parameters:
|
|
213
|
+
- `length` - - Number of active path entries to copy.
|
|
214
|
+
|
|
215
|
+
Returns: A newly allocated materialized path snapshot.
|
|
216
|
+
|
|
217
|
+
### randomMazeMovementUnit
|
|
218
|
+
|
|
219
|
+
`() => number`
|
|
220
|
+
|
|
221
|
+
Generate a pseudo-random number in the range `[0, 1)`.
|
|
222
|
+
|
|
223
|
+
Returns: A deterministic or host-random unit float for exploration logic.
|
|
224
|
+
|
|
225
|
+
### readMazeMovementOutputHistory
|
|
226
|
+
|
|
227
|
+
`(network: import("test/examples/asciiMaze/interfaces").INetwork) => number[][] | undefined`
|
|
228
|
+
|
|
229
|
+
Read the reflected `_lastStepOutputs` network history when present.
|
|
230
|
+
|
|
231
|
+
Parameters:
|
|
232
|
+
- `network` - - Network that may carry the reflected output history.
|
|
233
|
+
|
|
234
|
+
Returns: Sanitized output history or `undefined` when absent or invalid.
|
|
235
|
+
|
|
236
|
+
### requireMazeMovementBufferPools
|
|
237
|
+
|
|
238
|
+
`() => import("test/examples/asciiMaze/mazeMovement/mazeMovement.types").MazeMovementBufferPools`
|
|
239
|
+
|
|
240
|
+
Return the initialized pooled buffer surface for the current run.
|
|
241
|
+
|
|
242
|
+
Returns: The shared buffer pools.
|
|
243
|
+
|
|
244
|
+
### resetMazeMovementRunServiceState
|
|
245
|
+
|
|
246
|
+
`() => import("test/examples/asciiMaze/mazeMovement/mazeMovement.types").MazeMovementRunServiceState`
|
|
247
|
+
|
|
248
|
+
Reset the shared mutable run-scoped state before a new simulation begins.
|
|
249
|
+
|
|
250
|
+
Returns: The reused singleton state after reset.
|
|
251
|
+
|
|
252
|
+
### writeMazeMovementOutputHistory
|
|
253
|
+
|
|
254
|
+
`(network: import("test/examples/asciiMaze/interfaces").INetwork, history: number[][]) => void`
|
|
255
|
+
|
|
256
|
+
Persist the reflected `_lastStepOutputs` network history.
|
|
257
|
+
|
|
258
|
+
Parameters:
|
|
259
|
+
- `network` - - Network receiving the reflected output history.
|
|
260
|
+
- `history` - - Bounded output-history payload to persist.
|
|
261
|
+
|
|
262
|
+
## mazeMovement/mazeMovement.constants.ts
|
|
263
|
+
|
|
264
|
+
### mazeMovement.constants
|
|
265
|
+
|
|
266
|
+
Frozen tuning surface for the dedicated mazeMovement module.
|
|
267
|
+
|
|
268
|
+
This constant table keeps simulation policy, shaping thresholds, and lookup
|
|
269
|
+
tables in one place so the public facade can stay focused on orchestration.
|
|
270
|
+
|
|
271
|
+
### MAZE_MOVEMENT_CONSTANTS
|
|
272
|
+
|
|
273
|
+
## mazeMovement/mazeMovement.utils.ts
|
|
274
|
+
|
|
275
|
+
### computeActionEntropyFromCounts
|
|
276
|
+
|
|
277
|
+
`(directionCounts: number[], logActions: number, scratch: Float64Array<ArrayBufferLike>) => number`
|
|
278
|
+
|
|
279
|
+
Compute normalized action entropy from direction counts.
|
|
280
|
+
|
|
281
|
+
Parameters:
|
|
282
|
+
- `directionCounts` - - Number of moves taken in each direction.
|
|
283
|
+
- `logActions` - - Precomputed normalization factor for the action space.
|
|
284
|
+
- `scratch` - - Single-value floating-point scratch buffer reused by the caller.
|
|
285
|
+
|
|
286
|
+
Returns: Normalized entropy in the range `[0, 1]`.
|
|
287
|
+
|
|
288
|
+
### isFiniteNumberArray
|
|
289
|
+
|
|
290
|
+
`(candidate: unknown) => boolean`
|
|
291
|
+
|
|
292
|
+
Determine whether the provided value is a finite-number array.
|
|
293
|
+
|
|
294
|
+
Parameters:
|
|
295
|
+
- `candidate` - - Value to inspect.
|
|
296
|
+
|
|
297
|
+
Returns: True when the input is an array of finite numbers.
|
|
298
|
+
|
|
299
|
+
### materializePath
|
|
300
|
+
|
|
301
|
+
`(length: number, pathX: Int32Array<ArrayBufferLike>, pathY: Int32Array<ArrayBufferLike>) => [number, number][]`
|
|
302
|
+
|
|
303
|
+
Materialize the active prefix of pooled path buffers into a fresh array.
|
|
304
|
+
|
|
305
|
+
Parameters:
|
|
306
|
+
- `length` - - Number of path entries to materialize.
|
|
307
|
+
- `pathX` - - Pooled X-coordinate buffer.
|
|
308
|
+
- `pathY` - - Pooled Y-coordinate buffer.
|
|
309
|
+
|
|
310
|
+
Returns: A newly allocated array of path tuples.
|
|
311
|
+
|
|
312
|
+
### nextPowerOfTwo
|
|
313
|
+
|
|
314
|
+
`(n: number) => number`
|
|
315
|
+
|
|
316
|
+
Return the smallest power-of-two integer greater than or equal to `n`.
|
|
317
|
+
|
|
318
|
+
Parameters:
|
|
319
|
+
- `n` - - Target minimum integer capacity.
|
|
320
|
+
|
|
321
|
+
Returns: The smallest power of two greater than or equal to `n`.
|
|
322
|
+
|
|
323
|
+
### readOutputHistory
|
|
324
|
+
|
|
325
|
+
`(network: import("test/examples/asciiMaze/interfaces").INetwork) => number[][] | undefined`
|
|
326
|
+
|
|
327
|
+
Read the optional `_lastStepOutputs` history stored on a network.
|
|
328
|
+
|
|
329
|
+
Parameters:
|
|
330
|
+
- `network` - - Network instance that may expose a reflected outputs history.
|
|
331
|
+
|
|
332
|
+
Returns: Sanitized history buffer or `undefined` when absent or invalid.
|
|
333
|
+
|
|
334
|
+
### sumVisionGroup
|
|
335
|
+
|
|
336
|
+
`(vision: number[], start: number, groupLength: number, scratch: Float64Array<ArrayBufferLike>) => number`
|
|
337
|
+
|
|
338
|
+
Sum a contiguous group of entries from a vision vector into a reusable scratch buffer.
|
|
339
|
+
|
|
340
|
+
Parameters:
|
|
341
|
+
- `vision` - - Flat perception vector.
|
|
342
|
+
- `start` - - Start index of the group to sum.
|
|
343
|
+
- `groupLength` - - Number of entries in the group.
|
|
344
|
+
- `scratch` - - Reusable scratch buffer populated with copied values.
|
|
345
|
+
|
|
346
|
+
Returns: Numeric sum of the selected group.
|
|
347
|
+
|
|
348
|
+
### writeOutputHistory
|
|
349
|
+
|
|
350
|
+
`(network: import("test/examples/asciiMaze/interfaces").INetwork, history: number[][]) => void`
|
|
351
|
+
|
|
352
|
+
Persist a bounded outputs history on the network via reflection.
|
|
353
|
+
|
|
354
|
+
Parameters:
|
|
355
|
+
- `network` - - Target network to mutate.
|
|
356
|
+
- `history` - - Updated history buffer.
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# mazeMovement/finalization
|
|
2
|
+
|
|
3
|
+
## mazeMovement/finalization/mazeMovement.finalization.ts
|
|
4
|
+
|
|
5
|
+
### mazeMovement.finalization
|
|
6
|
+
|
|
7
|
+
Result-finalization helpers for the dedicated mazeMovement module.
|
|
8
|
+
|
|
9
|
+
These helpers assemble the final simulation payload once the orchestration
|
|
10
|
+
facade has finished stepping the run. Keeping this logic here lets the main
|
|
11
|
+
facade stay focused on the episode loop rather than on score shaping math.
|
|
12
|
+
|
|
13
|
+
### computeMazeMovementActionEntropy
|
|
14
|
+
|
|
15
|
+
`(directionCounts: number[]) => number`
|
|
16
|
+
|
|
17
|
+
Compute the normalized action-entropy summary for a finished run.
|
|
18
|
+
|
|
19
|
+
Parameters:
|
|
20
|
+
- `directionCounts` - - Per-direction action counts recorded during the run.
|
|
21
|
+
|
|
22
|
+
Returns: Normalized entropy in the range `[0, 1]`.
|
|
23
|
+
|
|
24
|
+
### finalizeFailedMazeMovementRun
|
|
25
|
+
|
|
26
|
+
`(state: import("test/examples/asciiMaze/mazeMovement/mazeMovement.types").SimulationState, encodedMaze: number[][], startPos: readonly [number, number], exitPos: readonly [number, number], distanceMap: number[][] | undefined) => import("test/examples/asciiMaze/mazeMovement/mazeMovement.types").MazeMovementSimulationResult`
|
|
27
|
+
|
|
28
|
+
Build the finalized payload for a failed maze run.
|
|
29
|
+
|
|
30
|
+
Parameters:
|
|
31
|
+
- `state` - - Completed simulation state for the failed run.
|
|
32
|
+
- `encodedMaze` - - Maze grid used to compute fallback geometric progress.
|
|
33
|
+
- `startPos` - - Start coordinate for the current episode.
|
|
34
|
+
- `exitPos` - - Exit coordinate for the current episode.
|
|
35
|
+
- `distanceMap` - - Optional precomputed distance map aligned to the maze.
|
|
36
|
+
|
|
37
|
+
Returns: Failure result with shaped fitness, path, and diagnostic summaries.
|
|
38
|
+
|
|
39
|
+
### finalizeSuccessfulMazeMovementRun
|
|
40
|
+
|
|
41
|
+
`(state: import("test/examples/asciiMaze/mazeMovement/mazeMovement.types").SimulationState, maxSteps: number) => import("test/examples/asciiMaze/mazeMovement/mazeMovement.types").MazeMovementSimulationResult`
|
|
42
|
+
|
|
43
|
+
Build the finalized payload for a successful maze run.
|
|
44
|
+
|
|
45
|
+
Parameters:
|
|
46
|
+
- `state` - - Completed simulation state for the successful run.
|
|
47
|
+
- `maxSteps` - - Maximum allowed step budget for the run.
|
|
48
|
+
|
|
49
|
+
Returns: Success result with fitness, path, and diagnostic summaries.
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Result-finalization helpers for the dedicated mazeMovement module.
|
|
3
|
+
*
|
|
4
|
+
* These helpers assemble the final simulation payload once the orchestration
|
|
5
|
+
* facade has finished stepping the run. Keeping this logic here lets the main
|
|
6
|
+
* facade stay focused on the episode loop rather than on score shaping math.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { MazeUtils } from '../../mazeUtils';
|
|
10
|
+
import { MAZE_MOVEMENT_CONSTANTS } from '../mazeMovement.constants';
|
|
11
|
+
import {
|
|
12
|
+
materializeMazeMovementPath,
|
|
13
|
+
randomMazeMovementUnit,
|
|
14
|
+
} from '../mazeMovement.services';
|
|
15
|
+
import type {
|
|
16
|
+
MazeMovementSimulationResult,
|
|
17
|
+
SimulationState,
|
|
18
|
+
} from '../mazeMovement.types';
|
|
19
|
+
import { computeActionEntropyFromCounts } from '../mazeMovement.utils';
|
|
20
|
+
|
|
21
|
+
const C = MAZE_MOVEMENT_CONSTANTS;
|
|
22
|
+
const ACTION_ENTROPY_SCRATCH = new Float64Array(1);
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Build the finalized payload for a successful maze run.
|
|
26
|
+
*
|
|
27
|
+
* @param state - Completed simulation state for the successful run.
|
|
28
|
+
* @param maxSteps - Maximum allowed step budget for the run.
|
|
29
|
+
* @returns Success result with fitness, path, and diagnostic summaries.
|
|
30
|
+
*/
|
|
31
|
+
export function finalizeSuccessfulMazeMovementRun(
|
|
32
|
+
state: SimulationState,
|
|
33
|
+
maxSteps: number,
|
|
34
|
+
): MazeMovementSimulationResult {
|
|
35
|
+
const stepsTaken = state.steps | 0;
|
|
36
|
+
const stepEfficiency = (maxSteps | 0) - stepsTaken;
|
|
37
|
+
const actionEntropy = computeMazeMovementActionEntropy(state.directionCounts);
|
|
38
|
+
const baseFitness =
|
|
39
|
+
C.SUCCESS_BASE_FITNESS +
|
|
40
|
+
stepEfficiency * C.STEP_EFFICIENCY_SCALE +
|
|
41
|
+
state.progressReward +
|
|
42
|
+
state.newCellExplorationBonus +
|
|
43
|
+
state.invalidMovePenalty;
|
|
44
|
+
const totalFitness =
|
|
45
|
+
baseFitness + actionEntropy * C.SUCCESS_ACTION_ENTROPY_SCALE;
|
|
46
|
+
const pathSnapshot = materializeMazeMovementPath(state.pathLength);
|
|
47
|
+
const saturationFraction =
|
|
48
|
+
stepsTaken > 0 ? state.saturatedSteps / stepsTaken : 0;
|
|
49
|
+
|
|
50
|
+
return {
|
|
51
|
+
success: true,
|
|
52
|
+
steps: stepsTaken,
|
|
53
|
+
path: pathSnapshot,
|
|
54
|
+
fitness: Math.max(C.MIN_SUCCESS_FITNESS, totalFitness),
|
|
55
|
+
progress: 100,
|
|
56
|
+
saturationFraction,
|
|
57
|
+
actionEntropy,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Build the finalized payload for a failed maze run.
|
|
63
|
+
*
|
|
64
|
+
* @param state - Completed simulation state for the failed run.
|
|
65
|
+
* @param encodedMaze - Maze grid used to compute fallback geometric progress.
|
|
66
|
+
* @param startPos - Start coordinate for the current episode.
|
|
67
|
+
* @param exitPos - Exit coordinate for the current episode.
|
|
68
|
+
* @param distanceMap - Optional precomputed distance map aligned to the maze.
|
|
69
|
+
* @returns Failure result with shaped fitness, path, and diagnostic summaries.
|
|
70
|
+
*/
|
|
71
|
+
export function finalizeFailedMazeMovementRun(
|
|
72
|
+
state: SimulationState,
|
|
73
|
+
encodedMaze: number[][],
|
|
74
|
+
startPos: readonly [number, number],
|
|
75
|
+
exitPos: readonly [number, number],
|
|
76
|
+
distanceMap?: number[][],
|
|
77
|
+
): MazeMovementSimulationResult {
|
|
78
|
+
const progress = distanceMap
|
|
79
|
+
? MazeUtils.calculateProgressFromDistanceMap(
|
|
80
|
+
distanceMap,
|
|
81
|
+
state.position,
|
|
82
|
+
startPos,
|
|
83
|
+
)
|
|
84
|
+
: MazeUtils.calculateProgress(
|
|
85
|
+
encodedMaze,
|
|
86
|
+
state.position,
|
|
87
|
+
startPos,
|
|
88
|
+
exitPos,
|
|
89
|
+
);
|
|
90
|
+
const progressFraction = progress / 100;
|
|
91
|
+
const shapedProgress =
|
|
92
|
+
Math.pow(progressFraction, C.PROGRESS_POWER) * C.PROGRESS_SCALE;
|
|
93
|
+
const explorationScore = state.visitedUniqueCount;
|
|
94
|
+
const actionEntropy = computeMazeMovementActionEntropy(state.directionCounts);
|
|
95
|
+
const entropyBonus = actionEntropy * C.ENTROPY_BONUS_WEIGHT;
|
|
96
|
+
const baseFitness =
|
|
97
|
+
shapedProgress +
|
|
98
|
+
explorationScore +
|
|
99
|
+
state.progressReward +
|
|
100
|
+
state.newCellExplorationBonus +
|
|
101
|
+
state.invalidMovePenalty +
|
|
102
|
+
entropyBonus +
|
|
103
|
+
state.localAreaPenalty;
|
|
104
|
+
const randomizedFitness =
|
|
105
|
+
baseFitness + randomMazeMovementUnit() * C.FITNESS_RANDOMNESS;
|
|
106
|
+
const stabilizedFitness =
|
|
107
|
+
randomizedFitness >= 0
|
|
108
|
+
? randomizedFitness
|
|
109
|
+
: -Math.log1p(1 - randomizedFitness);
|
|
110
|
+
const pathSnapshot = materializeMazeMovementPath(state.pathLength);
|
|
111
|
+
const stepsTaken = state.steps | 0;
|
|
112
|
+
const saturationFraction =
|
|
113
|
+
stepsTaken > 0 ? state.saturatedSteps / stepsTaken : 0;
|
|
114
|
+
|
|
115
|
+
return {
|
|
116
|
+
success: false,
|
|
117
|
+
steps: stepsTaken,
|
|
118
|
+
path: pathSnapshot,
|
|
119
|
+
fitness: stabilizedFitness,
|
|
120
|
+
progress,
|
|
121
|
+
saturationFraction,
|
|
122
|
+
actionEntropy,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Compute the normalized action-entropy summary for a finished run.
|
|
128
|
+
*
|
|
129
|
+
* @param directionCounts - Per-direction action counts recorded during the run.
|
|
130
|
+
* @returns Normalized entropy in the range `[0, 1]`.
|
|
131
|
+
*/
|
|
132
|
+
function computeMazeMovementActionEntropy(directionCounts: number[]): number {
|
|
133
|
+
return computeActionEntropyFromCounts(
|
|
134
|
+
directionCounts,
|
|
135
|
+
C.LOG_ACTIONS,
|
|
136
|
+
ACTION_ENTROPY_SCRATCH,
|
|
137
|
+
);
|
|
138
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Frozen tuning surface for the dedicated mazeMovement module.
|
|
3
|
+
*
|
|
4
|
+
* This constant table keeps simulation policy, shaping thresholds, and lookup
|
|
5
|
+
* tables in one place so the public facade can stay focused on orchestration.
|
|
6
|
+
*/
|
|
7
|
+
export const MAZE_MOVEMENT_CONSTANTS = Object.freeze({
|
|
8
|
+
DEFAULT_MAX_STEPS: 3000,
|
|
9
|
+
MOVE_HISTORY_LENGTH: 6,
|
|
10
|
+
REWARD_SCALE: 0.5,
|
|
11
|
+
LOOP_PENALTY: 10,
|
|
12
|
+
MEMORY_RETURN_PENALTY: 2,
|
|
13
|
+
REVISIT_PENALTY_PER_VISIT: 0.2,
|
|
14
|
+
VISIT_TERMINATION_THRESHOLD: 10,
|
|
15
|
+
INVALID_MOVE_PENALTY_HARSH: 1000,
|
|
16
|
+
INVALID_MOVE_PENALTY_MILD: 10,
|
|
17
|
+
OVERCONFIDENT_PROB: 0.985,
|
|
18
|
+
SECOND_PROB_LOW: 0.01,
|
|
19
|
+
LOGSTD_FLAT_THRESHOLD: 0.01,
|
|
20
|
+
OVERCONFIDENT_PENALTY: 0.25,
|
|
21
|
+
FLAT_COLLAPSE_PENALTY: 0.35,
|
|
22
|
+
SATURATION_ADJUST_MIN: 6,
|
|
23
|
+
SATURATION_ADJUST_INTERVAL: 5,
|
|
24
|
+
BIAS_CLAMP: 5,
|
|
25
|
+
BIAS_ADJUST_FACTOR: 0.5,
|
|
26
|
+
EPSILON_WARMUP_STEPS: 10,
|
|
27
|
+
EPSILON_STAGNANT_HIGH_THRESHOLD: 12,
|
|
28
|
+
EPSILON_STAGNANT_MED_THRESHOLD: 6,
|
|
29
|
+
EPSILON_SATURATION_TRIGGER: 3,
|
|
30
|
+
OSCILLATION_DETECT_LENGTH: 4,
|
|
31
|
+
SATURATION_PENALTY_TRIGGER: 5,
|
|
32
|
+
SATURATION_PENALTY_PERIOD: 10,
|
|
33
|
+
GLOBAL_BREAK_BONUS_START: 10,
|
|
34
|
+
GLOBAL_BREAK_BONUS_PER_STEP: 0.01,
|
|
35
|
+
GLOBAL_BREAK_BONUS_CAP: 0.5,
|
|
36
|
+
REPETITION_PENALTY_START: 4,
|
|
37
|
+
ENTROPY_BONUS_WEIGHT: 4,
|
|
38
|
+
VISION_LOS_START: 8,
|
|
39
|
+
VISION_GRAD_START: 12,
|
|
40
|
+
VISION_GROUP_LEN: 4,
|
|
41
|
+
PROXIMITY_GREEDY_DISTANCE: 2,
|
|
42
|
+
PROXIMITY_SUPPRESS_EXPLOR_DIST: 5,
|
|
43
|
+
EPSILON_INITIAL: 0.35,
|
|
44
|
+
EPSILON_STAGNANT_HIGH: 0.5,
|
|
45
|
+
EPSILON_STAGNANT_MED: 0.25,
|
|
46
|
+
EPSILON_SATURATIONS: 0.3,
|
|
47
|
+
EPSILON_MIN_NEAR_GOAL: 0.05,
|
|
48
|
+
NO_MOVE_STREAK_THRESHOLD: 5,
|
|
49
|
+
LOCAL_WINDOW: 30,
|
|
50
|
+
LOCAL_AREA_SPAN_THRESHOLD: 5,
|
|
51
|
+
LOCAL_AREA_STAGNATION_STEPS: 8,
|
|
52
|
+
LOCAL_AREA_PENALTY_AMOUNT: 0.05,
|
|
53
|
+
PROGRESS_REWARD_BASE: 0.3,
|
|
54
|
+
PROGRESS_REWARD_CONF_SCALE: 0.7,
|
|
55
|
+
PROGRESS_STEPS_MULT: 0.02,
|
|
56
|
+
PROGRESS_STEPS_MAX: 0.5,
|
|
57
|
+
DISTANCE_DELTA_SCALE: 2.0,
|
|
58
|
+
DISTANCE_DELTA_CONF_BASE: 0.4,
|
|
59
|
+
DISTANCE_DELTA_CONF_SCALE: 0.6,
|
|
60
|
+
PROGRESS_AWAY_BASE_PENALTY: 0.05,
|
|
61
|
+
PROGRESS_AWAY_CONF_SCALE: 0.15,
|
|
62
|
+
ENTROPY_HIGH_THRESHOLD: 0.95,
|
|
63
|
+
ENTROPY_CONFIDENT_THRESHOLD: 0.55,
|
|
64
|
+
ENTROPY_CONFIDENT_DIFF: 0.25,
|
|
65
|
+
ENTROPY_PENALTY: 0.03,
|
|
66
|
+
EXPLORATION_BONUS_SMALL: 0.015,
|
|
67
|
+
REPETITION_PENALTY_BASE: 0.05,
|
|
68
|
+
BACK_MOVE_PENALTY: 0.2,
|
|
69
|
+
SATURATION_PENALTY_BASE: 0.05,
|
|
70
|
+
SATURATION_PENALTY_ESCALATE: 0.1,
|
|
71
|
+
DEEP_STAGNATION_THRESHOLD: 40,
|
|
72
|
+
DEEP_STAGNATION_PENALTY: 2,
|
|
73
|
+
ACTION_DIM: 4,
|
|
74
|
+
LOG_ACTIONS: Math.log(4),
|
|
75
|
+
NO_MOVE: -1,
|
|
76
|
+
STD_MIN: 1e-6,
|
|
77
|
+
COLLAPSE_STD_THRESHOLD: 0.01,
|
|
78
|
+
COLLAPSE_STD_MED: 0.03,
|
|
79
|
+
COLLAPSE_RATIO_FULL: 1,
|
|
80
|
+
COLLAPSE_RATIO_HALF: 0.5,
|
|
81
|
+
TEMPERATURE_BASE: 1,
|
|
82
|
+
TEMPERATURE_SCALE: 1.2,
|
|
83
|
+
OUTPUT_HISTORY_LENGTH: 80,
|
|
84
|
+
FITNESS_RANDOMNESS: 0.01,
|
|
85
|
+
SUCCESS_BASE_FITNESS: 650,
|
|
86
|
+
STEP_EFFICIENCY_SCALE: 0.2,
|
|
87
|
+
SUCCESS_ACTION_ENTROPY_SCALE: 5,
|
|
88
|
+
MIN_SUCCESS_FITNESS: 150,
|
|
89
|
+
NEW_CELL_EXPLORATION_BONUS: 0.3,
|
|
90
|
+
REVISIT_PENALTY_STRONG: 0.5,
|
|
91
|
+
PROGRESS_POWER: 1.3,
|
|
92
|
+
PROGRESS_SCALE: 500,
|
|
93
|
+
NODE_TYPE_OUTPUT: 'output',
|
|
94
|
+
DIRECTION_DELTAS: [
|
|
95
|
+
[0, -1],
|
|
96
|
+
[1, 0],
|
|
97
|
+
[0, 1],
|
|
98
|
+
[-1, 0],
|
|
99
|
+
] as const,
|
|
100
|
+
OPPOSITE_DIR: [2, 3, 0, 1] as const,
|
|
101
|
+
} as const);
|