pm.Poisson behaves unexpectedly inside model context

Hi. I am trying to model a timeseries with a Poisson process as one of its drivers.

Let’s say that I have two thousand timepoints, and I want to model the occurrence of 0-1 events along this time span, using a Poisson process with a predefined rate. Suppose this rate is 0.02, so the mean expectation is 40 occurrences over the observed 2000-point trajectory.

If I call pm.Poisson.dist(mu=0.02).random(size=2000), it does exactly that creating an array shaped (2000,) with about 40 ones and zeros for the rest. However, if I call it inside the model context, like so: pm.Poisson('events', mu=0,02, shape=len(data)), the posterior trajectory always converges to an array of all zeros. In fact, if I set the rate to mu=10, it will also be a flat line at the corresponding level (i.e., always 10 events at each time point).

What I’d like it to do is to randomly draw a trajectory of zeros and ones on each step, corresponding to a deterministic or a stochastic rate mu=lambda_, so it (hopefully) converges to a trajectory that actually matches the observed event pattern. Is there a specific way in which that is achieved? Shouldn’t that be the default behavior anyway? Or is the nature of my observed data is pushing it to converge to a flat line? Really confused by this, any explanation is most welcome. Thank you!

Can you provide a more complete example, that also includes the outputs that you consider wrong?

1 Like

Hi @ricardoV94. Really appreciate your response. I figured out that it had nothing to do with how pymc was working (it was working as expected), but my model was apparently misspecified, so it resulted in unexpected posterior traces.

Btw, this is for the stochastic volatility jump model. I think I made some progress there, and just posted an update in another thread “Stochastic Volatility Jumps”. I would really appreciate if you could take a look and throw in some suggestions, as I know there have been a few unsuccessful attempts to implement more advanced SV models in the past, and I think I am getting closer to having a working implementation in pymc. Thanks again, and Happy New Year!

1 Like