minaskar / zeus

⚡️ zeus: Lightning Fast MCMC ⚡️
https://zeus-mcmc.readthedocs.io/
GNU General Public License v3.0
225 stars 34 forks source link

zeus fails to estimate parameters on simple example where emcee has no trouble #23

Open roboticarm2000 opened 2 years ago

roboticarm2000 commented 2 years ago

I'm trying a basic example, estimating mean and variance of a bivariate normal distribution given independent samples.
For this example, the prior on the mean and variance is that they are positive.

Emcee has no trouble finding the parameters. Zeus, however, fails with the following error:

RuntimeError: Number of expansions exceeded maximum limit! Make sure that the pdf is well-defined. Otherwise increase the maximum limit (maxiter=10^4 by default).

I tried specifying light_mode true or other moves without success.

Thanks, Alexis

test7.zip

minaskar commented 2 years ago

Hi Alexis,

I think the problem in this case is the use of improper priors (the prior integral diverges) for the means and variances. In general, I recommend not to use improper priors as they can render the posterior improper as well. When that happens, Metropolis-Hastings-like samplers such as emcee could give either reasonable or erroneous results with no guarantee though.

In general, a proper prior, even a very broad and uninformative one can save one from such problems. For instance, in the example that you describe, using a flat (or uniform) prior on either mean or variance (or both) can fix the issue, even if the upper bound is very high (e.g. 200-1000).

That said, there's another way to force zeus to give consistent results with emcee in this case. By setting maxstep equal to 1 or 2 you can force zeus to take smaller steps in parameter space (like emcee does) and thus don't try to explore regions of parameter space for large values of mu and sigma. In the default configuration of zeus this is exactly what's triggering the error message, zeus is expanding the "slice" trying to capture states with very high variance due to the improper prior.

Let me know if you have any more questions.

Cheers, Minas

roboticarm2000 commented 2 years ago

thanks. I'll give it a shot.