Skip to content

Commit

Permalink
nan/inf issue with chi2 likelihood def
Browse files Browse the repository at this point in the history
  • Loading branch information
settwi committed Nov 26, 2024
1 parent ce7b981 commit e541400
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
__pycache__/
*.py[cod]
*$py.class
.ruff_cache

# C extensions
*.so
Expand Down
7 changes: 6 additions & 1 deletion yaff/common_likelihoods.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ def chi2_likelihood(data: fitting.DataPacket, model: np.ndarray):

# Some count bins might be negative, or have zero error,
# so use nan_to_num
return -np.nan_to_num((numerator / total_sq_err)[restriction]).sum()
return -np.nan_to_num(
(numerator / total_sq_err)[restriction],
nan=0,
neginf=0,
posinf=0
).sum()

return chi2_likelihood

0 comments on commit e541400

Please sign in to comment.