@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,199 @@
1
+ # trainer/evaluation
2
+
3
+ ## trainer/evaluation/trainer.evaluation.service.types.ts
4
+
5
+ ### PopulationAggregateScoringContext
6
+
7
+ Aggregate scoring context shared while computing frame-primary scores.
8
+
9
+ ### PopulationStageEvaluationRequest
10
+
11
+ Candidate-stage request used by the staged population evaluator.
12
+
13
+ Keeping this internal contract narrow lets the orchestration service choose
14
+ a candidate budget without coupling the execution helpers to generation-plan
15
+ details.
16
+
17
+ ## trainer/evaluation/trainer.evaluation.service.ts
18
+
19
+ ### commitPopulationScores
20
+
21
+ `(population: readonly import("test/examples/flappy_bird/trainer/trainer.types").FlappyTrainerNetwork[], provisionalScoresByGenome: ReadonlyMap<import("test/examples/flappy_bird/trainer/trainer.types").FlappyTrainerNetwork, number>) => void`
22
+
23
+ Commits provisional scores to genome score fields.
24
+
25
+ Parameters:
26
+
27
+ - `population` - - Current population.
28
+ - `provisionalScoresByGenome` - - Final provisional score map.
29
+
30
+ Returns: Nothing.
31
+
32
+ ### evaluatePopulationFullStage
33
+
34
+ `(population: readonly import("test/examples/flappy_bird/trainer/trainer.types").FlappyTrainerNetwork[], generationEvaluationPlan: import("test/examples/flappy_bird/trainer/trainer.types").FlappyGenerationEvaluationPlan, aggregateByGenome: Map<import("test/examples/flappy_bird/trainer/trainer.types").FlappyTrainerNetwork, import("test/examples/flappy_bird/evaluation/evaluation.types").FlappySeedBatchEvaluation>, provisionalScoresByGenome: Map<import("test/examples/flappy_bird/trainer/trainer.types").FlappyTrainerNetwork, number>, elitismCount: number) => void`
35
+
36
+ Executes the full evaluation stage over the top provisional candidates.
37
+
38
+ Parameters:
39
+
40
+ - `population` - - Current population.
41
+ - `generationEvaluationPlan` - - Per-generation staged evaluation plan.
42
+ - `aggregateByGenome` - - Mutable aggregate cache keyed by genome.
43
+ - `provisionalScoresByGenome` - - Mutable provisional score map.
44
+ - `elitismCount` - - Configured elitism count.
45
+
46
+ Returns: Nothing.
47
+
48
+ ### evaluatePopulationQuickStage
49
+
50
+ `(population: readonly import("test/examples/flappy_bird/trainer/trainer.types").FlappyTrainerNetwork[], generationEvaluationPlan: import("test/examples/flappy_bird/trainer/trainer.types").FlappyGenerationEvaluationPlan, aggregateByGenome: Map<import("test/examples/flappy_bird/trainer/trainer.types").FlappyTrainerNetwork, import("test/examples/flappy_bird/evaluation/evaluation.types").FlappySeedBatchEvaluation>, provisionalScoresByGenome: Map<import("test/examples/flappy_bird/trainer/trainer.types").FlappyTrainerNetwork, number>) => void`
51
+
52
+ Executes the quick evaluation stage over the full population.
53
+
54
+ Parameters:
55
+
56
+ - `population` - - Current population.
57
+ - `generationEvaluationPlan` - - Per-generation staged evaluation plan.
58
+ - `aggregateByGenome` - - Mutable aggregate cache keyed by genome.
59
+ - `provisionalScoresByGenome` - - Mutable provisional score map.
60
+
61
+ Returns: Nothing.
62
+
63
+ ### evaluatePopulationReevaluationStage
64
+
65
+ `(population: readonly import("test/examples/flappy_bird/trainer/trainer.types").FlappyTrainerNetwork[], generationEvaluationPlan: import("test/examples/flappy_bird/trainer/trainer.types").FlappyGenerationEvaluationPlan, aggregateByGenome: Map<import("test/examples/flappy_bird/trainer/trainer.types").FlappyTrainerNetwork, import("test/examples/flappy_bird/evaluation/evaluation.types").FlappySeedBatchEvaluation>, provisionalScoresByGenome: Map<import("test/examples/flappy_bird/trainer/trainer.types").FlappyTrainerNetwork, number>, elitismCount: number) => void`
66
+
67
+ Executes the large-seed reevaluation stage over top candidates.
68
+
69
+ Parameters:
70
+
71
+ - `population` - - Current population.
72
+ - `generationEvaluationPlan` - - Per-generation staged evaluation plan.
73
+ - `aggregateByGenome` - - Mutable aggregate cache keyed by genome.
74
+ - `provisionalScoresByGenome` - - Mutable provisional score map.
75
+ - `elitismCount` - - Configured elitism count.
76
+
77
+ Returns: Nothing.
78
+
79
+ ### resolveFullPassCandidateCount
80
+
81
+ `(populationSize: number, elitismCount: number) => number`
82
+
83
+ Resolves how many genomes should advance to the full-pass stage.
84
+
85
+ Parameters:
86
+
87
+ - `populationSize` - - Population size.
88
+ - `elitismCount` - - Configured elitism count.
89
+
90
+ Returns: Full-pass candidate count.
91
+
92
+ ## trainer/evaluation/trainer.evaluation.service.services.ts
93
+
94
+ ### evaluatePopulationSelectedCandidateStage
95
+
96
+ `(population: readonly import("test/examples/flappy_bird/trainer/trainer.types").FlappyTrainerNetwork[], populationStageEvaluationRequest: import("test/examples/flappy_bird/trainer/evaluation/trainer.evaluation.service.types").PopulationStageEvaluationRequest, aggregateByGenome: Map<import("test/examples/flappy_bird/trainer/trainer.types").FlappyTrainerNetwork, import("test/examples/flappy_bird/evaluation/evaluation.types").FlappySeedBatchEvaluation>, provisionalScoresByGenome: Map<import("test/examples/flappy_bird/trainer/trainer.types").FlappyTrainerNetwork, number>) => void`
97
+
98
+ Evaluates a selected candidate subset for a population stage.
99
+
100
+ Parameters:
101
+
102
+ - `population` - - Current population.
103
+ - `populationStageEvaluationRequest` - - Candidate-stage evaluation request.
104
+ - `aggregateByGenome` - - Mutable aggregate cache keyed by genome.
105
+ - `provisionalScoresByGenome` - - Mutable provisional score map.
106
+
107
+ Returns: Nothing.
108
+
109
+ ### evaluateSpecificGenomesAcrossSeeds
110
+
111
+ `(genomes: readonly import("test/examples/flappy_bird/trainer/trainer.types").FlappyTrainerNetwork[], sharedSeeds: readonly number[], rolloutOptions: import("test/examples/flappy_bird/evaluation/evaluation.types").FlappyRolloutOptions, aggregateByGenome: Map<import("test/examples/flappy_bird/trainer/trainer.types").FlappyTrainerNetwork, import("test/examples/flappy_bird/evaluation/evaluation.types").FlappySeedBatchEvaluation>) => void`
112
+
113
+ Evaluates a specific genome subset across shared seeds.
114
+
115
+ Parameters:
116
+
117
+ - `genomes` - - Genomes selected for evaluation.
118
+ - `sharedSeeds` - - Shared deterministic seeds.
119
+ - `rolloutOptions` - - Rollout options for this stage.
120
+ - `aggregateByGenome` - - Mutable aggregate cache keyed by genome.
121
+
122
+ Returns: Nothing.
123
+
124
+ ## trainer/evaluation/trainer.evaluation.service.constants.ts
125
+
126
+ ### trainer.evaluation.service.constants
127
+
128
+ Fallback score assigned to genomes that have not yet been evaluated.
129
+
130
+ ### FLAPPY_TRAINER_MIN_PIPE_PROGRESS
131
+
132
+ ### FLAPPY_TRAINER_NEGATIVE_INFINITY_SCORE
133
+
134
+ ## trainer/evaluation/trainer.evaluation.service.utils.ts
135
+
136
+ ### assignFramePrimaryScores
137
+
138
+ `(population: readonly import("test/examples/flappy_bird/trainer/trainer.types").FlappyTrainerNetwork[], aggregateByGenome: ReadonlyMap<import("test/examples/flappy_bird/trainer/trainer.types").FlappyTrainerNetwork, import("test/examples/flappy_bird/evaluation/evaluation.types").FlappySeedBatchEvaluation>, provisionalScoresByGenome: Map<import("test/examples/flappy_bird/trainer/trainer.types").FlappyTrainerNetwork, number>) => void`
139
+
140
+ Assigns refreshed frame-primary scores to the current population.
141
+
142
+ Parameters:
143
+
144
+ - `population` - - Current population.
145
+ - `aggregateByGenome` - - Aggregate cache keyed by genome.
146
+ - `provisionalScoresByGenome` - - Mutable provisional score map.
147
+
148
+ Returns: Nothing.
149
+
150
+ ### collectAggregateValues
151
+
152
+ `(population: readonly import("test/examples/flappy_bird/trainer/trainer.types").FlappyTrainerNetwork[], aggregateByGenome: ReadonlyMap<import("test/examples/flappy_bird/trainer/trainer.types").FlappyTrainerNetwork, import("test/examples/flappy_bird/evaluation/evaluation.types").FlappySeedBatchEvaluation>) => import("test/examples/flappy_bird/evaluation/evaluation.types").FlappySeedBatchEvaluation[]`
153
+
154
+ Collects all currently available aggregate values.
155
+
156
+ Parameters:
157
+
158
+ - `population` - - Current population.
159
+ - `aggregateByGenome` - - Aggregate cache keyed by genome.
160
+
161
+ Returns: Collected aggregate values.
162
+
163
+ ### resolveMaximumMeanPipesPassed
164
+
165
+ `(aggregateValues: readonly import("test/examples/flappy_bird/evaluation/evaluation.types").FlappySeedBatchEvaluation[]) => number`
166
+
167
+ Resolves the leading mean pipe-progress value across available aggregates.
168
+
169
+ Parameters:
170
+
171
+ - `aggregateValues` - - Aggregate values currently available.
172
+
173
+ Returns: Highest mean pipe-progress value.
174
+
175
+ ### resolvePopulationAggregateScoringContext
176
+
177
+ `(population: readonly import("test/examples/flappy_bird/trainer/trainer.types").FlappyTrainerNetwork[], aggregateByGenome: ReadonlyMap<import("test/examples/flappy_bird/trainer/trainer.types").FlappyTrainerNetwork, import("test/examples/flappy_bird/evaluation/evaluation.types").FlappySeedBatchEvaluation>) => import("test/examples/flappy_bird/trainer/evaluation/trainer.evaluation.service.types").PopulationAggregateScoringContext`
178
+
179
+ Resolves the aggregate scoring context used by frame-primary scoring.
180
+
181
+ Parameters:
182
+
183
+ - `population` - - Current population.
184
+ - `aggregateByGenome` - - Aggregate cache keyed by genome.
185
+
186
+ Returns: Aggregate scoring context.
187
+
188
+ ### scoreAggregateFramePrimary
189
+
190
+ `(aggregate: import("test/examples/flappy_bird/evaluation/evaluation.types").FlappySeedBatchEvaluation, maximumMeanPipesPassed: number) => number`
191
+
192
+ Scores one aggregate using the frame-primary heuristic.
193
+
194
+ Parameters:
195
+
196
+ - `aggregate` - - Aggregate evaluation result.
197
+ - `maximumMeanPipesPassed` - - Best mean pipe progress in the population.
198
+
199
+ Returns: Provisional score.
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Fallback score assigned to genomes that have not yet been evaluated.
3
+ */
4
+ export const FLAPPY_TRAINER_NEGATIVE_INFINITY_SCORE = Number.NEGATIVE_INFINITY;
5
+
6
+ /**
7
+ * Minimum pipe-progress baseline used when no aggregates are available.
8
+ */
9
+ export const FLAPPY_TRAINER_MIN_PIPE_PROGRESS = 0;
@@ -0,0 +1,73 @@
1
+ import {
2
+ evaluateFlappyFitnessAcrossSeeds,
3
+ type FlappyRolloutOptions,
4
+ type FlappySeedBatchEvaluation,
5
+ } from '../../flappyEvaluation';
6
+ import { selectTopGenomesByScore } from '../trainer.selection.utils';
7
+ import type { FlappyTrainerNetwork } from '../trainer.types';
8
+ import { assignFramePrimaryScores } from './trainer.evaluation.service.utils';
9
+ import type { PopulationStageEvaluationRequest } from './trainer.evaluation.service.types';
10
+
11
+ /**
12
+ * Evaluates a selected candidate subset for a population stage.
13
+ *
14
+ * @param population - Current population.
15
+ * @param populationStageEvaluationRequest - Candidate-stage evaluation request.
16
+ * @param aggregateByGenome - Mutable aggregate cache keyed by genome.
17
+ * @param provisionalScoresByGenome - Mutable provisional score map.
18
+ * @returns Nothing.
19
+ */
20
+ export function evaluatePopulationSelectedCandidateStage(
21
+ population: readonly FlappyTrainerNetwork[],
22
+ populationStageEvaluationRequest: PopulationStageEvaluationRequest,
23
+ aggregateByGenome: Map<FlappyTrainerNetwork, FlappySeedBatchEvaluation>,
24
+ provisionalScoresByGenome: Map<FlappyTrainerNetwork, number>,
25
+ ): void {
26
+ // Step 1: Select the top-scoring candidates for the requested stage.
27
+ const selectedCandidates = selectTopGenomesByScore(
28
+ population,
29
+ provisionalScoresByGenome,
30
+ populationStageEvaluationRequest.candidateCount,
31
+ );
32
+
33
+ // Step 2: Evaluate the selected candidates across the stage's shared seeds.
34
+ evaluateSpecificGenomesAcrossSeeds(
35
+ selectedCandidates,
36
+ populationStageEvaluationRequest.sharedSeeds,
37
+ populationStageEvaluationRequest.rolloutOptions,
38
+ aggregateByGenome,
39
+ );
40
+
41
+ // Step 3: Refresh frame-primary scores for the full population.
42
+ assignFramePrimaryScores(
43
+ population,
44
+ aggregateByGenome,
45
+ provisionalScoresByGenome,
46
+ );
47
+ }
48
+
49
+ /**
50
+ * Evaluates a specific genome subset across shared seeds.
51
+ *
52
+ * @param genomes - Genomes selected for evaluation.
53
+ * @param sharedSeeds - Shared deterministic seeds.
54
+ * @param rolloutOptions - Rollout options for this stage.
55
+ * @param aggregateByGenome - Mutable aggregate cache keyed by genome.
56
+ * @returns Nothing.
57
+ */
58
+ export function evaluateSpecificGenomesAcrossSeeds(
59
+ genomes: readonly FlappyTrainerNetwork[],
60
+ sharedSeeds: readonly number[],
61
+ rolloutOptions: FlappyRolloutOptions,
62
+ aggregateByGenome: Map<FlappyTrainerNetwork, FlappySeedBatchEvaluation>,
63
+ ): void {
64
+ // Step 1: Evaluate each selected genome independently across the shared batch.
65
+ for (const genome of genomes) {
66
+ const aggregate = evaluateFlappyFitnessAcrossSeeds(
67
+ genome,
68
+ sharedSeeds,
69
+ rolloutOptions,
70
+ );
71
+ aggregateByGenome.set(genome, aggregate);
72
+ }
73
+ }
@@ -0,0 +1,165 @@
1
+ import type { FlappySeedBatchEvaluation } from '../../flappyEvaluation';
2
+ import {
3
+ FLAPPY_TRAINER_FULL_PASS_ELITISM_MULTIPLIER,
4
+ FLAPPY_TRAINER_FULL_PASS_POPULATION_FRACTION,
5
+ FLAPPY_TRAINER_REEVALUATION_MIN_CANDIDATE_COUNT,
6
+ } from '../trainer.constants';
7
+ import type {
8
+ FlappyGenerationEvaluationPlan,
9
+ FlappyTrainerNetwork,
10
+ } from '../trainer.types';
11
+ import { FLAPPY_TRAINER_NEGATIVE_INFINITY_SCORE } from './trainer.evaluation.service.constants';
12
+ import {
13
+ evaluatePopulationSelectedCandidateStage,
14
+ evaluateSpecificGenomesAcrossSeeds,
15
+ } from './trainer.evaluation.service.services';
16
+ import { assignFramePrimaryScores } from './trainer.evaluation.service.utils';
17
+ import type { PopulationStageEvaluationRequest } from './trainer.evaluation.service.types';
18
+
19
+ /**
20
+ * Executes the quick evaluation stage over the full population.
21
+ *
22
+ * @param population - Current population.
23
+ * @param generationEvaluationPlan - Per-generation staged evaluation plan.
24
+ * @param aggregateByGenome - Mutable aggregate cache keyed by genome.
25
+ * @param provisionalScoresByGenome - Mutable provisional score map.
26
+ * @returns Nothing.
27
+ *
28
+ * @example
29
+ * ```ts
30
+ * evaluatePopulationQuickStage(
31
+ * population,
32
+ * generationEvaluationPlan,
33
+ * aggregateByGenome,
34
+ * provisionalScoresByGenome,
35
+ * );
36
+ * ```
37
+ */
38
+ export function evaluatePopulationQuickStage(
39
+ population: readonly FlappyTrainerNetwork[],
40
+ generationEvaluationPlan: FlappyGenerationEvaluationPlan,
41
+ aggregateByGenome: Map<FlappyTrainerNetwork, FlappySeedBatchEvaluation>,
42
+ provisionalScoresByGenome: Map<FlappyTrainerNetwork, number>,
43
+ ): void {
44
+ evaluateSpecificGenomesAcrossSeeds(
45
+ population,
46
+ generationEvaluationPlan.quickSeeds,
47
+ generationEvaluationPlan.quickRolloutOptions,
48
+ aggregateByGenome,
49
+ );
50
+
51
+ assignFramePrimaryScores(
52
+ population,
53
+ aggregateByGenome,
54
+ provisionalScoresByGenome,
55
+ );
56
+ }
57
+
58
+ /**
59
+ * Executes the full evaluation stage over the top provisional candidates.
60
+ *
61
+ * @param population - Current population.
62
+ * @param generationEvaluationPlan - Per-generation staged evaluation plan.
63
+ * @param aggregateByGenome - Mutable aggregate cache keyed by genome.
64
+ * @param provisionalScoresByGenome - Mutable provisional score map.
65
+ * @param elitismCount - Configured elitism count.
66
+ * @returns Nothing.
67
+ */
68
+ export function evaluatePopulationFullStage(
69
+ population: readonly FlappyTrainerNetwork[],
70
+ generationEvaluationPlan: FlappyGenerationEvaluationPlan,
71
+ aggregateByGenome: Map<FlappyTrainerNetwork, FlappySeedBatchEvaluation>,
72
+ provisionalScoresByGenome: Map<FlappyTrainerNetwork, number>,
73
+ elitismCount: number,
74
+ ): void {
75
+ // Step 1: Resolve the candidate-stage request for the full evaluation pass.
76
+ const populationStageEvaluationRequest = {
77
+ candidateCount: resolveFullPassCandidateCount(
78
+ population.length,
79
+ elitismCount,
80
+ ),
81
+ sharedSeeds: generationEvaluationPlan.fullSeeds,
82
+ rolloutOptions: generationEvaluationPlan.fullRolloutOptions,
83
+ } satisfies PopulationStageEvaluationRequest;
84
+
85
+ // Step 2: Evaluate the selected candidates and refresh provisional scores.
86
+ evaluatePopulationSelectedCandidateStage(
87
+ population,
88
+ populationStageEvaluationRequest,
89
+ aggregateByGenome,
90
+ provisionalScoresByGenome,
91
+ );
92
+ }
93
+
94
+ /**
95
+ * Executes the large-seed reevaluation stage over top candidates.
96
+ *
97
+ * @param population - Current population.
98
+ * @param generationEvaluationPlan - Per-generation staged evaluation plan.
99
+ * @param aggregateByGenome - Mutable aggregate cache keyed by genome.
100
+ * @param provisionalScoresByGenome - Mutable provisional score map.
101
+ * @param elitismCount - Configured elitism count.
102
+ * @returns Nothing.
103
+ */
104
+ export function evaluatePopulationReevaluationStage(
105
+ population: readonly FlappyTrainerNetwork[],
106
+ generationEvaluationPlan: FlappyGenerationEvaluationPlan,
107
+ aggregateByGenome: Map<FlappyTrainerNetwork, FlappySeedBatchEvaluation>,
108
+ provisionalScoresByGenome: Map<FlappyTrainerNetwork, number>,
109
+ elitismCount: number,
110
+ ): void {
111
+ // Step 1: Resolve the candidate-stage request for reevaluation.
112
+ const populationStageEvaluationRequest = {
113
+ candidateCount: Math.max(
114
+ elitismCount,
115
+ FLAPPY_TRAINER_REEVALUATION_MIN_CANDIDATE_COUNT,
116
+ ),
117
+ sharedSeeds: generationEvaluationPlan.reevaluationSeeds,
118
+ rolloutOptions: generationEvaluationPlan.reevaluationRolloutOptions,
119
+ } satisfies PopulationStageEvaluationRequest;
120
+
121
+ // Step 2: Evaluate the selected candidates and refresh provisional scores.
122
+ evaluatePopulationSelectedCandidateStage(
123
+ population,
124
+ populationStageEvaluationRequest,
125
+ aggregateByGenome,
126
+ provisionalScoresByGenome,
127
+ );
128
+ }
129
+
130
+ /**
131
+ * Commits provisional scores to genome score fields.
132
+ *
133
+ * @param population - Current population.
134
+ * @param provisionalScoresByGenome - Final provisional score map.
135
+ * @returns Nothing.
136
+ */
137
+ export function commitPopulationScores(
138
+ population: readonly FlappyTrainerNetwork[],
139
+ provisionalScoresByGenome: ReadonlyMap<FlappyTrainerNetwork, number>,
140
+ ): void {
141
+ // Step 1: Copy provisional scores into the mutable genome score fields.
142
+ for (const genome of population) {
143
+ genome.score =
144
+ provisionalScoresByGenome.get(genome) ??
145
+ FLAPPY_TRAINER_NEGATIVE_INFINITY_SCORE;
146
+ }
147
+ }
148
+
149
+ /**
150
+ * Resolves how many genomes should advance to the full-pass stage.
151
+ *
152
+ * @param populationSize - Population size.
153
+ * @param elitismCount - Configured elitism count.
154
+ * @returns Full-pass candidate count.
155
+ */
156
+ function resolveFullPassCandidateCount(
157
+ populationSize: number,
158
+ elitismCount: number,
159
+ ): number {
160
+ // Step 1: Use the larger of the elitism-based and population-fraction candidate budgets.
161
+ return Math.max(
162
+ elitismCount * FLAPPY_TRAINER_FULL_PASS_ELITISM_MULTIPLIER,
163
+ Math.floor(populationSize * FLAPPY_TRAINER_FULL_PASS_POPULATION_FRACTION),
164
+ );
165
+ }
@@ -0,0 +1,25 @@
1
+ import type {
2
+ FlappyRolloutOptions,
3
+ FlappySeedBatchEvaluation,
4
+ } from '../../flappyEvaluation';
5
+
6
+ /**
7
+ * Candidate-stage request used by the staged population evaluator.
8
+ *
9
+ * Keeping this internal contract narrow lets the orchestration service choose
10
+ * a candidate budget without coupling the execution helpers to generation-plan
11
+ * details.
12
+ */
13
+ export type PopulationStageEvaluationRequest = {
14
+ candidateCount: number;
15
+ sharedSeeds: readonly number[];
16
+ rolloutOptions: FlappyRolloutOptions;
17
+ };
18
+
19
+ /**
20
+ * Aggregate scoring context shared while computing frame-primary scores.
21
+ */
22
+ export type PopulationAggregateScoringContext = {
23
+ aggregateValues: FlappySeedBatchEvaluation[];
24
+ maximumMeanPipesPassed: number;
25
+ };
@@ -0,0 +1,161 @@
1
+ import type { FlappySeedBatchEvaluation } from '../../flappyEvaluation';
2
+ import {
3
+ FLAPPY_TRAINER_FRAME_PRIMARY_BASE_SCORE,
4
+ FLAPPY_TRAINER_FRAME_PRIMARY_PIPE_WEIGHT,
5
+ FLAPPY_TRAINER_FRAME_PRIMARY_SURVIVAL_WEIGHT,
6
+ FLAPPY_TRAINER_FRAME_STABILITY_STDDEV_WEIGHT,
7
+ FLAPPY_TRAINER_PIPE_FALLBACK_PIPE_WEIGHT,
8
+ FLAPPY_TRAINER_PIPE_FILTER_TOLERANCE,
9
+ } from '../trainer.constants';
10
+ import type { FlappyTrainerNetwork } from '../trainer.types';
11
+ import {
12
+ FLAPPY_TRAINER_MIN_PIPE_PROGRESS,
13
+ FLAPPY_TRAINER_NEGATIVE_INFINITY_SCORE,
14
+ } from './trainer.evaluation.service.constants';
15
+ import type { PopulationAggregateScoringContext } from './trainer.evaluation.service.types';
16
+
17
+ /**
18
+ * Assigns refreshed frame-primary scores to the current population.
19
+ *
20
+ * @param population - Current population.
21
+ * @param aggregateByGenome - Aggregate cache keyed by genome.
22
+ * @param provisionalScoresByGenome - Mutable provisional score map.
23
+ * @returns Nothing.
24
+ */
25
+ export function assignFramePrimaryScores(
26
+ population: readonly FlappyTrainerNetwork[],
27
+ aggregateByGenome: ReadonlyMap<
28
+ FlappyTrainerNetwork,
29
+ FlappySeedBatchEvaluation
30
+ >,
31
+ provisionalScoresByGenome: Map<FlappyTrainerNetwork, number>,
32
+ ): void {
33
+ // Step 1: Resolve the aggregate scoring context shared by all genomes.
34
+ const populationAggregateScoringContext =
35
+ resolvePopulationAggregateScoringContext(population, aggregateByGenome);
36
+
37
+ // Step 2: Score each genome using the refreshed aggregate context.
38
+ for (const genome of population) {
39
+ const aggregate = aggregateByGenome.get(genome);
40
+ if (!aggregate) {
41
+ provisionalScoresByGenome.set(
42
+ genome,
43
+ FLAPPY_TRAINER_NEGATIVE_INFINITY_SCORE,
44
+ );
45
+ continue;
46
+ }
47
+
48
+ provisionalScoresByGenome.set(
49
+ genome,
50
+ scoreAggregateFramePrimary(
51
+ aggregate,
52
+ populationAggregateScoringContext.maximumMeanPipesPassed,
53
+ ),
54
+ );
55
+ }
56
+ }
57
+
58
+ /**
59
+ * Collects all currently available aggregate values.
60
+ *
61
+ * @param population - Current population.
62
+ * @param aggregateByGenome - Aggregate cache keyed by genome.
63
+ * @returns Collected aggregate values.
64
+ */
65
+ export function collectAggregateValues(
66
+ population: readonly FlappyTrainerNetwork[],
67
+ aggregateByGenome: ReadonlyMap<
68
+ FlappyTrainerNetwork,
69
+ FlappySeedBatchEvaluation
70
+ >,
71
+ ): FlappySeedBatchEvaluation[] {
72
+ const aggregateValues: FlappySeedBatchEvaluation[] = [];
73
+
74
+ // Step 1: Include only genomes that already have an aggregate in the cache.
75
+ for (const genome of population) {
76
+ const aggregate = aggregateByGenome.get(genome);
77
+ if (aggregate) {
78
+ aggregateValues.push(aggregate);
79
+ }
80
+ }
81
+
82
+ return aggregateValues;
83
+ }
84
+
85
+ /**
86
+ * Resolves the leading mean pipe-progress value across available aggregates.
87
+ *
88
+ * @param aggregateValues - Aggregate values currently available.
89
+ * @returns Highest mean pipe-progress value.
90
+ */
91
+ export function resolveMaximumMeanPipesPassed(
92
+ aggregateValues: readonly FlappySeedBatchEvaluation[],
93
+ ): number {
94
+ // Step 1: Resolve the leading mean pipe-progress value across all aggregates.
95
+ return aggregateValues.reduce(
96
+ (bestPipeProgress, aggregate) =>
97
+ Math.max(bestPipeProgress, aggregate.meanPipesPassed),
98
+ FLAPPY_TRAINER_MIN_PIPE_PROGRESS,
99
+ );
100
+ }
101
+
102
+ /**
103
+ * Scores one aggregate using the frame-primary heuristic.
104
+ *
105
+ * @param aggregate - Aggregate evaluation result.
106
+ * @param maximumMeanPipesPassed - Best mean pipe progress in the population.
107
+ * @returns Provisional score.
108
+ */
109
+ export function scoreAggregateFramePrimary(
110
+ aggregate: FlappySeedBatchEvaluation,
111
+ maximumMeanPipesPassed: number,
112
+ ): number {
113
+ // Step 1: Resolve the stability penalty and pipe-progress eligibility filter.
114
+ const frameStabilityPenalty =
115
+ aggregate.fitnessStdDev * FLAPPY_TRAINER_FRAME_STABILITY_STDDEV_WEIGHT;
116
+ const passesPipeFilter =
117
+ aggregate.meanPipesPassed >=
118
+ maximumMeanPipesPassed - FLAPPY_TRAINER_PIPE_FILTER_TOLERANCE;
119
+
120
+ // Step 2: Use the full frame-primary score when the genome remains near the pipe leader.
121
+ if (passesPipeFilter) {
122
+ return (
123
+ FLAPPY_TRAINER_FRAME_PRIMARY_BASE_SCORE +
124
+ aggregate.meanFramesSurvived *
125
+ FLAPPY_TRAINER_FRAME_PRIMARY_SURVIVAL_WEIGHT +
126
+ aggregate.meanPipesPassed * FLAPPY_TRAINER_FRAME_PRIMARY_PIPE_WEIGHT -
127
+ frameStabilityPenalty
128
+ );
129
+ }
130
+
131
+ // Step 3: Fall back to the pipe-progress-first score for trailing genomes.
132
+ return (
133
+ aggregate.meanPipesPassed * FLAPPY_TRAINER_PIPE_FALLBACK_PIPE_WEIGHT +
134
+ aggregate.meanFramesSurvived -
135
+ frameStabilityPenalty
136
+ );
137
+ }
138
+
139
+ /**
140
+ * Resolves the aggregate scoring context used by frame-primary scoring.
141
+ *
142
+ * @param population - Current population.
143
+ * @param aggregateByGenome - Aggregate cache keyed by genome.
144
+ * @returns Aggregate scoring context.
145
+ */
146
+ function resolvePopulationAggregateScoringContext(
147
+ population: readonly FlappyTrainerNetwork[],
148
+ aggregateByGenome: ReadonlyMap<
149
+ FlappyTrainerNetwork,
150
+ FlappySeedBatchEvaluation
151
+ >,
152
+ ): PopulationAggregateScoringContext {
153
+ // Step 1: Collect the currently available aggregate values.
154
+ const aggregateValues = collectAggregateValues(population, aggregateByGenome);
155
+
156
+ // Step 2: Resolve the highest mean pipe-progress value in the population.
157
+ return {
158
+ aggregateValues,
159
+ maximumMeanPipesPassed: resolveMaximumMeanPipesPassed(aggregateValues),
160
+ };
161
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Trainer evaluation compatibility facade.
3
+ *
4
+ * The staged population-evaluation implementation now lives in the dedicated
5
+ * `trainer/evaluation/` submodule so orchestration, scoring helpers, internal
6
+ * contracts, and sub-services can evolve behind a focused boundary.
7
+ */
8
+ export {
9
+ commitPopulationScores,
10
+ evaluatePopulationFullStage,
11
+ evaluatePopulationQuickStage,
12
+ evaluatePopulationReevaluationStage,
13
+ } from './evaluation/trainer.evaluation.service';