Suppose I have a generalized zero inflated poisson model:
\text{Pr}(k \mid \phi, \alpha, \lambda) = \begin{cases} \text{something}, & \text{if } k = 0 \\ \text{something}, & \text{if } k = 1, 2, \dots \end{cases}
I have to define the logarithm of the likelihood. Fortunately, I can use some theano functions:
def log_(phi, alp, lam, k):
return #something using theano functions: theano.tensor.log or
# theano.tensor.exp
Now, my data is the frequency of movements of something, which means for 0 I have a frequency of 182, for 1 I have 41, and so on. Let’s put that in a variable:
import numpy as np
counts = np.array([182, 41, 12, 2, 2, 0, 0, 1])
The documentation says that I should use DensityDist for this, something like this:
import pymc3 as pm
with pm.Model() as model_p:
# priors for phi, alpha and lamda
# phi =
# alpha =
# lamda =
gen_poisson = pm.DensityDist('gen_poisson', logp=logp_,
observed=dict(phi=phi, alp=alpha, lam=lamda))
As you may see, the function logp_
needs four arguments, only three have been passed. What about k
? I don’t know. How should I include my data, counts
, to DensityDist
? I don’t think this makes sense:
gen_poisson = pm.DensityDist('gen_poisson', logp=logp_,
observed=dict(phi=phi, alp=alpha, lam=lamda, k=counts))
Remember that each datum of counts
is the frequency of something. It has to be similar to this:
with pm.Model() as z_poisson:
# priors for psi and theta
# psi =
# theta =
# counts should be normalized before this line
y = pm.ZeroInflatedPoisson('y', psi, theta, observed=counts)
After reading these questions: Model definition, variable size and custom likelihood and theano fucntions and densitydist, I still don’t know how to include my data to DensityDist
. What should I do?