joshspeagle / dynesty

Dynamic Nested Sampling package for computing Bayesian posteriors and evidences
https://dynesty.readthedocs.io/
MIT License
357 stars 77 forks source link

Nested Sampling error #148

Closed jvines closed 5 years ago

jvines commented 5 years ago

Hi @joshspeagle, I have implemented dynesty in a 7 dimensional problem and when running it I get the following error:

Traceback (most recent call last): File "test.py", line 63, in f.fit() File "/Users/jvines/github/SED_fitting/code/fitter.py", line 185, in fit self.fit_dynesty() File "/Users/jvines/github/SED_fitting/code/fitter.py", line 244, in fit_dynesty sampler.run_nested(dlogz=self.dlogz) File "/anaconda3/lib/python3.7/site-packages/dynesty-0.9.5.3-py3.7.egg/dynesty/sampler.py", line 831, in run_nested File "/anaconda3/lib/python3.7/site-packages/dynesty-0.9.5.3-py3.7.egg/dynesty/sampler.py", line 702, in sample File "/anaconda3/lib/python3.7/site-packages/dynesty-0.9.5.3-py3.7.egg/dynesty/sampler.py", line 331, in _new_point File "/anaconda3/lib/python3.7/site-packages/dynesty-0.9.5.3-py3.7.egg/dynesty/sampler.py", line 315, in _get_point_value File "/anaconda3/lib/python3.7/site-packages/dynesty-0.9.5.3-py3.7.egg/dynesty/sampler.py", line 284, in _fill_queue File "/anaconda3/lib/python3.7/site-packages/dynesty-0.9.5.3-py3.7.egg/dynesty/nestedsamplers.py", line 622, in propose_live File "mtrand.pyx", line 992, in mtrand.RandomState.randint ValueError: Range cannot be empty (low >= high) unless no samples are taken

Before this happens the following warnings appear:

/anaconda3/lib/python3.7/site-packages/dynesty-0.9.5.3-py3.7.egg/dynesty/bounding.py:605: RuntimeWarning: invalid value encountered in double_scalars /anaconda3/lib/python3.7/site-packages/dynesty-0.9.5.3-py3.7.egg/dynesty/bounding.py:182: RuntimeWarning: invalid value encountered in double_scalars /anaconda3/lib/python3.7/site-packages/dynesty-0.9.5.3-py3.7.egg/dynesty/bounding.py:400: RuntimeWarning: invalid value encountered in double_scalars /anaconda3/lib/python3.7/site-packages/dynesty-0.9.5.3-py3.7.egg/dynesty/bounding.py:605: RuntimeWarning: invalid value encountered in double_scalars /anaconda3/lib/python3.7/site-packages/dynesty-0.9.5.3-py3.7.egg/dynesty/bounding.py:182: RuntimeWarning: invalid value encountered in double_scalars /anaconda3/lib/python3.7/site-packages/dynesty-0.9.5.3-py3.7.egg/dynesty/bounding.py:400: RuntimeWarning: invalid value encountered in double_scalars

This happens at this point of the run:

iter: 30971 | bound: 223 | nc: 25 | ncall: 840718 | eff(%): 3.684 | loglstar: -inf < 310.038 < inf | logz: 284.271 +/- 0.145 | dlogz: 0.030 > 0.010

The call I'm doing to dynesty is the following:

sampler = dynesty.NestedSampler( dynesty_log_like, pt_dynesty, 7, nlive=1000, bound='multi', sample='rwalk' ) sampler.run_nested(dlogz=0.01)

I could run dynesty with a higher dlogz, like 0.5, but that's not the idea... Could you help me out with this?

Thanks!

joshspeagle commented 5 years ago

This appears to suggest that the bounding decomposition for multi is failing because of a bad ellipsoid. That might be due to a bad sample or something else. Checking the current version of the code, I don't see any line corresponding to this error:

/anaconda3/lib/python3.7/site-packages/dynesty-0.9.5.3-py3.7.egg/dynesty/bounding.py:182: RuntimeWarning: invalid value encountered in double_scalars

Could you check what version you're running? I know I tried to squash a few ellipsoid decomposition bugs between slightly earlier versions and the current stable release.

jvines commented 5 years ago

Hi @joshspeagle , I'm using the version 0.9.5.3

joshspeagle commented 5 years ago

Okay, great. Do you have a copy of either the sampler, results, etc. that I can take a look at? I keep trying to pin down all these bugs, but it might be getting to the time where I should re-write some code blocks from scratch...

jvines commented 5 years ago

Hi Josh, sorry I've been away these days. I'll replicate the error and save the sampler and send it your way! I expect to be able to do this within the following week.

joshspeagle commented 5 years ago

I'm going to close this for now since it mirrors #140. Let me know here/there if there are any updates.

jvines commented 5 years ago

Hi @joshspeagle I haven't reproduced this error yet, but I'm getting an odd problem when running the dynamic nested sampler with custom init_nlive and init_dlogz. In this particular example, I'm setting the init_nlive to the default, 500, and the init_dlogz to 0.5, and once it reaches that point the dlogz goes down to 0.001 and the extremely inefficient warnings appear again. Is this expected behavior?

jvines commented 5 years ago

Hi @joshspeagle

I tried to run the exact same setup to reproduce the error, but it worked... Maybe the reason was my priors (as I've updated some of them)

joshspeagle commented 5 years ago

once it reaches that point the dlogz goes down to 0.001

This is expected behavior -- what's happening is you're adding the last set of live points into the chain of samples, which allows you to go "beyond" the input dlogz limit. After that, you should be starting to add points in batches with nlive_batch live points in each batch. This might be where the warnings start appearing. Is that correct?

Maybe the reason was my priors (as I've updated some of them)

This is definitely possible since the behavior can depend on the size/scope of the priors (as with MCMC).

jvines commented 5 years ago

This might be where the warnings start appearing. Is that correct?

Indeed, that is correct. It's curious to me though, why if I put the dlogz_init as 0.5 it gets stuck in the warnings, but if I keep it at the default 0.01, it doesn't.

jvines commented 4 years ago

Hi @joshspeagle , I've been getting this error again repeatedly alongside the singular matrix error. What do I need to send you to help figure out what might be going on??

joshspeagle commented 4 years ago

I think you’ve commented here (and elsewhere?) about possible issues. The most helpful thing is to send me as much information as possible to reproduce/diagnose the problem. Usually instances of the sampler right after hitting the error (or at some earlier sampling state) are best, but if you have a copy of the “results” dictionary that works too. If you have also run this problem with another sampler, a copy of those results and a description of what’s going on also helps.

In any case, please send me an email with more details and we can iterate from there!