joshspeagle / dynesty

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

add_batch volume of the single point #262

Closed segasai closed 3 years ago

segasai commented 3 years ago

It looks like the recent change with self.sampler.update(0) leads to issues: see below

 File "/home/skoposov/pyenv38/lib/python3.8/site-packages/dynesty/dynamicsampler.py", line 1595, in run_nested
    passback = self.add_batch(nlive=nlive_batch,
  File "/home/skoposov/pyenv38/lib/python3.8/site-packages/dynesty/dynamicsampler.py", line 1715, 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 1079, in sample_batch
    bound = self.sampler.update(0)
  File "/home/skoposov/pyenv38/lib/python3.8/site-packages/dynesty/nestedsamplers.py", line 689, in update
    self.mell.update(self.live_u[:, :self.ncdim],
  File "/home/skoposov/pyenv38/lib/python3.8/site-packages/dynesty/bounding.py", line 618, in update
    firstell = bounding_ellipsoid(points, pointvol=pointvol)
  File "/home/skoposov/pyenv38/lib/python3.8/site-packages/dynesty/bounding.py", line 1410, in bounding_ellipsoid
    raise ValueError("Cannot compute a bounding ellipsoid to a "
ValueError: Cannot compute a bounding ellipsoid to a single point if `pointvol` is not specified.

The investigation shows that this happens when the subset https://github.com/joshspeagle/dynesty/blob/b3dbd52369a9b9172b20e76cb53ddd7f43bf9a1c/py/dynesty/dynamicsampler.py#L1035 has only one element and therefore the ellipsoid has only one point. It is still not clear to me what value is the most appropriate there. So for my own purposese I've temporarily set the volume to math.exp(-1. * len(saved_logl) / nblive)

joshspeagle commented 3 years ago

That seems like a reasonable choice. If you want to submit a PR for this issue, that'd be great.

segasai commented 3 years ago

Can you provide the reasoning again for this or any other formula ? I really can't as it seems to me just a random placeholder, copied from last time. To me lets say 1/len(saved_logl) makes at least some sense. I'd rather have something at least somewhat justifiable.

joshspeagle commented 3 years ago

Yes. So essentially this is just trying to say that at a given iteration you expect to have a prior volume of X, so you shouldn't be fitting volumes of ellipsoids that are substantially smaller. For a fixed number of live points K, this value is X = exp(-i/K). This has a correspondence with i -> len(saved_logl) and K -> nblive. (Things get more complicated for the dynamic case here where Nlive_eff > Nlive_batch, so this will generally be an underestimate IIRC.)