Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for logL_birth #324

Merged
merged 40 commits into from
Apr 9, 2024
Merged
Changes from 30 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
f45e005
Fix for logL_birth
williamjameshandley Aug 1, 2023
bdc97db
bump version to 2.1.5
williamjameshandley Aug 1, 2023
f0020f8
Merge branch 'master' into logL_birth_inf
williamjameshandley Aug 4, 2023
85618c3
bump version to 2.1.6
williamjameshandley Aug 4, 2023
343caff
now avoiding dropna where possible and reducing code repetition
williamjameshandley Aug 4, 2023
2a0d11d
Merge branch 'logL_birth_inf' of github.com:handley-lab/anesthetic in…
williamjameshandley Aug 4, 2023
c353f18
Merge branch 'master' into logL_birth_inf
lukashergt Aug 15, 2023
a3c221b
Merge branch 'master' into logL_birth_inf
lukashergt Aug 16, 2023
b185eb1
version bump to 2.2.2
lukashergt Aug 16, 2023
aefbf14
Merge branch 'master' into logL_birth_inf
lukashergt Aug 16, 2023
318d1e0
Dropping all infs with warnings
williamjameshandley Aug 20, 2023
df622ef
Corrected bump_version script
williamjameshandley Aug 22, 2023
b51b3ef
Added a scatter kind
williamjameshandley Aug 22, 2023
bdb7911
Merge branch 'logL_birth_inf' of github.com:handley-lab/anesthetic in…
williamjameshandley Aug 22, 2023
36f7ee4
Merge branch 'master' into logL_birth_inf
lukashergt Sep 30, 2023
247c10c
fix mistakenly changed DOI in README
lukashergt Sep 30, 2023
a498a0b
check for inf directly instead of indirectly using isfinite, since na…
lukashergt Sep 30, 2023
d2915fb
add `pytest.warns` to tests to explicitly check for the existance of …
lukashergt Sep 30, 2023
03104f9
Merge branch 'master' into logL_birth_inf
lukashergt Oct 19, 2023
941b712
Merge branch 'master' into logL_birth_inf
lukashergt Nov 2, 2023
fda5207
Update samples.py for pep8
lukashergt Nov 2, 2023
6499f6d
Merge branch 'master' into logL_birth_inf
lukashergt Nov 3, 2023
cc7dfd9
version bump to 2.5.2
lukashergt Nov 3, 2023
95dc805
Merge branch 'master' into logL_birth_inf
williamjameshandley Mar 2, 2024
00dcebc
Merge branch 'master' into logL_birth_inf
williamjameshandley Mar 2, 2024
6dee428
bump version to 2.7.4
williamjameshandley Mar 2, 2024
96a71bf
Removed obselete test for #96
williamjameshandley Mar 2, 2024
4b9c66f
Merge branch 'master' into logL_birth_inf
williamjameshandley Mar 18, 2024
233777b
Merge branch 'master' into logL_birth_inf
williamjameshandley Mar 18, 2024
6a05edf
Merge branch 'master' into logL_birth_inf
lukashergt Apr 8, 2024
d3b2928
Update README.rst version to 2.8.5
lukashergt Apr 8, 2024
e1526ea
Update _version.py to 2.8.5
lukashergt Apr 8, 2024
6f6de11
Merge branch 'master' into logL_birth_inf
williamjameshandley Apr 9, 2024
b2136e3
bump version to 2.8.6
williamjameshandley Apr 9, 2024
d5a2b87
Merge branch 'master' into logL_birth_inf
lukashergt Apr 9, 2024
35b64b2
bump version to 2.8.7
lukashergt Apr 9, 2024
14f4709
Merge branch 'master' into logL_birth_inf
williamjameshandley Apr 9, 2024
e40cbec
bump version to 2.8.8
williamjameshandley Apr 9, 2024
2242d50
bump version to 2.8.9
lukashergt Apr 9, 2024
7eb1869
Merge branch 'master' into logL_birth_inf
lukashergt Apr 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 24 additions & 8 deletions anesthetic/samples.py
Original file line number Diff line number Diff line change
@@ -174,8 +174,11 @@ def plot_1d(self, axes=None, *args, **kwargs):
for x, ax in axes.items():
if x in self and kwargs['kind'] is not None:
xlabel = self.get_label(x)
self[x].plot(ax=ax, xlabel=xlabel, logx=x in logx,
*args, **kwargs)
if np.isinf(self[x]).any():
warnings.warn(f"column {x} has inf values.")
selfx = self[x].replace([-np.inf, np.inf], np.nan)
selfx.plot(ax=ax, xlabel=xlabel, logx=x in logx,
*args, **kwargs)
ax.set_xlabel(xlabel)
else:
ax.plot([], [])
@@ -239,6 +242,9 @@ def plot_2d(self, axes=None, *args, **kwargs):
- 'hist_1d': 1d histograms down the diagonal
- 'hist_2d': 2d histograms in lower triangle
- 'hist': 1d & 2d histograms in lower & diagonal
- 'scatter_2d': 2d scatter in lower triangle
- 'scatter': 1d histograms down diagonal
& 2d scatter in lower triangle

