Bladeren bron

fix: select_top should include variants with scores but trials=0

Elite/migrated variants carry inherited scores but start with trials=0.
They were invisible to select_top, add eviction, track_best_history,
apply_extinction, and evolve_skill stats because the filter required
trials > 0. Changed all 5 occurrences to v.trials > 0 or v.scores.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
nonvioce 5 maanden geleden
bovenliggende
commit
f5b0a00bd8
1 gewijzigde bestanden met toevoegingen van 5 en 5 verwijderingen
  1. 5 5
      scripts/prompt_evolver.py

+ 5 - 5
scripts/prompt_evolver.py

@@ -157,7 +157,7 @@ class PromptPopulation:
             self.variants.append(PromptVariant(t, source="seed"))
 
     def select_top(self, n: int = 3, weights: dict[str, float] | None = None) -> list[PromptVariant]:
-        scored = [v for v in self.variants if v.trials > 0]
+        scored = [v for v in self.variants if v.trials > 0 or v.scores]
         scored.sort(key=lambda v: v.composite_score(weights), reverse=True)
         return scored[:n]
 
@@ -186,7 +186,7 @@ class PromptPopulation:
             self.variants.append(variant)
             return True
         # 淘汰最弱个体
-        scored = [(v.composite_score() if v.trials > 0 else float("-inf"), v)
+        scored = [(v.composite_score() if (v.trials > 0 or v.scores) else float("-inf"), v)
                    for v in self.variants]
         scored.sort(key=lambda x: x[0])
         worst = scored[0][1]
@@ -199,7 +199,7 @@ class PromptPopulation:
     # ── 停滞检测 & 灭绝 ────────────────────────────
 
     def track_best_history(self) -> None:
-        scored = [v for v in self.variants if v.trials > 0]
+        scored = [v for v in self.variants if v.trials > 0 or v.scores]
         best = max((v.composite_score() for v in scored), default=0.0)
         self._best_score_history.append(best)
         if len(self._best_score_history) > 5:
@@ -229,7 +229,7 @@ class PromptPopulation:
                   "reseeded_style": 0, "reseeded_crossover": 0}
 
         scored = sorted(
-            [v for v in self.variants if v.trials > 0],
+            [v for v in self.variants if v.trials > 0 or v.scores],
             key=lambda v: v.composite_score()
         )
         unscored = [v for v in self.variants if v.trials == 0]
@@ -689,7 +689,7 @@ def evolve_skill(generations: int = 3, mutation_rate: float = 0.3) -> dict:
 
     print(f"  岛屿数: {len(model.islands)}")
     for cat, pop in model.islands.items():
-        scored = [v for v in pop.variants if v.trials > 0]
+        scored = [v for v in pop.variants if v.trials > 0 or v.scores]
         print(f"    [{cat}] variants={len(pop.variants)} scored={len(scored)} gen={pop.generation}")
 
     total_offspring = 0