Commit 07e3cd37 authored by Gregory Ashton's avatar Gregory Ashton

Resolve "CDF plots with priors show the PDF"

parent d77bc859
......@@ -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')
else:
ax.plot(theta, prior.cdf(theta), color='C2')
if save:
fig.tight_layout()
......
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