Girish Mahajan (Editor)

Nested sampling algorithm

Updated on
Edit
Like
Comment
Share on FacebookTweet on TwitterShare on LinkedInShare on Reddit

The nested sampling algorithm is a computational approach to the problem of comparing models in Bayesian statistics, developed in 2004 by physicist John Skilling.

Contents

Background

Bayes' theorem can be applied to a pair of competing models M 1 and M 2 for data D , one of which may be true (though which one is unknown) but which both cannot be true simultaneously. The posterior probability for M 1 may be calculated as:

P ( M 1 | D ) = P ( D | M 1 ) P ( M 1 ) P ( D ) = P ( D | M 1 ) P ( M 1 ) P ( D | M 1 ) P ( M 1 ) + P ( D | M 2 ) P ( M 2 ) = 1 1 + P ( D | M 2 ) P ( D | M 1 ) P ( M 2 ) P ( M 1 )

Given no a priori information in favor of M 1 or M 2 , it is reasonable to assign prior probabilities P ( M 1 ) = P ( M 2 ) = 1 / 2 , so that P ( M 2 ) / P ( M 1 ) = 1 . The remaining Bayes factor P ( D | M 2 ) / P ( D | M 1 ) is not so easy to evaluate, since in general it requires marginalizing nuisance parameters. Generally, M 1 has a set of parameters that can be grouped together and called θ , and M 2 has its own vector of parameters that may be of different dimensionality, but is still termed θ . The marginalization for M 1 is

P ( D | M 1 ) = d θ P ( D | θ , M 1 ) P ( θ | M 1 )

and likewise for M 2 . 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 P ( θ | D , M 1 ) . 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 Z = P ( D | M ) where M is M 1 or M 2 :

Start with N points θ 1 , . . . , θ N sampled from prior. for i = 1 to j do % The number of iterations j is chosen by guesswork. L i := min ( current likelihood values of the points ) ; X i := exp ( i / N ) ; w i := X i 1 X i Z := Z + L i w i ; Save the point with least likelihood as a sample point with weight w i . 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 L i . end return Z ;

At each iteration, X i is an estimate of the amount of prior mass covered by the hypervolume in parameter space of all points with likelihood greater than θ i . The weight factor w i is an estimate of the amount of prior mass that lies between two nested hypersurfaces { θ | P ( D | θ , M ) = P ( D | θ i 1 , M ) } and { θ | P ( D | θ , M ) = P ( D | θ i , M ) } . The update step Z := Z + L i w i computes the sum over i of L i w i to numerically approximate the integral

P ( D | M ) = P ( D | θ , M ) P ( θ | M ) d θ = P ( D | θ , M ) d P ( θ | M )

The idea is to subdivide the range of f ( θ ) = P ( D | θ , M ) and estimate, for each interval [ f ( θ i 1 ) , f ( θ i ) ] , 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.

Implementations

Example implementations demonstrating the nested sampling algorithm are publicly available for download, written in several programming languages.

  • Simple examples in C, R, or Python are on John Skilling's website.
  • A Haskell port of the above simple codes is on Hackage.
  • An example in R originally designed for fitting spectra is described at and is on GitHub.
  • An example in C++, named Diamonds, is on GitHub.
  • A highly modular Python parallel example for statistical physics and condensed matter physics uses is on GitHub.
  • Applications

    Since nested sampling was proposed in 2004, it has been used in many aspects of 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 algorithm to handle multimodal posteriors has been suggested as a means to detect astronomical objects in extant datasets. Other applications of nested sampling are in the field of finite element updating where the algorithm is used to choose an optimal finite element model, and this was applied to structural dynamics.

    References

    Nested sampling algorithm Wikipedia