Closed andrewfowlie closed 2 years ago
Hi @andrewfowlie. As we discussed offline, I think that in fact we can already achieve this functionality with PolyChord's dynamic nested sampling capacity. PolyChord implements dynamic nested sampling by passing settings.nlives
as a dictionary mapping loglikelihood generation contours to the number of live points desired within that loglikelihood. To achieve the mode of 'stopping generating samples and finishing the run when the lowest likelihood live point reaches logLstop
' one would therefore pass a dictionary of {logLstop:0}
.
Here is a very minimal working example:
from pypolychord import run_polychord
from pypolychord.settings import PolyChordSettings
# settings to tell PolyChord to wind down when logL_limit is reached
logLstop = -0.1
nDims = 4
settings = PolyChordSettings(nDims, 0)
settings.nlives = {logLstop:0}
settings.max_ndead = -1
# run a toy gaussian likelihood with center 0.5, width 0.1, max 0.0
likelihood = lambda t: (-(t-0.5)@(t-0.5)/2/0.1**2, [])
run_polychord(likelihood, nDims, 0, settings)
And a plot showing the nlive profile this generates
from anesthetic import NestedSamples
import matplotlib.pyplot as plt
samples = NestedSamples(root='chains/test')
plt.plot(samples.logL, samples.nlive)
plt.axvline(logLstop, color='k', ls='--')
plt.xlim(-0.5,0)
plt.xlabel('logL')
plt.ylabel('nlive')
plt.savefig('nlive.png')
Does this accomplish the same thing within the existing framework?
yes! that's it. And then the iteration at which it stopped can be found by ndead - nlive?
Indeed! Shame we didn't spot this for the paper, but nice that there is a clean way to implement it. I had not thought of using PolyChord's dynamic nested sampling as a stopping criteria before, but I suspect there may be other uses of this.
Adds
logLstop
setting, with default 1e30. Run stops collecting new samples (i.e.,more_samples_needed
gives false) once the smallest loglike amongst active live points exceedslogLstop
.The setting is accessible through the Python interface too.