Spaces:
Sleeping
Prompt β cheap diversity knobs (tournament size + mutation + random immigrants), curve as the test
The fitness curve collapses early (best = median by ~gen 10, then flat) β premature convergence. Add the cheap diversity levers before considering the island model. Verified against the code. Defaults must preserve current behaviour exactly. pytest + tsc after.
Verified current state (engine_v2/gp.py)
run_gp_v2(..., population_size=150, tournament_k=3, elitism=5, p_mutate=0.7, ...). _tournament_select (line 31) picks 121-204): evaluate β rank β carry k random contenders and returns the best. Main loop (elitism elites β fill the rest via _tournament_select Γ2 + crossover + mutate. There is no random-immigrant mechanism today.
Part A β add the three levers to run_gp_v2
- Tournament size β
tournament_kis already a param. Lowering it (3 β 2) reduces selection pressure β slower takeover β more diversity. Keep the default 3. - Mutation β
p_mutateis already a param (0.7). Allow raising it (e.g. 0.85). Keep the default 0.7. - Random immigrants (new) β add
immigrant_fraction: float = 0.0. When > 0, each generation reserveround(immigrant_fraction * population_size)slots in the new population for fresh random programs drawn fromramped_population(same rng/seed, same grammar/objective constraints as init) instead of crossover+mutation offspring. Fill them after the elites, before/among the offspring; never displace the elites. Default 0.0 β behaviour unchanged.
Part B β one UI toggle to drive them (so you can A/B the curve)
RunRequestgainsdiversity: bool = False. The_workermapsdiversity=Trueβtournament_k=2,p_mutate=0.85,immigrant_fraction=0.10(tune if needed);diversity=Falseβ current defaults unchanged.- Frontend: a Parameters checkbox "Maintain diversity" (default OFF). Tooltip in plain English: "Off: the population can collapse to near-clones early (the fitness curve's best and median lines meet and go flat). On: lowers selection pressure and injects fresh random programs each generation, so the population keeps exploring β watch the best-vs-median gap stay open longer."
Part C β the test is the curve
The success criterion is visible in the Live view fitness curve: with Maintain diversity ON, the best and median lines should stay separated for many more generations (the population doesn't collapse to clones by ~gen 10), versus OFF where they meet early. Also confirm the winner's held-out AUROC doesn't meaningfully drop (diversity should preserve or improve detection, not hurt it). Re-run HPV coherence-on with the toggle off vs on and compare the curves.
CONSTRAINTS
- Defaults preserve current behaviour byte-for-byte (immigrant_fraction 0, tournament_k 3, p_mutate 0.7) so existing runs are unchanged. No airgap/API-shape break beyond the additive
diversityfield. Airgap untouched (this is search-internal; opaque IDs throughout).
Checkpoint
run_gp_v2acceptsimmigrant_fraction; with it >0, fresh random programs enter each generation without displacing elites.- The "Maintain diversity" toggle (default off) flips tournament_k / p_mutate / immigrant_fraction.
- With the toggle ON, the fitness curve's best-vs-median gap visibly persists longer; winner held-out is not degraded.
pytestgreen (defaults unchanged),tscclean, airgap untouched.