I’m trying to model a fairly complicated self-exciting spatio-temporal point process model. The big details are in a preprint, but broadly, any event is seen as either drawn from the background (a fixed spatial distribution of events) or triggered by a previous event (a distribution centered at the previous event).

In maximum likelihood it’s fit a lot like a standard mixture model, using expectation-maximization. Get expected mixing proportions given current parameters, use these to maximize the expected log-likelihood to get new parameters, and iterate until convergence.

I’m trying to build a Bayesian version of this. There is a method for these kinds of models which proceeds along similar lines:

- Draw a possible mixture structure. That is, assign each event to either the background or to a prior event which triggered it, using the current parameter value estimates.
- Condition on this mixture structure and draw from the posterior of each parameter after this conditioning. (The conditioning makes the posteriors
*much*more tractable.) - Return to step 1 and repeat.

I’d like to implement a version of this in PyMC3 so my method is more flexible than my current hard-coded version.

To do this, I gather I’d need to write a custom step method which implements step 1, drawing the mixing structure, so I can use that structure when writing out step 2. I already have a very fast implementation of step 1 using Cython.

The PyMC3 documentation says it “easily incorporates custom step methods”, but I can’t find any examples or further documentation on how to do this. How can I build a sampler which uses a custom method to draw the mixture structure, so I can then use PyMC3’s built-in samplers for the parameters of the model?

(And is this even a reasonable approach to the problem?)

Thanks!