diff --git a/bilby/core/prior/analytical.py b/bilby/core/prior/analytical.py index 722d4553f38a95b058505088cd5a34653896ed61..96b8a9e9244e334a657e1f084f0e99d398c68872 100644 --- a/bilby/core/prior/analytical.py +++ b/bilby/core/prior/analytical.py @@ -40,7 +40,6 @@ class DeltaFunction(Prior): ======= float: Rescaled probability, equivalent to peak """ - self.test_valid_for_rescaling(val) return self.peak * val ** 0 def prob(self, val): @@ -105,7 +104,6 @@ class PowerLaw(Prior): ======= Union[float, array_like]: Rescaled probability """ - self.test_valid_for_rescaling(val) if self.alpha == -1: return self.minimum * np.exp(val * np.log(self.maximum / self.minimum)) else: @@ -206,7 +204,6 @@ class Uniform(Prior): ======= Union[float, array_like]: Rescaled probability """ - self.test_valid_for_rescaling(val) return self.minimum + val * (self.maximum - self.minimum) def prob(self, val): @@ -314,7 +311,6 @@ class SymmetricLogUniform(Prior): ======= Union[float, array_like]: Rescaled probability """ - self.test_valid_for_rescaling(val) if isinstance(val, (float, int)): if val < 0.5: return -self.maximum * np.exp(-2 * val * np.log(self.maximum / self.minimum)) @@ -401,7 +397,6 @@ class Cosine(Prior): This maps to the inverse CDF. This has been analytically solved for this case. """ - self.test_valid_for_rescaling(val) norm = 1 / (np.sin(self.maximum) - np.sin(self.minimum)) return np.arcsin(val / norm + np.sin(self.minimum)) @@ -456,7 +451,6 @@ class Sine(Prior): This maps to the inverse CDF. This has been analytically solved for this case. """ - self.test_valid_for_rescaling(val) norm = 1 / (np.cos(self.minimum) - np.cos(self.maximum)) return np.arccos(np.cos(self.minimum) - val / norm) @@ -515,7 +509,6 @@ class Gaussian(Prior): This maps to the inverse CDF. This has been analytically solved for this case. """ - self.test_valid_for_rescaling(val) return self.mu + erfinv(2 * val - 1) * 2 ** 0.5 * self.sigma def prob(self, val): @@ -602,7 +595,6 @@ class TruncatedGaussian(Prior): This maps to the inverse CDF. This has been analytically solved for this case. """ - self.test_valid_for_rescaling(val) return erfinv(2 * val * self.normalisation + erf( (self.minimum - self.mu) / 2 ** 0.5 / self.sigma)) * 2 ** 0.5 * self.sigma + self.mu @@ -695,7 +687,6 @@ class LogNormal(Prior): This maps to the inverse CDF. This has been analytically solved for this case. """ - self.test_valid_for_rescaling(val) return np.exp(self.mu + np.sqrt(2 * self.sigma ** 2) * erfinv(2 * val - 1)) def prob(self, val): @@ -790,7 +781,6 @@ class Exponential(Prior): This maps to the inverse CDF. This has been analytically solved for this case. """ - self.test_valid_for_rescaling(val) return -self.mu * log1p(-val) def prob(self, val): @@ -887,7 +877,6 @@ class StudentT(Prior): This maps to the inverse CDF. This has been analytically solved for this case. """ - self.test_valid_for_rescaling(val) if isinstance(val, (float, int)): if val == 0: rescaled = -np.inf @@ -977,7 +966,6 @@ class Beta(Prior): This maps to the inverse CDF. This has been analytically solved for this case. """ - self.test_valid_for_rescaling(val) return btdtri(self.alpha, self.beta, val) * (self.maximum - self.minimum) + self.minimum def prob(self, val): @@ -1070,7 +1058,6 @@ class Logistic(Prior): This maps to the inverse CDF. This has been analytically solved for this case. """ - self.test_valid_for_rescaling(val) if isinstance(val, (float, int)): if val == 0: rescaled = -np.inf @@ -1151,7 +1138,6 @@ class Cauchy(Prior): This maps to the inverse CDF. This has been analytically solved for this case. """ - self.test_valid_for_rescaling(val) rescaled = self.alpha + self.beta * np.tan(np.pi * (val - 0.5)) if isinstance(val, (float, int)): if val == 1: @@ -1233,7 +1219,6 @@ class Gamma(Prior): This maps to the inverse CDF. This has been analytically solved for this case. """ - self.test_valid_for_rescaling(val) return gammaincinv(self.k, val) * self.theta def prob(self, val): @@ -1385,8 +1370,6 @@ class FermiDirac(Prior): .. [1] M. Pitkin, M. Isi, J. Veitch & G. Woan, `arXiv:1705.08978v1 <https:arxiv.org/abs/1705.08978v1>`_, 2017. """ - self.test_valid_for_rescaling(val) - inv = (-np.exp(-1. * self.r) + (1. + np.exp(self.r)) ** -val + np.exp(-1. * self.r) * (1. + np.exp(self.r)) ** -val) diff --git a/bilby/core/prior/base.py b/bilby/core/prior/base.py index 023f1609f36f5adc77920ea5fda85e7c36fea6cb..3edeec29b21c0ea8d9fb9d7bcc0d3dea61c5adf9 100644 --- a/bilby/core/prior/base.py +++ b/bilby/core/prior/base.py @@ -202,23 +202,6 @@ class Prior(object): """ return (val >= self.minimum) & (val <= self.maximum) - @staticmethod - def test_valid_for_rescaling(val): - """Test if 0 < val < 1 - - Parameters - ========== - val: Union[float, int, array_like] - - Raises - ======= - ValueError: If val is not between 0 and 1 - """ - valarray = np.atleast_1d(val) - tests = (valarray < 0) + (valarray > 1) - if np.any(tests): - raise ValueError("Number to be rescaled should be in [0, 1]") - def __repr__(self): """Overrides the special method __repr__. diff --git a/bilby/core/prior/interpolated.py b/bilby/core/prior/interpolated.py index ece311a5a5bb475cc543b29ffd37b949592d802f..187e8a60a3742c3ad8a6c42b436acdc82c0c9f43 100644 --- a/bilby/core/prior/interpolated.py +++ b/bilby/core/prior/interpolated.py @@ -86,7 +86,6 @@ class Interped(Prior): This maps to the inverse CDF. This is done using interpolation. """ - self.test_valid_for_rescaling(val) rescaled = self.inverse_cumulative_distribution(val) if rescaled.shape == (): rescaled = float(rescaled) diff --git a/bilby/core/prior/joint.py b/bilby/core/prior/joint.py index a10a0add2038e120acd82017a20656e440edd636..393a32b9c461324d007934e321a5faaa9eebe960 100644 --- a/bilby/core/prior/joint.py +++ b/bilby/core/prior/joint.py @@ -710,7 +710,6 @@ class JointPrior(Prior): A sample from the prior paramter. """ - self.test_valid_for_rescaling(val) self.dist.rescale_parameters[self.name] = val if self.dist.filled_rescale(): diff --git a/bilby/gw/prior.py b/bilby/gw/prior.py index 739cbf6a02b638c5c41634ee57fe34af2f8b5386..f9b6c182b98579455f60d3d2464c9601c9e20c85 100644 --- a/bilby/gw/prior.py +++ b/bilby/gw/prior.py @@ -369,7 +369,6 @@ class UniformInComponentsMassRatio(Prior): return (self._integral(val) - self._integral(self.minimum)) / self.norm def rescale(self, val): - self.test_valid_for_rescaling(val) resc = self.icdf(val) if resc.ndim == 0: return resc.item() diff --git a/examples/tutorials/making_priors.ipynb b/examples/tutorials/making_priors.ipynb index 7f9d5719edbf85b17c49c9bb665a35dd05dd3999..8daef3bc17d9ac35df3545e2470bbdc79120d4c4 100644 --- a/examples/tutorials/making_priors.ipynb +++ b/examples/tutorials/making_priors.ipynb @@ -127,7 +127,6 @@ " self.alpha = alpha\n", " \n", " def rescale(self, val):\n", - " bilby.prior.Prior.test_valid_for_rescaling(val)\n", " return np.log((np.exp(self.alpha * self.maximum) - np.exp(self.alpha * self.minimum)) * val\n", " + np.exp(self.alpha * self.minimum)) / self.alpha\n", " \n", diff --git a/test/core/prior/prior_test.py b/test/core/prior/prior_test.py index 6afdc9933ad782fd5cc5eab603f92bf4287a7d5f..9241945433cca240af4a4dc740b537d24aa59c83 100644 --- a/test/core/prior/prior_test.py +++ b/test/core/prior/prior_test.py @@ -239,11 +239,6 @@ class TestPriorClasses(unittest.TestCase): all((many_samples >= prior.minimum) & (many_samples <= prior.maximum)) ) - def test_out_of_bounds_rescaling(self): - """Test the the rescaling works as expected.""" - for prior in self.priors: - self.assertRaises(ValueError, lambda: prior.rescale(-1)) - def test_least_recently_sampled(self): for prior in self.priors: least_recently_sampled_expected = prior.sample()