Skip to content
Snippets Groups Projects
Commit f065ba49 authored by Gregory Ashton's avatar Gregory Ashton
Browse files

Add lnprob for PowerLaw, Uniform, and Gaussian

Adds a lnprob method to a few of the priors. Need to add this for all
priors and a method to calculate it, if not given.
parent 468835a0
No related branches found
No related tags found
1 merge request!41Add hyper-parameter likelihood
......@@ -135,6 +135,11 @@ class Uniform(Prior):
in_prior = (val >= self.minimum) & (val <= self.maximum)
return 1 / self.support * in_prior
def lnprob(self, val):
"""Return the log-prior probability of val"""
in_prior = (val >= self.minimum) & (val <= self.maximum)
return -np.log(self.support) * in_prior
class DeltaFunction(Prior):
"""Dirac delta function prior, this always returns peak."""
......@@ -186,6 +191,12 @@ class PowerLaw(Prior):
return np.nan_to_num(val ** self.alpha * (1 + self.alpha) / (self.maximum ** (1 + self.alpha)
- self.minimum ** (1 + self.alpha))) * in_prior
def lnprob(self, val):
in_prior = (val >= self.minimum) & (val <= self.maximum)
normalising = (1+self.alpha)/(self.maximum ** (1 + self.alpha)
- self.minimum ** (1 + self.alpha))
return self.alpha * val * np.log(normalising) * in_prior
class Cosine(Prior):
......@@ -249,6 +260,9 @@ class Gaussian(Prior):
"""Return the prior probability of val"""
return np.exp(-(self.mu - val)**2 / (2 * self.sigma**2)) / (2 * np.pi)**0.5 / self.sigma
def lnprob(self, val):
return -0.5*((self.mu - val)**2 / self.sigma**2 + np.log(2 * np.pi * self.sigma**2))
class TruncatedGaussian(Prior):
"""
......
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