diff --git a/README.rst b/README.rst index 7a289866..7808577b 100644 --- a/README.rst +++ b/README.rst @@ -2,7 +2,7 @@ anesthetic: nested sampling post-processing =========================================== :Authors: Will Handley and Lukas Hergt -:Version: 2.5.0 +:Version: 2.5.1 :Homepage: https://github.com/handley-lab/anesthetic :Documentation: http://anesthetic.readthedocs.io/ diff --git a/anesthetic/_version.py b/anesthetic/_version.py index e59b17b4..b8c54948 100644 --- a/anesthetic/_version.py +++ b/anesthetic/_version.py @@ -1 +1 @@ -__version__ = '2.5.0' +__version__ = '2.5.1' diff --git a/anesthetic/utils.py b/anesthetic/utils.py index cd3b5b2e..efe1c80c 100644 --- a/anesthetic/utils.py +++ b/anesthetic/utils.py @@ -456,7 +456,11 @@ def triangular_sample_compression_2d(x, y, cov, w=None, n=1000): if w is None: w = pandas.Series(index=x.index, data=np.ones_like(x)) - if isinstance(n, str): + if n is False: + n = len(x) + elif n is True or isinstance(n, str): + if n is True: + n = 'entropy' n = int(neff(w, beta=n)) # Select samples for triangulation diff --git a/tests/test_utils.py b/tests/test_utils.py index bceeb61d..24196c25 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -88,12 +88,18 @@ def test_triangular_sample_compression_2d(): cov = np.identity(2) tri, W = triangular_sample_compression_2d(x, y, cov, w) assert len(W) == 1000 - assert np.isclose(sum(W), sum(w), rtol=1e-1) + assert sum(W) == pytest.approx(sum(w), rel=1e-1) + tri, W = triangular_sample_compression_2d(x, y, cov, w, n=False) + assert len(W) == n + assert sum(W) == pytest.approx(sum(w)) + tri, W = triangular_sample_compression_2d(x, y, cov, w, n=True) # entropy + assert n/2 < len(W) < n + assert sum(W) == pytest.approx(sum(w), rel=1e-3) tri, W = triangular_sample_compression_2d(x, y, cov, w, n='inf') - assert n/10 < len(W) < n - assert np.isclose(sum(W), sum(w), rtol=1e-1) + assert len(W) == pytest.approx(n/2, rel=1e-1) + assert sum(W) == pytest.approx(sum(w), rel=1e-2) tri, W = triangular_sample_compression_2d(x, y, cov, w, n=10000) - assert n == len(W) + assert len(W) == n assert sum(W) == pytest.approx(sum(w))