问题
I used to code my MCMC using C. But I'd like to give PyMC a try.
Suppose X_n is the underlying state whose dynamics following a Markov chain and Y_n is the observed data. In particular,
Y_n has Poisson distribution with mean depending on X_n and a multidimensional unknown parameter theta X_n | X_{n-1} has distribution depending on theta
How should I describe this model using PyMC?
Another question: I can find conjugate priors for theta but not for X_n. Is it possible to specify which posteriors are updated using conjugate priors and which using MCMC?
回答1:
Here is an example of a state-space model in PyMC on the PyMC wiki. It basically involves populating a list and allowing PyMC to treat it as a container of PyMC nodes.
As for the second part of the question, you could certainly calculate some of your conjugate posteriors ahead of time and put them into the model. For example, if you observed binomial data x=4
, n=10
you could insert a Beta node p = Beta('p', 5, 7)
to represent that posterior (its really just a prior, as far as the model is concerned, but it is the posterior given data x
). Then PyMC would draw a sample for this posterior at every iteration to be used wherever it is needed in the model.
来源:https://stackoverflow.com/questions/20458972/pymc-how-can-i-describe-a-state-space-model