Skip to content

Commit

Permalink
stop warning when logL==logL_birth==-inf (#395)
Browse files Browse the repository at this point in the history
* stop warning about `logL<=logL_birth` when both are `-inf`, just silently drop those samples

* version bump to 2.8.15

* fix test for warning after having relaxed its eagerness

* Update README.rst

* Update _version.py
  • Loading branch information
lukashergt authored Sep 27, 2024
1 parent b4b9d46 commit 8c972f5
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
anesthetic: nested sampling post-processing
===========================================
:Authors: Will Handley and Lukas Hergt
:Version: 2.8.15
:Version: 2.8.16
:Homepage: https://github.com/handley-lab/anesthetic
:Documentation: http://anesthetic.readthedocs.io/

Expand Down
2 changes: 1 addition & 1 deletion anesthetic/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '2.8.15'
__version__ = '2.8.16'
20 changes: 11 additions & 9 deletions anesthetic/samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -1302,15 +1302,17 @@ def recompute(self, logL_birth=None, inplace=False):
n_bad = invalid.sum()
n_equal = (samples.logL == samples.logL_birth).sum()
if n_bad:
warnings.warn("%i out of %i samples have logL <= logL_birth,"
"\n%i of which have logL == logL_birth."
"\nThis may just indicate numerical rounding "
"errors at the peak of the likelihood, but "
"further investigation of the chains files is "
"recommended."
"\nDropping the invalid samples." %
(n_bad, len(samples), n_equal),
RuntimeWarning)
n_inf = ((samples.logL == samples.logL_birth) &
(samples.logL == -np.inf)).sum()
if n_bad > n_inf:
warnings.warn(
"%i out of %i samples have logL <= logL_birth,\n"
"%i of which have logL == logL_birth.\n"
"This may just indicate numerical rounding errors at "
"the peak of the likelihood, but further "
"investigation of the chains files is recommended.\n"
"Dropping the invalid samples."
% (n_bad, len(samples), n_equal), RuntimeWarning)
samples = samples[~invalid].reset_index(drop=True)

samples.sort_values('logL', inplace=True)
Expand Down
1 change: 1 addition & 0 deletions tests/test_samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -1133,6 +1133,7 @@ def test_beta():
def test_beta_with_logL_infinities():
ns = read_chains("./tests/example_data/pc")
ns.loc[:10, ('logL', r'$\ln\mathcal{L}$')] = -np.inf
ns.loc[1000, ('logL', r'$\ln\mathcal{L}$')] = -np.inf
with pytest.warns(RuntimeWarning):
ns.recompute(inplace=True)
assert (ns.logL == -np.inf).sum() == 0
Expand Down

0 comments on commit 8c972f5

Please sign in to comment.