nchopin / particles

Sequential Monte Carlo in python
MIT License
395 stars 75 forks source link

Make mcmc.PMMH work with any Feynman-Kac class #44

Closed nchopin closed 1 year ago

nchopin commented 2 years ago

By default, PMMH runs the bootstrap filter associated to the considered state-space model. It is possible to use a different algorithm, by setting argument fk_cls to another Feynman-Kac class; however, this works only for FK classes that have the same structure as state_space_models.Bootstrap or state_space_models.GuidedPF (taking as arguments data and ssm, for the state-space model). What if the user wants to specify a FK class with a different structure?

P3ngwings commented 1 year ago

Hi, I have a question regarding the PMMH algorithm. I'm mostly interested in filtering/smoothing, so I'm not up to date on every theoretical part of the parameter estimation. I only wanted to try it out to see if I get any useful results from the get-go. My model is a bit more complex but to boil down my problem: When picking the new 'guess' for theta in the step method of the GenericRWHM class (starting in line 231 in mcmc) any parameter is changed by a value determined via a random Gaussian sample. Here it gets problematic in my case: How does this not 'overshoot' in many small scenarios, say your theta is just one parameter and your prior distribution is a uniform distribution on [0.4, 0.45]. In almost every step this value is missed and the step gets a weight of -inf, making it obsolete.

I changed the new choice to a random sample from the prior distribution in my case (as a quick fix), but I don't know if that is the right (theoretical) way to choose the next guess for theta.

When trying out the example of the documentation (Bayesian Inference, PMMH) this also happens with the parameter 'rho' as it is uniform distributed in [-1,1] (I simply printed out the value for 'rho' and the value self.prop.lpost[0] to see if it is outside / -inf).

Regards, David

nchopin commented 1 year ago

Hi, to fix your problem (proposed values often fall outside the support of the prior distribution), you may :

  1. change the value of parameter `rw_cov' (default is Identity), which gives the covariance matrix of the random walk proposal. You could take something like tau * Identity, with tau=10^{-1} or 10^{-2}. This will make the steps of the random walk much smaller, so it's more likely you stay in the support of the prior.
  2. consider using an unconstrained prior, say a Gaussian with a small variance.

Regarding 1, I don't know whether you use the adaptive version (adaptive=True by default) or not. In the former case, the value of rw_cov is used only at the beginning, since the adaptive version is learning this covariance matrix sequentially from the chain.

Hope this helps. I guess your question shows the documentation is not so clear about these points, I will try to improve it.

nchopin commented 1 year ago

Closing this, as the initial issue has been addressed (experimental branch, module mcmc now better explains what to do).