joshspeagle / dynesty

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

Overflow fix #287

Closed segasai closed 3 years ago

segasai commented 3 years ago

Fix the overflow problem that happens when trying to run on 128d gaussian

In [1]: import test_highdim as T
In [7]: co= T.Config(np.random.RandomState(33),128)
In [9]: rstate=np.random.RandomState(33)
In [10]: co= T.Config(rstate,128)
In [11]: T.do_gaussian(co,'rslice','multi',rstate=rstate)
/home/skoposov/curwork/dynesty/py/dynesty/sampler.py:807: RuntimeWarning: overflow encountered in double_scalars
  math.exp(loglstar_new - logz_new) * loglstar_new)
/home/skoposov/curwork/dynesty/py/dynesty/sampler.py:810: RuntimeWarning: invalid value encountered in double_scalars
  dh = h_new - h
/home/skoposov/curwork/dynesty/py/dynesty/sampler.py:806: RuntimeWarning: overflow encountered in double_scalars
  lzterm = (math.exp(loglstar - logz_new) * loglstar +
....
/home/skoposov/curwork/dynesty/py/dynesty/sampler.py:807: RuntimeWarning: overflow encountered in double_scalars
  math.exp(loglstar_new - logz_new) * loglstar_new)
/home/skoposov/curwork/dynesty/py/dynesty/sampler.py:810: RuntimeWarning: invalid value encountered in double_scalars
  dh = h_new - h
---------------------------------------------------------------------------
OverflowError                             Traceback (most recent call last)
<ipython-input-11-cdc64999aaef> in <module>
----> 1 T.do_gaussian(co,'rslice','multi',rstate=rstate)

~/curwork/dynesty/tests/test_highdim.py in do_gaussian(co, sample, bound, rstate)
     74                                            rstate=rstate,
     75                                            vol_dec=.25)
---> 76     sampler.run_nested(print_progress=printing)
     77     res = sampler.results
     78     return res.logz[-1], res.logzerr[-1]

~/curwork/dynesty/py/dynesty/dynamicsampler.py in run_nested(self, nlive_init, maxiter_init, maxcall_init, dlogz_init, logl_max_init, n_effective_init, nlive_batch, wt_function, wt_kwargs, maxiter_batch, maxcall_batch, maxiter, maxcall, maxbatch, n_effective, stop_function, stop_kwargs, use_stop, save_bounds, print_progress, print_func, live_points)
   1554         try:
   1555             if not self.base:
-> 1556                 for results in self.sample_initial(
   1557                         nlive=nlive_init,
   1558                         dlogz=dlogz_init,

~/curwork/dynesty/py/dynesty/dynamicsampler.py in sample_initial(self, nlive, update_interval, first_update, maxiter, maxcall, logl_max, dlogz, n_effective, live_points, save_samples, resume)
    793         # Run the sampler internally as a generator.
    794         for i in range(1):
--> 795             for it, results in enumerate(
    796                     self.sampler.sample(maxiter=maxiter,
    797                                         save_samples=save_samples,

~/curwork/dynesty/py/dynesty/sampler.py in sample(self, maxiter, maxcall, dlogz, logl_max, n_effective, add_live, save_bounds, save_samples)
    805             logz_new = np.logaddexp(logz, logwt)
    806             lzterm = (math.exp(loglstar - logz_new) * loglstar +
--> 807                       math.exp(loglstar_new - logz_new) * loglstar_new)
    808             h_new = (math.exp(logdvol) * lzterm + math.exp(logz - logz_new) *
    809                      (h + logz) - logz_new)

OverflowError: math range error
coveralls commented 3 years ago

Pull Request Test Coverage Report for Build 947555196


Changes Missing Coverage Covered Lines Changed/Added Lines %
py/dynesty/results.py 10 14 71.43%
<!-- Total: 37 41 90.24% -->
Files with Coverage Reduction New Missed Lines %
py/dynesty/results.py 1 84.42%
<!-- Total: 1 -->
Totals Coverage Status
Change from base Build 941608477: 2.2%
Covered Lines: 3662
Relevant Lines: 4611

💛 - Coveralls