diff --git a/bilby/core/prior/analytical.py b/bilby/core/prior/analytical.py index 9b1d52898fcd9bdb190636f96e9151c54c4a2a1b..b575b3376e99a5185dfba1b01fd5de174a87b6de 100644 --- a/bilby/core/prior/analytical.py +++ b/bilby/core/prior/analytical.py @@ -337,7 +337,8 @@ class SymmetricLogUniform(Prior): ------- float: Prior probability of val """ - return (np.nan_to_num(0.5 / np.abs(val) / np.log(self.maximum / self.minimum)) * + val = np.abs(val) + return (np.nan_to_num(0.5 / val / np.log(self.maximum / self.minimum)) * self.is_in_prior_range(val)) def ln_prob(self, val): @@ -354,6 +355,18 @@ class SymmetricLogUniform(Prior): """ return np.nan_to_num(- np.log(2 * np.abs(val)) - np.log(np.log(self.maximum / self.minimum))) + def cdf(self, val): + val = np.atleast_1d(val) + norm = 0.5 / np.log(self.maximum / self.minimum) + cdf = np.zeros((len(val))) + lower_indices = np.where(np.logical_and(-self.maximum <= val, val <= -self.minimum))[0] + upper_indices = np.where(np.logical_and(self.minimum <= val, val <= self.maximum))[0] + cdf[lower_indices] = -norm * np.log(-val[lower_indices] / self.maximum) + cdf[np.where(np.logical_and(-self.minimum < val, val < self.minimum))] = 0.5 + cdf[upper_indices] = 0.5 + norm * np.log(val[upper_indices] / self.minimum) + cdf[np.where(self.maximum < val)] = 1 + return cdf + class Cosine(Prior):