mixle.evolve.population module¶
The meta-search that learns which improvement operators help: a bandit + a diversity population.
The operator-choice problem is a non-stationary bandit: each step, pick an operator (arm), apply it through the Phase-1 propose+verify gate, observe the verified gate delta as reward (0 if the challenger was rejected), and update the arm’s value. Because the reward is the anti-regression verified delta, the policy cannot be fooled by overfit in-sample gains.
OperatorBandit– Thompson or UCB over a fixed operator pool. Reward is the verified delta; cost is tracked for a report. Non-stationary: a forgetting factor decays stale arm statistics so the policy can follow a problem whose best operator changes over the run.Population– a diversity-preserving population of model structures evolved by the bandit: select operators, apply them to parents, gate the challengers, reward the bandit, and keep the verified-best plus a coarse-but-honest capability-diversity quota.runreturns aSearchResult;championis the incumbent.
- class OperatorBandit(operators, *, policy='thompson', decay=0.97, prior_cost_aware=True, seed=0)[source]
Bases:
objectA non-stationary bandit over a fixed pool of
ImprovementOperator.select(k)returns thekhighest-value operators under the chosen policy;rewardfolds a verified delta + cost back into the chosen arm;reportis the “which operators help” artifact.- Policies:
'thompson'– Beta-Bernoulli Thompson sampling on the win indicator (reward > 0), scaled by the mean positive reward, so an operator that wins rarely but big and one that wins often but small are compared on expected verified delta.'ucb'– UCB1 on the mean reward with asqrt(2 ln N / n)exploration bonus.
Non-stationarity: each
rewardfirst multiplies every arm’s statistics bydecay(a forgetting factor in(0, 1]), so old evidence fades and the policy can track a shifting best operator.- Parameters:
- value(name)[source]
The current policy value of operator
name(a Thompson draw or the UCB index).
- select(k=1)[source]
Return the
koperators with the highest policy value (a fresh Thompson draw each call).
- reward(op_name, delta, cost)[source]
Fold a verified
delta(0 if the challenger was rejected) andcostinto the arm.Decays every arm first (non-stationarity), then updates the chosen arm. A
deltais clipped at 0 below – a rejected challenger is a zero reward, never negative, matching the anti-regression guarantee (we never punish an operator for a rejected proposal beyond not rewarding it).
- class Population(seeds, *, objective, operators=None, bandit=None, size=12, diversity_quota=2, seed=0)[source]
Bases:
objectA diversity-preserving population of model structures, evolved by the
OperatorBandit.seedsare fitted models (the starting structures). Eachstep()selects operators via the bandit, applies them to parents chosen by fitness, gates the challengers with the Phase-1 champion/challenger rule (Benjamini-Hochberg multiplicity, since a generation produces many challengers at once), rewards the bandit with the verified deltas, and keeps the verified-best plus a coarse capability-diversity quota.- Parameters:
seeds (Sequence[Any]) – the initial fitted models (at least one).
objective (Objective) – the
Objectiveto optimize (lower-is-better aware).operators (Sequence[ImprovementOperator] | None) – the proposal-move pool; defaults to the Phase-1 safe set.
bandit (OperatorBandit | None) – an
OperatorBanditoveroperators(built with the default policy if omitted).size (int) – the carrying capacity of the population.
diversity_quota (int) – how many of
sizeslots are reserved for capability-diverse members (the rest go to the fittest); the quota keeps the search from collapsing onto one structure too early.seed (int) – RNG seed for parent sampling and the bandit.
- step(data)[source]
Run one generation: select -> propose -> gate -> reward -> survivor selection.
- Parameters:
data (Any)
- Return type:
GenerationReport
- run(data, generations=5)[source]
Evolve for
generationssteps; return aSearchResult.The returned
best_modelis the run incumbent, guaranteed no worse than the best seed on the objective (anti-regression).historyis one row per generation (proposals / verified / score).
- property champion: Any
The current run incumbent (the best model seen, anti-regression guaranteed).