gaurv007 commited on
Commit
d23ddc4
·
verified ·
1 Parent(s): c3e8081

Upload alpha_factory/deterministic/theme_sampler.py

Browse files
alpha_factory/deterministic/theme_sampler.py CHANGED
@@ -175,12 +175,21 @@ def pick_theme(
175
  dead_themes: Optional[list[str]] = None,
176
  top_k: int = 3,
177
  ) -> str:
178
- """Pick the best theme to explore next."""
 
 
 
 
179
  scores = compute_gap_scores(existing_themes, existing_anomaly_tags, dead_themes)
180
  top = scores[:top_k]
181
- if not top:
182
- return random.choice(list(THEME_FIELDS.keys()))
183
- return random.choice(top)[0]
 
 
 
 
 
184
 
185
 
186
  def get_theme_fields(theme: str) -> list[str]:
 
175
  dead_themes: Optional[list[str]] = None,
176
  top_k: int = 3,
177
  ) -> str:
178
+ """Pick the best theme to explore next.
179
+
180
+ Never returns a dead theme. Falls back to a random non-dead theme.
181
+ """
182
+ dead_set = set(dead_themes or [])
183
  scores = compute_gap_scores(existing_themes, existing_anomaly_tags, dead_themes)
184
  top = scores[:top_k]
185
+ if top:
186
+ return random.choice(top)[0]
187
+ # All themes dead — return a random non-dead theme, or highest-gap dead as last resort
188
+ alive_themes = [t for t in THEME_FIELDS.keys() if t not in dead_set]
189
+ if alive_themes:
190
+ return random.choice(alive_themes)
191
+ # Absolute last resort: return first theme (all are dead)
192
+ return list(THEME_FIELDS.keys())[0]
193
 
194
 
195
  def get_theme_fields(theme: str) -> list[str]: