joshspeagle / dynesty

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

Probabilities do not sum to 1 #263

Closed segasai closed 3 years ago

segasai commented 3 years ago

While running recent version of the code, I've hit this error.

  File "/home/skoposov/pyenv38/lib/python3.8/site-packages/dynesty/dynamicsampler.py", line 1596, in run_nested
    passback = self.add_batch(nlive=nlive_batch,
  File "/home/skoposov/pyenv38/lib/python3.8/site-packages/dynesty/dynamicsampler.py", line 1716, in add_batch
    for results in self.sample_batch(nlive_new=nlive,
  File "/home/skoposov/pyenv38/lib/python3.8/site-packages/dynesty/dynamicsampler.py", line 1054, in sample_batch
    subset = self.rstate.choice(np.nonzero(subset)[0],
  File "mtrand.pyx", line 933, in numpy.random.mtrand.RandomState.choice
ValueError: probabilities do not sum to 1

which was recently introduced code

I haven't had a chance to investigate this. I'm guessing it has to do with very large/small/inf values in logwt

joshspeagle commented 3 years ago

Yes, this can happen due to numerical precision issues in logsumexp, and can be fixed using a sum operation.