joshspeagle / dynesty

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

Initial guesses #301

Closed bjnorfolk closed 3 years ago

bjnorfolk commented 3 years ago

Hi,

Wondering if it's possible to set an initial guess of the model parameters. I know there's the live_points dynesty parameter as listed in the API, but I'm not sure how to exactly use this. If I have some gaussian model with an amplitude (Amp), offset (r0) and fwhm (rw), is there a way to just pass the array init_guess=[amp,r0,rw] as an initial guess? Also, is there a commonly taken number of live points, nlive, used for given a number of model parameters?

Cheers, Brodie

joshspeagle commented 3 years ago

Hey Brodie!

So Nested Sampling (and hence dynesty) doesn't start from an initial guess -- the main strategy is to integrate over the entire prior, estimating the posterior along the way. So there isn't any way to do this because it runs a bit orthogonal to how the code operates. The live_points functionality allows for users to start from a pre-specified set of initial positions, which can be useful for restarting, repeatability tests, if the prior is a bit more complicated than the prior_transform function implies, etc.

As for the choice of nlive, in general you just want it to be > a few x n_params^2. The default options are I believe either 250 or 500, which tends to satisfy this for problems with fewer parameters. You can run with fewer or more, but with fewer the performance can substantially degrade (and you're more likely to miss solutions) and with you you generally have smaller sampling uncertainties/better performance (but it takes longer -- runtime is directly proportional to the number of live points for NestedSampler).

Hope this helps! Josh

bjnorfolk commented 3 years ago

Hi Josh thanks for the reply.

One final question, if I want to run dynasty on a cluster I need to specify the run time. For MCMC this is easy with the progress bar, but for dynasty I'm failing to extrapolate a run time from the output. Any suggestions?

Thanks again, Brodie

joshspeagle commented 3 years ago

This is a bit harder to do with dynesty since you're not running for a specified number of iterations in most cases, but rather a specified error tolerance. You can pass in things like maxcall or maxiter into the arguments to terminate sampling early once a certain number of likelihood evaluations and/or iterations are reached, but other than that the best strategy is to run a few tests to see what the wall clock runtimes can look like and then go from there.

bjnorfolk commented 3 years ago

Ok great, thanks for all the advice!