Feel free to add your own to this list!
Default:
@@ -337,16 +343,24 @@ def plot_2d(self, axes=None, *args, **kwargs):
if x in self and y in self and lkwargs['kind'] is not None:
xlabel = self.get_label(x)
ylabel = self.get_label(y)
if np.isinf(self[x]).any():
warnings.warn(f"column {x} has inf values.")
if x == y:
self[x].plot(ax=ax.twin, xlabel=xlabel,
logx=x in logx,
*args, **lkwargs)
selfx = self[x].replace([-np.inf, np.inf], np.nan)
selfx.plot(ax=ax.twin, xlabel=xlabel,
logx=x in logx,
*args, **lkwargs)
ax.set_xlabel(xlabel)
ax.set_ylabel(ylabel)
else:
self.plot(x, y, ax=ax, xlabel=xlabel,
logx=x in logx, logy=y in logy,
ylabel=ylabel, *args, **lkwargs)
if np.isinf(self[x]).any():
warnings.warn(f"column {y} has inf values.")
selfxy = self[[x, y]]
selfxy = self.replace([-np.inf, np.inf], np.nan)
selfxy = selfxy.dropna(axis=0)
selfxy.plot(x, y, ax=ax, xlabel=xlabel,
logx=x in logx, logy=y in logy,
ylabel=ylabel, *args, **lkwargs)
ax.set_xlabel(xlabel)
ax.set_ylabel(ylabel)
else:
@@ -370,6 +384,8 @@ def plot_2d(self, axes=None, *args, **kwargs):
'hist': {'diagonal': 'hist_1d', 'lower': 'hist_2d'},
'hist_1d': {'diagonal': 'hist_1d'},
'hist_2d': {'lower': 'hist_2d'},
'scatter': {'diagonal': 'hist_1d', 'lower': 'scatter_2d'},
'scatter_2d': {'lower': 'scatter_2d'},
}

def importance_sample(self, logL_new, action='add', inplace=False):
5 changes: 3 additions & 2 deletions bin/bump_version.py
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@

current_version = run("cat", vfile)
current_version = current_version.split("=")[-1].strip().strip("'")
escaped_version = current_version.replace(".", "\.")
current_version = version.parse(current_version)

if len(sys.argv) > 1:
@@ -33,9 +34,9 @@

for f in [vfile, README]:
if sys.platform == "darwin": # macOS sed requires empty string for backup
run("sed", "-i", "", f"s/{current_version}/{new_version}/g", f)
run("sed", "-i", "", f"s/{escaped_version}/{new_version}/g", f)
else:
run("sed", "-i", f"s/{current_version}/{new_version}/g", f)
run("sed", "-i", f"s/{escaped_version}/{new_version}/g", f)

run("git", "add", vfile, README)
run("git", "commit", "-m", f"bump version to {new_version}")
25 changes: 9 additions & 16 deletions tests/test_samples.py
Original file line number Diff line number Diff line change
@@ -418,6 +418,10 @@ def test_plot_2d_no_axes():
assert axes.iloc[-1, 1].get_xlabel() == 'x1'
assert axes.iloc[-1, 2].get_xlabel() == 'x2'

with pytest.warns(UserWarning):
axes = ns[['x0', 'logL_birth']].plot_2d()
axes = ns.drop_labels()[['x0', 'logL_birth']].plot_2d()


def test_plot_1d_no_axes():
np.random.seed(3)
@@ -431,6 +435,11 @@ def test_plot_1d_no_axes():
assert axes.iloc[1].get_xlabel() == 'x1'
assert axes.iloc[2].get_xlabel() == 'x2'

with pytest.warns(UserWarning):
axes = ns.plot_1d()
axes = ns[['x0', 'logL_birth']].plot_1d()
axes = ns.drop_labels()[['x0', 'logL_birth']].plot_1d()


@pytest.mark.parametrize('kind', ['kde', 'hist', skipif_no_fastkde('fastkde')])
def test_plot_logscale_1d(kind):
@@ -1213,22 +1222,6 @@ def test_hist_range_1d():
assert x2 >= +1


def test_contour_plot_2d_nan():
"""Contour plots with nans arising from issue #96"""
np.random.seed(3)
ns = read_chains('./tests/example_data/pc')

ns.loc[:9, ('x0', '$x_0$')] = np.nan
with pytest.raises((np.linalg.LinAlgError, RuntimeError, ValueError)):
ns.plot_2d(['x0', 'x1'])

# Check this error is removed in the case of zero weights
weights = ns.get_weights()
weights[:10] = 0
ns.set_weights(weights, inplace=True)
ns.plot_2d(['x0', 'x1'])


def test_compute_insertion():
np.random.seed(3)
ns = read_chains('./tests/example_data/pc')