I have only recently started using PyMC3 but tried to look this up as much as I could before posting a question, so hopefully you won’t have to excuse my ignorance.
So, I have a set of observed timeseries data and a group of models that can generate such timeseries, ranging from simple models that draw samples from a distribution, to more complex HMMs and some biologically plausible models, all written as Python scripts/functions.
My question is, is there a way to use PyMC3 to sample and identify the optimal parameters of those models that give the best fit to the data?
So the process would be, sample a set of model parameters, run the model, evaluate fit, repeat until best fit achieved (essentially MH).
Can that be achieved in PyMC3 or is there anything else you would recommend trying?
Is there a way to transcribe those models into PyMC3 and then proceed as usual?
Looking forward to hearing any recommendations on this.
Thank you in advance for any help.
PyMC3 is a package with a focus on continuous models and full posterior inference. It seems like you are targeting maximum likelihood in discrete models. While PyMC3 should support that to some degree (e.g. using
pm.find_MAP()) you might have better luck with e.g. https://github.com/hmmlearn/hmmlearn which was built for that purpose.
Otherwise I recommend you check out the upsides of full Bayesian inference.
You can also check out https://github.com/elfi-dev/elfi which is quite suitable for your problem.
Thanks a lot @twiecki!
Indeed, some of the models I am using are discrete but I also have a group of continuous models in hand and am definitely interested in a Bayesian inference approach.
Let me rephrase my question a bit since I might have given a wrong impression of what I am attempting. I am actually interested in getting a full posterior over the model parameters (and then using the most probable ones).
My main concern at the moment is that I do not know if there is a way to either use my existing models in conjunction with PyMC3 (i.e. can a simple python function be introduced as the model structure) or, if not, to re-write those models in “PyMC3 notation” to get the parameters posterior.
I might be making matters worse with my “explanation” so please feel free to ask for any clarifications or further details.
Hi @junpenglao, thank you for this suggestion! This package does look very interesting and might be the one to help in my endeavour; I will keep you posted once I get a chance to familiarise myself with it and give it a go.