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:
@@ -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}
|
||||
Reference in New Issue
Block a user