-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bring structural time series functionality to PyMC #6284
Comments
This is a great idea. |
Currently, the road map is to build on top of Nicoleta's GSoC work:
While I dont have a timeline yet, the initial PR to add 1. is almost done. The majority of the work is to add a Kalman filter, but we need some experiment to explore what is the most performative approach as otherwise |
I have a prototype library for BSTS here: https://github.com/jessegrabowski/pymc_statespace Kalman filtering is brutally slow for anything but the most trivial problems. I spent a good chunk of time trying to optimize the Aesara code, but I feel like I went as far as I can, given my limited knowledge of Aesara. I have been exploring alternatives, including:
None have been particularly fruitful. (2) is a flight of fancy, and (3) hasn't ended up working very well. I think there is gold in the hills of (1), but I need to make an effort to reach out to @aseyboldt and see what needs to be done to get loop/scan support up and running in Nutpie, and whether Aesara linking could be cut out of the loop entirely to write a log-likelihood function directly with numba. |
+1 to this request. I am not an expert but would be happy to contribute (even unit-testing) |
thanks for the tag. am excited to see this come together |
Just to make the point that numba is the way to go, I put together a short gist notebook showing the difference between a numba-wrapped kalman filter implementation and the pure aesara implementation. Gradients aren't available, but using numba gives a 4x speedup (even faster when using slice sampler) I think this could be pushed even higher by making several adjustments, but there is work to do. A faster kalman filter would use I think a productive avenue of attack right now would be to get a working model compiled with nutpie and see what that offers in terms of speedup, without worrying about anything fancier. The framework I have errors out when compiling to nutpie -- something to do with the gradient of the scan in the logp. I'm going to open an issue over there and see if it goes anywhere. |
I'll +1 Numba. I essentially ported R's |
I was wondering if there are any updates on this? TIA |
Check out the module @jessegrabowski developed over pymc-experimental: https://discourse.pymc.io/t/pymc-experimental-now-includes-state-spaces-models/12773 |
We can actually close this as completed I'd say. |
The problem
PyMC already has some timeseries capability, but this needs to be expanded to cover Bayesian Structural Time series (STS). We do have some good time series example notebooks:
What we want
If we look at the Bayesian Structural Time Series section of the excellent Bayesian Modeling and Computation in Python book (by @aloctavodia, @canyon289, and @junpenglao) then we can see that it is trivial to build an STS model using
tfp.sts
:So long story short, it would be excellent if we can expand the native PyMC time series capabilities in general, but specifically for Bayesian STS.
Note: There is already an STS implementation in JAX here. One approach would be to call jax code using the kind of approach outlined in How to wrap a JAX function for use in PyMC. However, @ricardoV94 and @lucianopaz point out that that approach would restrict the backends available. Native PyMC/Aesara implementions would mean C/Python/Numba backends are available.
A list of relevant useful functionality that we may want to enable is given on the
tfp.sts
page.The text was updated successfully, but these errors were encountered: