@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,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';
|