Skip to content

Commit 67a5271

Browse files
committed
fix the math domain error that occured when all numbers are equal
This closes #62.
1 parent 197b56f commit 67a5271

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

adaptive/learner/average_learner.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,11 @@ def std(self):
8989
n = self.npoints
9090
if n < 2:
9191
return np.inf
92-
return sqrt((self.sum_f_sq - n * self.mean**2) / (n - 1))
92+
numerator = self.sum_f_sq - n * self.mean**2
93+
if numerator < 0:
94+
# in this case the numerator ~ -1e-15
95+
return 0
96+
return sqrt(numerator / (n - 1))
9397

9498
@cache_latest
9599
def loss(self, real=True, *, n=None):

0 commit comments

Comments
 (0)