From e88902e6ee809f5f1c9bc8c60a1c5f9f09140993 Mon Sep 17 00:00:00 2001 From: David Condrey Date: Mon, 27 Jul 2026 12:00:54 -0700 Subject: [PATCH] fix: use math.fsum in variance to avoid fp rounding when all credits are equal --- misterdev/core/evolution/partial_credit.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/misterdev/core/evolution/partial_credit.py b/misterdev/core/evolution/partial_credit.py index 472995b..9157e3d 100644 --- a/misterdev/core/evolution/partial_credit.py +++ b/misterdev/core/evolution/partial_credit.py @@ -20,6 +20,7 @@ regressions==0 + resolved_rate (see fitness.py). Pure and deterministic. """ +import math from dataclasses import dataclass from typing import Iterable, Optional, Sequence, Tuple @@ -99,8 +100,8 @@ def variance(self) -> float: """Sample variance of the per-task credits (population form).""" if self.total < 1: return 0.0 - m = self.mean_credit - return sum((c - m) ** 2 for c in self.credits) / self.total + m = math.fsum(self.credits) / self.total + return math.fsum((c - m) ** 2 for c in self.credits) / self.total @property def stderr(self) -> float: