Skip to content

Commit

Permalink
automatic minmax limits (#80)
Browse files Browse the repository at this point in the history
* set limits to min and max for all parameters not specified in .ranges file

* adjust example .ranges file to have a mix of limits

`x0` and `x1` in the pc example data are both Gaussians with their limits set
to `None` in the .ranges file. I removed the limits on `x1` such that the
expected behaviour now (with auto minmax limits) should be:

* `x0` limits are set to (None, None) as specified in .ranges file
* `x1` limits will be set to (x1.min(), x1.max()) automatically

* forgot to remove debug print statements

* add test for limit assignment, both automatic (min and max) and from .ranges file

* version bump 1.2.6; automatic min-max limits

* apply automatic minmax limit assignment also to logL, weight and nlive

* test limits for logL, weight and nlive

* move automatic limit assignment into its own method and call in MCMCSamples and NestedSamples

* make the method  private
  • Loading branch information
Lukas Hergt authored May 22, 2020
1 parent 6e953fd commit dac3a23
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
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
10 changes: 10 additions & 0 deletions anesthetic/samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,14 @@ def __init__(self, *args, **kwargs):
self['weight'] = self.weight
self.tex['weight'] = r'MCMC weight'

self._set_automatic_limits()

def _set_automatic_limits(self):
"""Set all unassigned limits to min and max of sample."""
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 +437,8 @@ def __init__(self, *args, **kwargs):
if logL_birth is not None:
self._compute_nlive(logL_birth)

self._set_automatic_limits()

@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

0 comments on commit dac3a23

Please sign in to comment.