Skip to content

Commit

Permalink
Merge branch 'master' into logL_birth_inf
Browse files Browse the repository at this point in the history
  • Loading branch information
lukashergt authored Nov 3, 2023
2 parents fda5207 + 3dac5ad commit 6499f6d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
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 6499f6d

Please sign in to comment.