@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.
Files changed (223) hide show
  1. package/.github/agents/boundary-mapper.agent.md +29 -0
  2. package/.github/agents/docs-scout.agent.md +29 -0
  3. package/.github/agents/plan-scout.agent.md +29 -0
  4. package/.github/agents/solid-split.agent.md +138 -0
  5. package/.github/copilot-instructions.md +103 -0
  6. package/package.json +6 -3
  7. package/plans/ES2023 migration +13 -8
  8. package/plans/Evolution_Training_Interoperability_Contracts.md +1 -1
  9. package/plans/Interactive_Examples_and_Learning_Path.md +10 -2
  10. package/plans/Memory_Optimization.md +3 -3
  11. package/plans/README.md +63 -0
  12. package/plans/Roadmap.md +15 -3
  13. package/plans/asciiMaze_SOLID_split.done.md +130 -0
  14. package/plans/flappy_bird_SOLID_split.done.md +67 -0
  15. package/scripts/assets/theme.css +221 -34
  16. package/scripts/copy-examples.mjs +9 -5
  17. package/scripts/export-onnx.mjs +3 -3
  18. package/scripts/generate-bench-tables.mjs +10 -10
  19. package/scripts/generate-bench-tables.ts +10 -10
  20. package/scripts/generate-docs.ts +1415 -449
  21. package/scripts/render-docs-html.ts +15 -8
  22. package/src/README.md +101 -223
  23. package/src/architecture/README.md +57 -185
  24. package/src/architecture/layer/README.md +38 -38
  25. package/src/architecture/network/README.md +33 -31
  26. package/src/architecture/network/activate/README.md +77 -77
  27. package/src/architecture/network/connect/README.md +15 -13
  28. package/src/architecture/network/deterministic/README.md +7 -7
  29. package/src/architecture/network/evolve/README.md +44 -44
  30. package/src/architecture/network/gating/README.md +20 -20
  31. package/src/architecture/network/genetic/README.md +51 -51
  32. package/src/architecture/network/mutate/README.md +97 -97
  33. package/src/architecture/network/onnx/README.md +264 -264
  34. package/src/architecture/network/prune/README.md +39 -39
  35. package/src/architecture/network/remove/README.md +26 -26
  36. package/src/architecture/network/serialize/README.md +56 -56
  37. package/src/architecture/network/slab/README.md +61 -61
  38. package/src/architecture/network/standalone/README.md +24 -24
  39. package/src/architecture/network/stats/README.md +9 -9
  40. package/src/architecture/network/topology/README.md +46 -46
  41. package/src/architecture/network/training/README.md +21 -21
  42. package/src/methods/README.md +9 -87
  43. package/src/multithreading/README.md +8 -77
  44. package/src/multithreading/workers/README.md +2 -2
  45. package/src/multithreading/workers/browser/README.md +0 -6
  46. package/src/multithreading/workers/node/README.md +0 -3
  47. package/src/neat/README.md +562 -568
  48. package/src/utils/README.md +18 -18
  49. package/test/examples/asciiMaze/README.md +59 -59
  50. package/test/examples/asciiMaze/asciiMaze.e2e.test.ts +14 -9
  51. package/test/examples/asciiMaze/browser-entry/README.md +196 -0
  52. package/test/examples/asciiMaze/browser-entry/browser-entry.abort.services.ts +95 -0
  53. package/test/examples/asciiMaze/browser-entry/browser-entry.constants.ts +23 -0
  54. package/test/examples/asciiMaze/browser-entry/browser-entry.curriculum.services.ts +115 -0
  55. package/test/examples/asciiMaze/browser-entry/browser-entry.globals.services.ts +106 -0
  56. package/test/examples/asciiMaze/browser-entry/browser-entry.host.services.ts +157 -0
  57. package/test/examples/asciiMaze/browser-entry/browser-entry.services.ts +14 -0
  58. package/test/examples/asciiMaze/browser-entry/browser-entry.ts +129 -0
  59. package/test/examples/asciiMaze/browser-entry/browser-entry.types.ts +120 -0
  60. package/test/examples/asciiMaze/browser-entry/browser-entry.utils.ts +98 -0
  61. package/test/examples/asciiMaze/browser-entry.ts +10 -576
  62. package/test/examples/asciiMaze/dashboardManager/README.md +276 -0
  63. package/test/examples/asciiMaze/dashboardManager/archive/README.md +16 -0
  64. package/test/examples/asciiMaze/dashboardManager/archive/dashboardManager.archive.services.ts +267 -0
  65. package/test/examples/asciiMaze/dashboardManager/dashboardManager.constants.ts +35 -0
  66. package/test/examples/asciiMaze/dashboardManager/dashboardManager.services.ts +103 -0
  67. package/test/examples/asciiMaze/dashboardManager/dashboardManager.ts +181 -0
  68. package/test/examples/asciiMaze/dashboardManager/dashboardManager.types.ts +267 -0
  69. package/test/examples/asciiMaze/dashboardManager/dashboardManager.utils.ts +254 -0
  70. package/test/examples/asciiMaze/dashboardManager/live/README.md +14 -0
  71. package/test/examples/asciiMaze/dashboardManager/live/dashboardManager.live.services.ts +264 -0
  72. package/test/examples/asciiMaze/dashboardManager/telemetry/README.md +47 -0
  73. package/test/examples/asciiMaze/dashboardManager/telemetry/dashboardManager.telemetry.services.ts +513 -0
  74. package/test/examples/asciiMaze/dashboardManager.ts +13 -2335
  75. package/test/examples/asciiMaze/evolutionEngine/README.md +1058 -0
  76. package/test/examples/asciiMaze/evolutionEngine/curriculumPhase.ts +90 -0
  77. package/test/examples/asciiMaze/evolutionEngine/engineState.constants.ts +36 -0
  78. package/test/examples/asciiMaze/evolutionEngine/engineState.ts +58 -513
  79. package/test/examples/asciiMaze/evolutionEngine/engineState.types.ts +212 -0
  80. package/test/examples/asciiMaze/evolutionEngine/engineState.utils.ts +301 -0
  81. package/test/examples/asciiMaze/evolutionEngine/evolutionEngine.types.ts +445 -0
  82. package/test/examples/asciiMaze/evolutionEngine/evolutionLoop.ts +81 -50
  83. package/test/examples/asciiMaze/evolutionEngine/optionsAndSetup.ts +2 -4
  84. package/test/examples/asciiMaze/evolutionEngine/populationDynamics.ts +17 -33
  85. package/test/examples/asciiMaze/evolutionEngine/populationPruning.ts +1 -1
  86. package/test/examples/asciiMaze/evolutionEngine/rngAndTiming.ts +1 -2
  87. package/test/examples/asciiMaze/evolutionEngine/sampling.ts +1 -1
  88. package/test/examples/asciiMaze/evolutionEngine/scratchPools.ts +2 -5
  89. package/test/examples/asciiMaze/evolutionEngine/setupHelpers.ts +30 -37
  90. package/test/examples/asciiMaze/evolutionEngine/telemetryMetrics.ts +16 -58
  91. package/test/examples/asciiMaze/evolutionEngine/trainingWarmStart.ts +2 -2
  92. package/test/examples/asciiMaze/evolutionEngine.ts +55 -55
  93. package/test/examples/asciiMaze/fitness.ts +2 -2
  94. package/test/examples/asciiMaze/fitness.types.ts +65 -0
  95. package/test/examples/asciiMaze/interfaces.ts +64 -1352
  96. package/test/examples/asciiMaze/mazeMovement/README.md +356 -0
  97. package/test/examples/asciiMaze/mazeMovement/finalization/README.md +49 -0
  98. package/test/examples/asciiMaze/mazeMovement/finalization/mazeMovement.finalization.ts +138 -0
  99. package/test/examples/asciiMaze/mazeMovement/mazeMovement.constants.ts +101 -0
  100. package/test/examples/asciiMaze/mazeMovement/mazeMovement.services.ts +230 -0
  101. package/test/examples/asciiMaze/mazeMovement/mazeMovement.ts +299 -0
  102. package/test/examples/asciiMaze/mazeMovement/mazeMovement.types.ts +185 -0
  103. package/test/examples/asciiMaze/mazeMovement/mazeMovement.utils.ts +153 -0
  104. package/test/examples/asciiMaze/mazeMovement/policy/README.md +91 -0
  105. package/test/examples/asciiMaze/mazeMovement/policy/mazeMovement.policy.ts +467 -0
  106. package/test/examples/asciiMaze/mazeMovement/runtime/README.md +95 -0
  107. package/test/examples/asciiMaze/mazeMovement/runtime/mazeMovement.runtime.ts +354 -0
  108. package/test/examples/asciiMaze/mazeMovement/shaping/README.md +124 -0
  109. package/test/examples/asciiMaze/mazeMovement/shaping/mazeMovement.shaping.ts +459 -0
  110. package/test/examples/asciiMaze/mazeMovement.ts +12 -2978
  111. package/test/examples/flappy_bird/Trace-20260309T191949.json +24124 -0
  112. package/test/examples/flappy_bird/browser-entry/README.md +1129 -0
  113. package/test/examples/flappy_bird/browser-entry/browser-entry.host.utils.ts +4 -324
  114. package/test/examples/flappy_bird/browser-entry/browser-entry.network-view.utils.ts +6 -399
  115. package/test/examples/flappy_bird/browser-entry/browser-entry.playback.utils.ts +1 -717
  116. package/test/examples/flappy_bird/browser-entry/browser-entry.spawn.utils.ts +11 -31
  117. package/test/examples/flappy_bird/browser-entry/browser-entry.visualization.utils.ts +15 -893
  118. package/test/examples/flappy_bird/browser-entry/host/README.md +307 -0
  119. package/test/examples/flappy_bird/browser-entry/host/host.resize.service.ts +1 -295
  120. package/test/examples/flappy_bird/browser-entry/host/host.ts +562 -6
  121. package/test/examples/flappy_bird/browser-entry/host/resize/README.md +274 -0
  122. package/test/examples/flappy_bird/browser-entry/host/resize/host.resize.service.constants.ts +31 -0
  123. package/test/examples/flappy_bird/browser-entry/host/resize/host.resize.service.services.ts +360 -0
  124. package/test/examples/flappy_bird/browser-entry/host/resize/host.resize.service.ts +117 -0
  125. package/test/examples/flappy_bird/browser-entry/host/resize/host.resize.service.types.ts +63 -0
  126. package/test/examples/flappy_bird/browser-entry/host/resize/host.resize.service.utils.ts +250 -0
  127. package/test/examples/flappy_bird/browser-entry/network-view/README.md +399 -0
  128. package/test/examples/flappy_bird/browser-entry/network-view/network-view.topology.utils.ts +255 -0
  129. package/test/examples/flappy_bird/browser-entry/network-view/network-view.ts +802 -7
  130. package/test/examples/flappy_bird/browser-entry/playback/README.md +684 -0
  131. package/test/examples/flappy_bird/browser-entry/playback/background/README.md +277 -0
  132. package/test/examples/flappy_bird/browser-entry/playback/background/ground-grid/README.md +770 -0
  133. package/test/examples/flappy_bird/browser-entry/playback/background/ground-grid/playback.background.ground-grid.cache.services.ts +178 -0
  134. package/test/examples/flappy_bird/browser-entry/playback/background/ground-grid/playback.background.ground-grid.constants.ts +107 -0
  135. package/test/examples/flappy_bird/browser-entry/playback/background/ground-grid/playback.background.ground-grid.geometry.utils.ts +518 -0
  136. package/test/examples/flappy_bird/browser-entry/playback/background/ground-grid/playback.background.ground-grid.math.utils.ts +117 -0
  137. package/test/examples/flappy_bird/browser-entry/playback/background/ground-grid/playback.background.ground-grid.pulse.utils.ts +233 -0
  138. package/test/examples/flappy_bird/browser-entry/playback/background/ground-grid/playback.background.ground-grid.services.ts +211 -0
  139. package/test/examples/flappy_bird/browser-entry/playback/background/ground-grid/playback.background.ground-grid.ts +48 -0
  140. package/test/examples/flappy_bird/browser-entry/playback/background/ground-grid/playback.background.ground-grid.types.ts +212 -0
  141. package/test/examples/flappy_bird/browser-entry/playback/background/ground-grid/playback.background.ground-grid.utils.ts +81 -0
  142. package/test/examples/flappy_bird/browser-entry/playback/background/playback.background.cache.services.ts +96 -0
  143. package/test/examples/flappy_bird/browser-entry/playback/background/playback.background.constants.ts +62 -0
  144. package/test/examples/flappy_bird/browser-entry/playback/background/playback.background.services.ts +244 -0
  145. package/test/examples/flappy_bird/browser-entry/playback/background/playback.background.ts +53 -0
  146. package/test/examples/flappy_bird/browser-entry/playback/background/playback.background.types.ts +68 -0
  147. package/test/examples/flappy_bird/browser-entry/playback/background/playback.background.utils.ts +100 -0
  148. package/test/examples/flappy_bird/browser-entry/playback/frame-render/README.md +310 -0
  149. package/test/examples/flappy_bird/browser-entry/playback/frame-render/playback.frame-render.service.ts +92 -0
  150. package/test/examples/flappy_bird/browser-entry/playback/frame-render/playback.frame-render.services.ts +272 -0
  151. package/test/examples/flappy_bird/browser-entry/playback/frame-render/playback.frame-render.types.ts +39 -0
  152. package/test/examples/flappy_bird/browser-entry/playback/frame-render/playback.frame-render.utils.ts +493 -0
  153. package/test/examples/flappy_bird/browser-entry/playback/playback.constants.ts +1 -1
  154. package/test/examples/flappy_bird/browser-entry/playback/playback.frame-render.service.ts +4 -0
  155. package/test/examples/flappy_bird/browser-entry/playback/playback.snapshot.utils.ts +44 -0
  156. package/test/examples/flappy_bird/browser-entry/playback/playback.starfield.service.ts +39 -122
  157. package/test/examples/flappy_bird/browser-entry/playback/playback.starfield.services.ts +272 -0
  158. package/test/examples/flappy_bird/browser-entry/playback/playback.starfield.types.ts +62 -0
  159. package/test/examples/flappy_bird/browser-entry/playback/playback.starfield.utils.ts +11 -4
  160. package/test/examples/flappy_bird/browser-entry/playback/playback.ts +409 -8
  161. package/test/examples/flappy_bird/browser-entry/playback/playback.types.ts +4 -12
  162. package/test/examples/flappy_bird/browser-entry/runtime/README.md +235 -0
  163. package/test/examples/flappy_bird/browser-entry/runtime/runtime.evolution-launch.service.ts +45 -0
  164. package/test/examples/flappy_bird/browser-entry/runtime/runtime.lifecycle.service.ts +81 -0
  165. package/test/examples/flappy_bird/browser-entry/runtime/runtime.startup.service.ts +74 -0
  166. package/test/examples/flappy_bird/browser-entry/runtime/runtime.ts +31 -121
  167. package/test/examples/flappy_bird/browser-entry/runtime/runtime.types.ts +36 -0
  168. package/test/examples/flappy_bird/browser-entry/visualization/README.md +557 -0
  169. package/test/examples/flappy_bird/browser-entry/visualization/visualization.constants.ts +110 -0
  170. package/test/examples/flappy_bird/browser-entry/visualization/visualization.draw.service.ts +957 -19
  171. package/test/examples/flappy_bird/browser-entry/visualization/visualization.legend.utils.ts +138 -3
  172. package/test/examples/flappy_bird/browser-entry/visualization/visualization.topology.utils.ts +3 -27
  173. package/test/examples/flappy_bird/browser-entry/visualization/visualization.ts +1 -23
  174. package/test/examples/flappy_bird/browser-entry/worker-channel/README.md +156 -0
  175. package/test/examples/flappy_bird/constants/README.md +1179 -0
  176. package/test/examples/flappy_bird/constants/constants.network-view.ts +24 -0
  177. package/test/examples/flappy_bird/constants/constants.palette.ts +7 -0
  178. package/test/examples/flappy_bird/constants/constants.starfield.ts +78 -3
  179. package/test/examples/flappy_bird/environment/README.md +143 -0
  180. package/test/examples/flappy_bird/environment/environment.observation.utils.ts +1 -19
  181. package/test/examples/flappy_bird/environment/environment.step.service.ts +3 -66
  182. package/test/examples/flappy_bird/evaluation/README.md +130 -0
  183. package/test/examples/flappy_bird/evaluation/evaluation.fitness.utils.ts +1 -1
  184. package/test/examples/flappy_bird/evaluation/evaluation.rollout.service.ts +5 -375
  185. package/test/examples/flappy_bird/evaluation/rollout/README.md +291 -0
  186. package/test/examples/flappy_bird/evaluation/rollout/evaluation.rollout.constants.ts +30 -0
  187. package/test/examples/flappy_bird/evaluation/rollout/evaluation.rollout.service.ts +58 -0
  188. package/test/examples/flappy_bird/evaluation/rollout/evaluation.rollout.services.ts +310 -0
  189. package/test/examples/flappy_bird/evaluation/rollout/evaluation.rollout.types.ts +56 -0
  190. package/test/examples/flappy_bird/evaluation/rollout/evaluation.rollout.utils.ts +368 -0
  191. package/test/examples/flappy_bird/flappy-evolution-worker/README.md +618 -0
  192. package/test/examples/flappy_bird/flappy-evolution-worker/flappy-evolution-worker.playback.service.ts +7 -7
  193. package/test/examples/flappy_bird/flappy-evolution-worker/flappy-evolution-worker.simulation.frame.service.ts +364 -0
  194. package/test/examples/flappy_bird/flappy-evolution-worker/flappy-evolution-worker.simulation.types.ts +14 -0
  195. package/test/examples/flappy_bird/flappy-evolution-worker/flappy-evolution-worker.simulation.utils.ts +4 -201
  196. package/test/examples/flappy_bird/flappy-evolution-worker/flappy-evolution-worker.ts +184 -345
  197. package/test/examples/flappy_bird/flappy-evolution-worker/flappy-evolution-worker.warm-start.service.ts +291 -0
  198. package/test/examples/flappy_bird/flappy.simulation.shared.utils.ts +5 -0
  199. package/test/examples/flappy_bird/simulation-shared/README.md +417 -0
  200. package/test/examples/flappy_bird/simulation-shared/observation/README.md +183 -0
  201. package/test/examples/flappy_bird/simulation-shared/observation/observation.features.utils.ts +301 -0
  202. package/test/examples/flappy_bird/simulation-shared/observation/observation.ts +9 -0
  203. package/test/examples/flappy_bird/simulation-shared/observation/observation.vector.utils.ts +59 -0
  204. package/test/examples/flappy_bird/simulation-shared/simulation-shared.observation.utils.ts +5 -403
  205. package/test/examples/flappy_bird/simulation-shared/simulation-shared.spawn.utils.ts +20 -6
  206. package/test/examples/flappy_bird/{evaluation/evaluation.statistics.utils.ts → simulation-shared/simulation-shared.statistics.utils.ts} +23 -8
  207. package/test/examples/flappy_bird/trainer/README.md +563 -0
  208. package/test/examples/flappy_bird/trainer/evaluation/README.md +199 -0
  209. package/test/examples/flappy_bird/trainer/evaluation/trainer.evaluation.service.constants.ts +9 -0
  210. package/test/examples/flappy_bird/trainer/evaluation/trainer.evaluation.service.services.ts +73 -0
  211. package/test/examples/flappy_bird/trainer/evaluation/trainer.evaluation.service.ts +165 -0
  212. package/test/examples/flappy_bird/trainer/evaluation/trainer.evaluation.service.types.ts +25 -0
  213. package/test/examples/flappy_bird/trainer/evaluation/trainer.evaluation.service.utils.ts +161 -0
  214. package/test/examples/flappy_bird/trainer/trainer.evaluation.service.ts +13 -0
  215. package/test/examples/flappy_bird/trainer/trainer.report.service.services.ts +181 -0
  216. package/test/examples/flappy_bird/trainer/trainer.report.service.ts +126 -0
  217. package/test/examples/flappy_bird/trainer/trainer.selection.utils.ts +89 -0
  218. package/test/examples/flappy_bird/trainer/trainer.ts +11 -553
  219. package/test/examples/flappy_bird/browser-entry/browser-entry.utils.ts +0 -12
  220. package/test/examples/flappy_bird/environment/environment.ts +0 -7
  221. package/test/examples/flappy_bird/evaluation/evaluation.ts +0 -7
  222. package/test/examples/flappy_bird/simulation-shared/simulation-shared.ts +0 -15
  223. 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);