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

automatic minmax limits #80

Merged
merged 9 commits into from
May 22, 2020
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ anesthetic: nested sampling visualisation
=========================================
:anesthetic: nested sampling visualisation
:Author: Will Handley
:Version: 1.2.5
:Version: 1.2.6
:Homepage: https://github.com/williamjameshandley/anesthetic
:Documentation: http://anesthetic.readthedocs.io/

Expand Down
8 changes: 8 additions & 0 deletions anesthetic/samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ def __init__(self, *args, **kwargs):
self['weight'] = self.weight
self.tex['weight'] = r'MCMC weight'

for param in self.columns:
if param not in self.limits:
self.limits[param] = (self[param].min(), self[param].max())

def plot(self, ax, paramname_x, paramname_y=None, *args, **kwargs):
"""Interface for 2D and 1D plotting routines.

Expand Down Expand Up @@ -429,6 +433,10 @@ def __init__(self, *args, **kwargs):
if logL_birth is not None:
self._compute_nlive(logL_birth)

for param in self.columns:
if param not in self.limits:
self.limits[param] = (self[param].min(), self[param].max())
lukashergt marked this conversation as resolved.
Show resolved Hide resolved

@property
def beta(self):
"""Thermodynamic inverse temperature."""
Expand Down
1 change: 0 additions & 1 deletion tests/example_data/pc.ranges
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
x0 None None
x1 None None
x2 0 None
x3 0 1
24 changes: 24 additions & 0 deletions tests/test_samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,3 +523,27 @@ def test_live_points():
logL = pc.logL_birth.max()
assert (last_live_points.logL > logL).all()
assert len(last_live_points) == pc.nlive.mode()[0]


def test_limit_assignment():
numpy.random.seed(3)
ns = NestedSamples(root='./tests/example_data/pc')
# `None` in .ranges file:
assert ns.limits['x0'][0] is None
assert ns.limits['x0'][1] is None
# parameter not listed in .ranges file:
assert ns.limits['x1'][0] == ns.x1.min()
assert ns.limits['x1'][1] == ns.x1.max()
# `None` for only one limit in .ranges file:
assert ns.limits['x2'][0] == 0
assert ns.limits['x2'][1] is None
# both limits specified in .ranges file:
assert ns.limits['x3'][0] == 0
assert ns.limits['x3'][1] == 1
# limits for logL, weight, nlive
assert ns.limits['logL'][0] == -777.0115456428716
assert ns.limits['logL'][1] == 5.748335384373301
assert ns.limits['weight'][0] == 0
assert ns.limits['weight'][1] == 1
assert ns.limits['nlive'][0] == 0
assert ns.limits['nlive'][1] == 125