Skip to content

Commit

Permalink
fix the math domain error that occured when all numbers are equal
Browse files Browse the repository at this point in the history
This closes #62.
  • Loading branch information
basnijholt committed Oct 15, 2018
1 parent 197b56f commit 67a5271
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion adaptive/learner/average_learner.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,11 @@ def std(self):
n = self.npoints
if n < 2:
return np.inf
return sqrt((self.sum_f_sq - n * self.mean**2) / (n - 1))
numerator = self.sum_f_sq - n * self.mean**2
if numerator < 0:
# in this case the numerator ~ -1e-15
return 0
return sqrt(numerator / (n - 1))

@cache_latest
def loss(self, real=True, *, n=None):
Expand Down

0 comments on commit 67a5271

Please sign in to comment.