Skip to content

Commit

Permalink
boolean ncompress in kde_contour_plot_2d (handley-lab#350)
Browse files Browse the repository at this point in the history
* add tests for `True` or `False` passed to `triangular_sample_compression_2d` that will show this currently fails

* version bump to 2.4.3

* fix `ncompress` in `triangular_sample_compression_2d` allowing it to take boolean values
  • Loading branch information
lukashergt authored Nov 3, 2023
1 parent 10f032f commit 3dac5ad
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 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.5.0
:Version: 2.5.1
: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.5.0'
__version__ = '2.5.1'
6 changes: 5 additions & 1 deletion anesthetic/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 10 additions & 4 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))


Expand Down

0 comments on commit 3dac5ad

Please sign in to comment.