feat(ga): generation summary stats (median/max/p90/entropy)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-09 20:20:12 +02:00
parent 34f88865da
commit c2a7a62763
2 changed files with 52 additions and 0 deletions
+26
View File
@@ -0,0 +1,26 @@
from __future__ import annotations
import math
import numpy as np
def generation_summary(fitnesses: list[float], n_bins: int = 10) -> dict[str, float]:
arr = np.asarray(fitnesses, dtype=float)
if arr.size == 0:
return {"median": 0.0, "max": 0.0, "p90": 0.0, "entropy": 0.0}
median = float(np.median(arr))
fmax = float(np.max(arr))
p90 = float(np.percentile(arr, 90))
if fmax > 0:
normalized = arr / fmax
else:
normalized = arr
hist, _ = np.histogram(normalized, bins=n_bins, range=(0.0, 1.0))
total = hist.sum()
probs = hist / total if total > 0 else hist
entropy = float(-sum(p * math.log(p) for p in probs if p > 0))
return {"median": median, "max": fmax, "p90": p90, "entropy": entropy}