Search code examples
recursionbayesianpymc

Recursive Bayesian with pymc


In general bayesian inference works like:

prior = foo
for data in (dataSet as it arrives):
    posterior = prior+model+data
    prior = posterior

The amazing pakedge PyMC seems to have the workflow:

prior = foo
run MCMC on prior+AllTheModel+AllTheData
posterior = trace

That is cool, but how can I close the loop? I.E. How do I convert a trace into a prior for my next data or model?


To be more specific about my use case: I have data that comes in over the course of each work day. My current workflow with PyMC:

At the end of each day the program is run. 
It starts with uninformative priors. 
Then it loads in all the data for the whole history.
Runs MCMC, and generates reports from the traces.

The first few days of the project, the program runs in a reasonable time, small bern and small thin. When we are weeks into the project, the program takes a long time to run. Furthermore, it often needs to be rerun do to insufficient bern or high acor. This is a Shlemiel the painter's algorithm. Is there a way to save the analyses done yesterday as the prior to a model of todays data?


Solution

  • There is no good way to do this in PyMC. The posterior that comes out is represented by a set of samples. You could set your prior to be a mixture of point masses on yesterday's samples, but that is unlikely to work well. You have to fit a parametric approximation to the posterior to effectively use it as a prior.