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

pass boundary types to dynesty #3364

Merged
merged 4 commits into from
Jul 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions pycbc/boundaries.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,12 +311,16 @@ def __init__(self, min_bound=-numpy.inf, max_bound=numpy.inf,
# can be used with arrays
if self._min.name == 'reflected' and self._max.name == 'reflected':
self._reflect = numpy.vectorize(self._reflect_well)
self.reflected = 'well'
elif self._min.name == 'reflected':
self._reflect = numpy.vectorize(self._min.reflect_right)
self.reflected = 'min'
elif self._max.name == 'reflected':
self._reflect = numpy.vectorize(self._max.reflect_left)
self.reflected = 'max'
else:
self._reflect = _pass
self.reflected = False

def __repr__(self):
return str(self.__class__)[:-1] + " " + " ".join(
Expand Down
32 changes: 32 additions & 0 deletions pycbc/distributions/joint.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,38 @@ def rvs(self, size=1):

return out

@property
def well_reflected(self):
""" Get list of which parameters are well reflected
"""
reflect = []
bounds = self.bounds
for param in bounds:
if bounds[param].reflected == 'well':
reflect.append(param)
return reflect

@property
def cyclic(self):
""" Get list of which parameters are cyclic
"""
cyclic = []
bounds = self.bounds
for param in bounds:
if bounds[param].cyclic:
cyclic.append(param)
return cyclic

@property
def bounds(self):
""" Get the dict of boundaries
"""
bnds = {}
for dist in self.distributions:
if hasattr(dist, 'bounds'):
bnds.update(dist.bounds)
return bnds

def cdfinv(self, **original):
""" Apply the inverse cdf to the array of values [0, 1]. Every
variable parameter must be given as a keyword argument.
Expand Down
27 changes: 27 additions & 0 deletions pycbc/inference/sampler/dynesty.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,38 @@ def __init__(self, model, nlive, nprocesses=1,
else:
self.run_with_checkpoint = False

# Check for cyclic boundaries
periodic = []
cyclic = self.model.prior_distribution.cyclic
for i, param in enumerate(self.variable_params):
if param in cyclic:
logging.info('Param: %s will be cyclic', param)
periodic.append(i)

if len(periodic) == 0:
periodic = None

# Check for reflected boundaries. Dynesty only supports
# reflection on both min and max of boundary.
reflective = []
reflect = self.model.prior_distribution.well_reflected
for i, param in enumerate(self.variable_params):
if param in reflect:
logging.info("Param: %s will be well reflected", param)
reflective.append(i)

if len(reflective) == 0:
reflective = None

if self.nlive < 0:
# Interpret a negative input value for the number of live points
# (which is clearly an invalid input in all senses)
# as the desire to dynamically determine that number
self._sampler = dynesty.DynamicNestedSampler(log_likelihood_call,
prior_call, self.ndim,
pool=self.pool,
reflective=reflective,
periodic=periodic,
**kwargs)
self.run_with_checkpoint = False
logging.info("Checkpointing not currently supported with"
Expand All @@ -119,6 +144,8 @@ def __init__(self, model, nlive, nprocesses=1,
self._sampler = dynesty.NestedSampler(log_likelihood_call,
prior_call, self.ndim,
nlive=self.nlive,
reflective=reflective,
periodic=periodic,
pool=self.pool, **kwargs)

# properties of the internal sampler which should not be pickled
Expand Down