Skip to content
Snippets Groups Projects
Commit 6436d66d authored by Isobel Marguarethe Romero-Shaw's avatar Isobel Marguarethe Romero-Shaw Committed by Gregory Ashton
Browse files

Raise ValueError if prior maximum <= prior minimum and prior is not a DeltaFunction

parent b9103f19
No related branches found
No related tags found
No related merge requests found
......@@ -25,7 +25,7 @@ class DeltaFunction(Prior):
"""
super(DeltaFunction, self).__init__(name=name, latex_label=latex_label, unit=unit,
minimum=peak, maximum=peak)
minimum=peak, maximum=peak, check_range_nonzero=False)
self.peak = peak
self._is_fixed = True
......
......@@ -15,7 +15,7 @@ class Prior(object):
_default_latex_labels = {}
def __init__(self, name=None, latex_label=None, unit=None, minimum=-np.inf,
maximum=np.inf, boundary=None):
maximum=np.inf, check_range_nonzero=True, boundary=None):
""" Implements a Prior object
Parameters
......@@ -30,15 +30,24 @@ class Prior(object):
Minimum of the domain, default=-np.inf
maximum: float, optional
Maximum of the domain, default=np.inf
check_range_nonzero: boolean, optional
If True, checks that the prior range is non-zero
boundary: str, optional
The boundary condition of the prior, can be 'periodic', 'reflective'
Currently implemented in cpnest, dynesty and pymultinest.
"""
if check_range_nonzero and maximum <= minimum:
raise ValueError(
"maximum {} <= minimum {} for {} prior on {}".format(
maximum, minimum, type(self).__name__, name
)
)
self.name = name
self.latex_label = latex_label
self.unit = unit
self.minimum = minimum
self.maximum = maximum
self.check_range_nonzero = check_range_nonzero
self.least_recently_sampled = None
self.boundary = boundary
self._is_fixed = False
......
......@@ -42,9 +42,9 @@ class TestPriorInstantiationWithoutOptionalPriors(unittest.TestCase):
arguments.
"""
self.prior = bilby.core.prior.Prior(name='test_name', latex_label='test_label', minimum=0, maximum=1,
boundary=None)
check_range_nonzero=True, boundary=None)
expected_string = "Prior(name='test_name', latex_label='test_label', unit=None, minimum=0, maximum=1, " \
"boundary=None)"
"check_range_nonzero=True, boundary=None)"
self.assertTrue(sorted(expected_string) == sorted(self.prior.__repr__()))
def test_base_prob(self):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment