Nested sampling algorithm
||This article provides insufficient context for those unfamiliar with the subject. (October 2009)|
Bayes' theorem can be applied to a pair of competing models and for data , one of which may be true (though which one is not known) but which both cannot simultaneously be true, as follows:
Given no a priori information in favor of or , it is reasonable to assign prior probabilities , so that . The remaining ratio is not so easy to evaluate since in general it requires marginalization of nuisance parameters. Generally, has a collection of parameters that can be lumped together and called , and has its own vector of parameters that may be of different dimensionality but is still referred to as . The marginalization for is
and likewise for . This integral is often analytically intractable, and in these cases it is necessary to employ a numerical algorithm to find an approximation. The nested sampling algorithm was developed by John Skilling specifically to approximate these marginalization integrals, and it has the added benefit of generating samples from the posterior distribution . It is an alternative to methods from the Bayesian literature such as bridge sampling and defensive importance sampling.
Here is a simple version of the nested sampling algorithm, followed by a description of how it computes the marginal probability density where is or :
Start with points sampled from prior. for to do % The number of iterations j is chosen by guesswork. current likelihood values of the points; Save the point with least likelihood as a sample point with weight . Update the point with least likelihood with some Markov Chain Monte Carlo steps according to the prior, accepting only steps that keep the likelihood above . end return ;
At each iteration, is an estimate of the amount of prior mass covered by the hypervolume in parameter space of all points with likelihood greater than . The weight factor is an estimate of the amount of prior mass that lies between two nested hypersurfaces and . The update step computes the sum over of to numerically approximate the integral
The idea is to chop up the range of and estimate, for each interval , how likely it is a priori that a randomly chosen would map to this interval. This can be thought of as a Bayesian's way to numerically implement Lebesgue integration.
- Simple example code written in C, R, or Python demonstrating this algorithm can be downloaded from John Skilling's website
- There is also a Haskell port of the above simple codes on Hackage
- An implementation in R originally designed for fitting of spectra is described at  and can be obtained on GitHub at 
- A highly modular Python parallel implementation of Nested Sampling for statistical physics and condensed matter physics applications is publicly available from GitHub .
Since nested sampling was proposed in 2004, it has been used in multiple settings within the field of astronomy. One paper suggested using nested sampling for cosmological model selection and object detection, as it "uniquely combines accuracy, general applicability and computational feasibility." A refinement of the nested sampling algorithm to handle multimodal posteriors has also been suggested as a means of detecting astronomical objects in existing datasets.
- Skilling, John (2004). "Nested Sampling". AIP Conference Proceedings 735: 395–405. doi:10.1063/1.1835238.
- Skilling, John (2006). "Nested Sampling for General Bayesian Computation". Bayesian Analysis 1 (4): 833–860. doi:10.1214/06-BA127.
- Chen, Ming-Hui, Shao, Qi-Man, and Ibrahim, Joseph George (2000). Monte Carlo methods in Bayesian computation. Springer. ISBN 978-0-387-98935-8.
- Mukherjee, P., Parkinson, D., and Liddle, A.R. (2006). "A Nested Sampling Algorithm for Cosmological Model Selection". Astrophysical Journal 638 (2): 51–54. arXiv:astro-ph/0508461. Bibcode:2005astro.ph..8461M. doi:10.1086/501068.
- Feroz, F., Hobson, M.P. (2008). "Multimodal nested sampling: an efficient and robust alternative to Markov Chain Monte Carlo methods for astronomical data analyses". MNRAS 384 (2): 449–463. arXiv:0704.3704. Bibcode:2008MNRAS.384..449F. doi:10.1111/j.1365-2966.2007.12353.x.