I am trying to learn Pymc3 by creating my own version of zip log-likelihood. I eventually want to expand to a case not covered by built in Pymc3.

If I run the same observed y’s through my implementation and the built in one, the sign of ‘ap’ is flipped (negative in the built-in, positive in mine). It seems like this should be straightforward to take the log of the likelihood:

f(x \mid \psi, \theta) = \left\{ \begin{array}{l} (1-\psi) + \psi e^{-\theta}, \text{if } x = 0 \\ \psi \frac{e^{-\theta}\theta^x}{x!}, \text{if } x=1,2,3,\ldots \end{array} \right.

Is there a simple bug in my code??

#MINE

```
class ZeroInflatedPoisson_JA(Continuous):
def __init__(self, pi, theta, *args, **kwargs):
super(ZeroInflatedPoisson_JA, self).__init__(*args, **kwargs)
#create variables for theta and pi
self.theta = theta = tt.as_tensor_variable(theta)
self.pi = pi = tt.as_tensor_variable(pi)
self.poisson_ = Poisson.dist(theta)
def logp(self, value):
return tt.switch(tt.eq(value, 0),
tt.log((1 - self.pi) + self.pi*tt.exp(-1.0*self.theta)),
tt.log(self.pi)+self.poisson_.logp(value)
)
with pm.Model() as ZIPP_JA:
#prior
ap = pm.Normal('ap', 0., 1.)
al = pm.Normal('al', 0., 10.)
#logit link (rethinking code is logit(p) <-ap which implies that p is invlogit(ap)
#sigmoid is same thing as invlogit)
p = pm.math.sigmoid(ap)
theta = pm.math.exp(al)
y_obs = ZeroInflatedPoisson_JA('y_obs', p, theta, observed=y)
ZIPP_JA = pm.sample(1000, tune=1000,chains=4)
```