Commit 0998b75b authored by Gregory Ashton's avatar Gregory Ashton

Merge branch '382-cdf-plots-with-priors-show-the-pdf' into 'master'

Resolve "CDF plots with priors show the PDF"

Closes #382

See merge request lscsoft/bilby!538
parents d77bc859 07e3cd37
Pipeline #68527 passed with stages
in 5 minutes and 42 seconds
......@@ -536,6 +536,19 @@ class Prior(object):
return np.nan
def cdf(self, val):
""" Generic method to calculate CDF, can be overwritten in subclass """
if np.any(np.isinf([self.minimum, self.maximum])):
raise ValueError(
"Unable to use the generic CDF calculation for priors with"
"infinite support")
x = np.linspace(self.minimum, self.maximum, 1000)
pdf = self.prob(x)
cdf = cumtrapz(pdf, x, initial=0)
interp = interp1d(x, cdf, assume_sorted=True, bounds_error=False,
fill_value=(0, 1))
return interp(val)
def ln_prob(self, val):
"""Return the prior ln probability of val, this should be overwritten
......@@ -679,7 +679,10 @@ class Result(object):
if isinstance(prior, Prior):
theta = np.linspace(ax.get_xlim()[0], ax.get_xlim()[1], 300)
ax.plot(theta, prior.prob(theta), color='C2')
if cumulative is False:
ax.plot(theta, prior.prob(theta), color='C2')
ax.plot(theta, prior.cdf(theta), color='C2')
if save:
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment