Skip to content
Snippets Groups Projects
Commit 195e300d authored by Matthew Pitkin's avatar Matthew Pitkin
Browse files

likelihood.py: add pymc3_likelihood method for PoissonLikelihood class

parent 76509005
No related branches found
No related tags found
1 merge request!139Add PyMC3 sampler
......@@ -236,3 +236,27 @@ class PoissonLikelihood(Likelihood):
-self.sumlogfactorial)
else:
raise ValueError("Poisson rate function returns wrong value type!")
def pymc3_likelihood(self, sampler):
from tupak.core.sampler import Sampler
if not isinstance(sampler, Sampler):
raise ValueError("'sampler' is not a Sampler class")
try:
samplername = sampler.external_sampler.__name__
except ValueError:
raise ValueError("Sampler's 'external_sampler' has not been initialised")
if samplername != 'pymc3':
raise ValueError("Only use this class method for PyMC3 sampler")
for key in sampler.pymc3_priors:
if key not in self.function_keys:
raise ValueError("Prior key '{}' is not a function key!".format(key))
# get rate function
rate = self.function(self.x, **sampler.pymc3_priors)
return sampler.external_sampler.Poisson('likelihood', mu=rate,
observed=self.y)
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