jessegrabowski / gEconpy

A collection of tools for working with DSGE models in python, inspired by the R package gEcon
https://geconpy.readthedocs.io/en/latest/index.html
GNU General Public License v3.0
21 stars 4 forks source link

PyMC Integration #8

Open jessegrabowski opened 1 year ago

jessegrabowski commented 1 year ago

Ideally, all the model estimation should be handled by PyMC. I'm currently using Emcee because gradients aren't available for several steps in the solution process, including:

  1. Log linearization
  2. BK condition check
  3. Kalman filter

Statsmodels uses numerical approximation of gradients for (3), which I have found to be very unstable. Gradients are available if a Scan Op is used, but I have found this to be extremely slow (see here) (2) requires a QZ decomposition, which is non-differentiable. (1) is differentiable if is solved via cycle reduction, but this also requires a Scan.

Perhaps a jax scan could be faster?

jessegrabowski commented 1 year ago

I want to up the importance of this, without worrying about gradients. PyMC should be front and center for sampling and estimation. Still, two questions:

  1. Should the current prior declaration API be removed in favor of a PyMC model block?
  2. Is pm.sample_smc strictly superior to emcee?

I'm leaning towards yes for (1), because the infrastructure to handle many different distributions etc is getting quite heavy. It would also promote decoupling to remove anything to do with sampling from the gEconModel object and into a pm.draw style API that could be called internally where needed.

With respect to (2), early tests suggest that yes, it is better. But I am having some trouble with multiple chains and my numba linear algebra overloads.