joshspeagle / dynesty

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

assert q > 0 # Should never fail AssertionError #396

Closed ghost closed 1 year ago

ghost commented 1 year ago

Dynesty version Dynesty 1.2.3, installed with pip

Your question I get the following error after running the sampler for 20h with mostly an effective sampling rate of about 9%, any insight as to why the sampling runs into this?

23012it [20:23:09, 45.69s/it, batch: 1 | bound: 206 | nc: 49 | ncall: 253012 | eff(%):  9.034 | loglstar: -205327278666723012it [20:23:54,  3.19s/it, batch: 1 | bound: 206 | nc: 49 | ncall: 253012 | eff(%):  9.034 | loglstar: -20532727866677340571355416887296.000 <   -inf <    inf | logz:   -inf +/-    nan | stop: 10000.000]
Traceback (most recent call last):
  File "run_dynesty.py", line 57, in <module>
    dsampler.run_nested(wt_kwargs ={'pfrac':1.0}, maxiter_init=10000, maxbatch=10)
  File "~/.local/lib/python3.7/site-packages/dynesty/dynamicsampler.py", line 1718, in run_nested
    stop_val=stop_val)
  File "~/.local/lib/python3.7/site-packages/dynesty/dynamicsampler.py", line 1862, in add_batch
    save_bounds=save_bounds):
  File "~/.local/lib/python3.7/site-packages/dynesty/dynamicsampler.py", line 1284, in sample_batch
    save_bounds=save_bounds)):
  File "~/.local/lib/python3.7/site-packages/dynesty/sampler.py", line 740, in sample
    u, v, logl, nc = self._new_point(loglstar_new)
  File "~/.local/lib/python3.7/site-packages/dynesty/sampler.py", line 360, in _new_point
    u, v, logl, nc, blob = self._get_point_value(loglstar)
  File "~/.local/lib/python3.7/site-packages/dynesty/sampler.py", line 343, in _get_point_value
    self._fill_queue(loglstar)
  File "~/.local/lib/python3.7/site-packages/dynesty/sampler.py", line 311, in _fill_queue
    point, axes = self.propose_point(*args)
  File "~/.local/lib/python3.7/site-packages/dynesty/nestedsamplers.py", line 600, in propose_unif
    u, idx = self.mell.sample(rstate=self.rstate)
  File "~/.local/lib/python3.7/site-packages/dynesty/bounding.py", line 472, in sample
    assert q > 0  # Should never fail
AssertionError
segasai commented 1 year ago

Thanks for the report!

This is definitely unexpected. Is there any chance that you can run this in the session with a debugger? I'd need to know the variables around here https://github.com/joshspeagle/dynesty/blob/0ee1324f8b85f3e8e7a4da65c87c1ea8ec712288/py/dynesty/bounding.py#L472

The reason for the error is that the point sampled from the ellipsoid fails the test X^T A^ X <1 where A is a matrix definining the ellipsoid. The most likely guess why that happens is that this is a purely numerical artefact and we need to replace the test by q<1+eps.

so if you could print one thing from the debugger after the error, it would be this np.einsum('ai,aij,aj->a', delts, self.ams, delts).min()

The expectation is that it will be something 1+ very small number

segasai commented 1 year ago

I think I have a patch which may improve things (assuming my hypothesis about the cause was correct) if you could try this branch https://github.com/joshspeagle/dynesty/tree/v1.2.3patch

ghost commented 1 year ago

Hi segasai, yes that patch appears to have removed the bug from appearing! Thanks for the quick fix.

segasai commented 1 year ago

great! The next release will likely be a 2.0.0, it will contain that fix aside from many other improvements.