nestedsamplers.jl

Implementations of single and multi-ellipsoid nested sampling

https://github.com/chalk-lab/nestedsamplers.jl

Science Score: 75.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
    Found 3 DOI reference(s) in README
  • Academic publication links
    Links to: zenodo.org
  • Academic email domains
  • Institutional organization owner
    Organization chalk-lab has institutional domain (mlg.eng.cam.ac.uk)
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (13.6%) to scientific vocabulary

Keywords

bayesian-inference evidence-based nested-samplers nested-sampling
Last synced: 4 months ago · JSON representation ·

Repository

Implementations of single and multi-ellipsoid nested sampling

Basic Info
Statistics
  • Stars: 47
  • Watchers: 5
  • Forks: 10
  • Open Issues: 14
  • Releases: 20
Topics
bayesian-inference evidence-based nested-samplers nested-sampling
Created about 6 years ago · Last pushed 8 months ago
Metadata Files
Readme License Citation

README.md

NestedSamplers.jl

Build Status PkgEval Coverage LICENSE

Stable Dev

Implementations of single- and multi-ellipsoidal nested sampling algorithms in pure Julia. We implement the AbstractMCMC.jl interface, allowing straightforward sampling from a variety of statistical models.

This package was heavily influenced by nestle, dynesty, and NestedSampling.jl.

Citing

DOI

If you use this library, or a derivative of it, in your work, please consider citing it. This code is built off a multitude of academic works, which have been noted in the docstrings where appropriate. These references, along with references for the more general calculations, can all be found in CITATION.bib

Installation

To use the nested samplers first install this library

julia julia> ]add NestedSamplers

Usage

For in-depth usage, see the online documentation. In general, you'll need to write a log-likelihood function and a prior transform function. These are supplied to a NestedModel, defining the statistical model

```julia using NestedSamplers using Distributions using LinearAlgebra

logl(X) = logpdf(MvNormal([1, -1], I), X) prior(X) = 4 .* (X .- 0.5)

or equivalently

priors = [Uniform(-2, 2), Uniform(-2, 2)] model = NestedModel(logl, priors) ```

after defining the model, set up the nested sampler. This will involve choosing the bounding space and proposal scheme, or you can rely on the defaults. In addition, we need to define the dimensionality of the problem and the number of live points. More points results in a more precise evidence estimate at the cost of runtime. For more information, see the docs.

```julia bounds = Bounds.MultiEllipsoid prop = Proposals.Slice(slices=10)

1000 live points

sampler = Nested(2, 1000; bounds=bounds, proposal=prop) ```

once the sampler is set up, we can leverage all of the AbstractMCMC.jl interface, including the step iterator, transducer, and a convenience sample method. The sample method takes keyword arguments for the convergence criteria.

Note: both the samples and the sampler state will be returned by sample

julia using StatsBase chain, state = sample(model, sampler; dlogz=0.2)

you can resample taking into account the statistical weights, again using StatsBase

julia chain_resampled = sample(chain, Weights(vec(chain["weights"])), length(chain))

These are chains from MCMCChains.jl, which offer a lot of flexibility in exploring posteriors, combining data, and offering lots of convenient conversions (like to DataFrames).

Finally, we can see the estimate of the Bayesian evidence

julia using Measurements state.logz ± state.logzerr

Contributions and Support

ColPrac: Contributor's Guide on Collaborative Practices for Community Packages

Primary Author: Miles Lucas (@mileslucas)

Contributions are always welcome! In general, contributions should follow ColPrac. Take a look at the issues for ideas of open problems! To discuss ideas or plan contributions, open a discussion.

Owner

  • Name: Learning and Inference Group
  • Login: chalk-lab
  • Kind: organization
  • Location: United Kingdom

Hong Ge's Research Group at Cambridge University

Citation (CITATION.bib)

# zenodo DOI citation
@software{miles_lucas_2021_5808196,
  author       = {Miles Lucas and
                  Saranjeet Kaur and
                  Tor Erlend Fjelde and
                  Alexander Plavin and
                  Hong Ge and
                  Cameron Pfiffer},
  title        = {TuringLang/NestedSamplers.jl: v0.8.1},
  month        = dec,
  year         = 2021,
  publisher    = {Zenodo},
  version      = {v0.8.1},
  doi          = {10.5281/zenodo.5808196},
  url          = {https://doi.org/10.5281/zenodo.5808196}
}

## References
# original nested sampling algorithm
@article{skillingNestedSampling2004,
	title = {Nested {Sampling}},
	volume = {735},
	url = {https://ui.adsabs.harvard.edu/abs/2004AIPC..735..395S},
	doi = {10.1063/1.1835238},
	abstract = {"The evidence Z is often the single most important number in the [Bayesian] problem and I think every effort should be devoted to calculating it" (MacKay 2003). Nested sampling does this by giving a direct estimate of the density of states. Posterior samples are an optional by-product.},
	urldate = {2021-11-25},
	author = {Skilling, John},
	month = nov,
	year = {2004},
	note = {Conference Name: Bayesian Inference and Maximum Entropy Methods in Science and Engineering: 24th International Workshop on Bayesian Inference and Maximum Entropy Methods in Science and Engineering
ADS Bibcode: 2004AIPC..735..395S},
	keywords = {02.50.Tt, Inference methods},
	pages = {395--405},
}
# derived work, analysis of nested sampling errors
@article{speagleDYNESTYDynamicNested2020,
	title = {{DYNESTY}: a dynamic nested sampling package for estimating {Bayesian} posteriors and evidences},
	volume = {493},
	issn = {0035-8711},
	shorttitle = {{DYNESTY}},
	url = {https://ui.adsabs.harvard.edu/abs/2020MNRAS.493.3132S},
	doi = {10.1093/mnras/staa278},
	abstract = {We present DYNESTY, a public, open-source, PYTHON package to estimate Bayesian posteriors and evidences (marginal likelihoods) using the dynamic nested sampling methods developed by Higson et al. By adaptively allocating samples based on posterior structure, dynamic nested sampling has the benefits of Markov chain Monte Carlo (MCMC) algorithms that focus exclusively on posterior estimation while retaining nested sampling's ability to estimate evidences and sample from complex, multimodal distributions. We provide an overview of nested sampling, its extension to dynamic nested sampling, the algorithmic challenges involved, and the various approaches taken to solve them in this and previous work. We then examine DYNESTY's performance on a variety of toy problems along with several astronomical applications. We find in particular problems DYNESTY can provide substantial improvements in sampling efficiency compared to popular MCMC approaches in the astronomical literature. More detailed statistical results related to nested sampling are also included in the appendix.},
	urldate = {2021-11-25},
	journal = {Monthly Notices of the Royal Astronomical Society},
	author = {Speagle, Joshua S.},
	month = apr,
	year = {2020},
	note = {ADS Bibcode: 2020MNRAS.493.3132S},
	keywords = {Astrophysics - Instrumentation and Methods for Astrophysics, methods: data analysis, methods: statistical, Statistics - Computation},
	pages = {3132--3158},
}
# error analysis of Bayesian evidence estimation
@techreport{chopinPropertiesNestedSampling2008,
	title = {Properties of {Nested} {Sampling}},
	url = {https://ui.adsabs.harvard.edu/abs/2008arXiv0801.3887C},
	abstract = {Nested sampling is a simulation method for approximating marginal likelihoods proposed by Skilling (2006). We establish that nested sampling has an approximation error that vanishes at the standard Monte Carlo rate and that this error is asymptotically Gaussian. We show that the asymptotic variance of the nested sampling approximation typically grows linearly with the dimension of the parameter. We discuss the applicability and efficiency of nested sampling in realistic problems, and we compare it with two current methods for computing marginal likelihood. We propose an extension that avoids resorting to Markov chain Monte Carlo to obtain the simulated points.},
	urldate = {2022-01-08},
	author = {Chopin, Nicolas and Robert, Christian},
	month = jan,
	year = {2008},
	note = {Publication Title: arXiv e-prints
ADS Bibcode: 2008arXiv0801.3887C
Type: article},
	keywords = {Mathematics - Statistics Theory, Statistics - Computation},
}
# random walk and random stagger sampling
@article{skillingNestedSamplingGeneral2006a,
	title = {Nested sampling for general {Bayesian} computation},
	volume = {1},
	issn = {1936-0975, 1931-6690},
	url = {https://projecteuclid.org/journals/bayesian-analysis/volume-1/issue-4/Nested-sampling-for-general-Bayesian-computation/10.1214/06-BA127.full},
	doi = {10.1214/06-BA127},
	abstract = {Nested sampling estimates directly how the likelihood function relates to prior mass. The evidence (alternatively the marginal likelihood, marginal density of the data, or the prior predictive) is immediately obtained by summation. It is the prime result of the computation, and is accompanied by an estimate of numerical uncertainty. Samples from the posterior distribution are an optional by-product, obtainable for any temperature. The method relies on sampling within a hard constraint on likelihood value, as opposed to the softened likelihood of annealing methods. Progress depends only on the shape of the "nested" contours of likelihood, and not on the likelihood values. This invariance (over monotonic re-labelling) allows the method to deal with a class of phase-change problems which effectively defeat thermal annealing.},
	number = {4},
	urldate = {2022-01-08},
	journal = {Bayesian Analysis},
	author = {Skilling, John},
	month = dec,
	year = {2006},
	note = {Publisher: International Society for Bayesian Analysis},
	keywords = {algorithm, annealing, Bayesian computation, evidence, marginal likelihood, Model selection, nest, phase change},
	pages = {833--859},
}
# orthogonal (Gibbs) slice sampling
@article{nealSliceSampling2003,
	title = {Slice sampling},
	volume = {31},
	issn = {0090-5364, 2168-8966},
	url = {https://projecteuclid.org/journals/annals-of-statistics/volume-31/issue-3/Slice-sampling/10.1214/aos/1056562461.full},
	doi = {10.1214/aos/1056562461},
	abstract = {Markov chain sampling methods that adapt to characteristics of the distribution being sampled can be constructed using the principle that one can ample from a distribution by sampling uniformly from the region under the plot of its density function. A Markov chain that converges to this uniform distribution can be constructed by alternating uniform sampling in the vertical direction with uniform sampling from the horizontal "slice" defined by the current vertical position, or more generally, with some update that leaves the uniform distribution over this slice invariant. Such "slice sampling" methods are easily implemented for univariate distributions, and can be used to sample from a multivariate distribution by updating each variable in turn. This approach is often easier to implement than Gibbs sampling and more efficient than simple Metropolis updates, due to the ability of slice sampling to adaptively choose the magnitude of changes made. It is therefore attractive for routine and automated use. Slice sampling methods that update all variables simultaneously are also possible. These methods can adaptively choose the magnitudes of changes made to each variable, based on the local properties of the density function. More ambitiously, such methods could potentially adapt to the dependencies between variables by constructing local quadratic approximations. Another approach is to improve sampling efficiency by suppressing random walks. This can be done for univariate slice sampling by "overrelaxation," and for multivariate slice sampling by "reflection" from the edges of the slice.},
	number = {3},
	urldate = {2022-01-08},
	journal = {The Annals of Statistics},
	author = {Neal, Radford M.},
	month = jun,
	year = {2003},
	note = {Publisher: Institute of Mathematical Statistics},
	keywords = {65C05, 65C60, Adaptive methods, auxiliary variables, dynamical methods, Gibbs sampling, Markov chain Monte Carlo, Metropolis algorithm, overrelaxation},
	pages = {705--767},
}
# random slice sampling
@article{handleyPolychordNestedSampling2015,
	title = {polychord: nested sampling for cosmology.},
	volume = {450},
	issn = {0035-8711},
	shorttitle = {polychord},
	url = {https://ui.adsabs.harvard.edu/abs/2015MNRAS.450L..61H},
	doi = {10.1093/mnrasl/slv047},
	abstract = {POLYCHORD is a novel nested sampling algorithm tailored for high-dimensional parameter spaces. In addition, it can fully exploit a hierarchy of parameter speeds such as is found in COSMOMC and CAMB. It utilizes slice sampling at each iteration to sample within the hard likelihood constraint of nested sampling. It can identify and evolve separate modes of a posterior semi-independently and is parallelized using OPENMPI. POLYCHORD is available for download at http://ccpforge.cse.rl.ac.uk/gf/project/polychord/.},
	urldate = {2022-01-08},
	journal = {Monthly Notices of the Royal Astronomical Society},
	author = {Handley, W. J. and Hobson, M. P. and Lasenby, A. N.},
	month = jun,
	year = {2015},
	note = {ADS Bibcode: 2015MNRAS.450L..61H},
	keywords = {Astrophysics - Cosmology and Nongalactic Astrophysics, Astrophysics - Instrumentation and Methods for Astrophysics, methods: data analysis, methods: statistical},
	pages = {L61--L65},
}
# random slice sampling
@article{handleyPOLYCHORDNextgenerationNested2015,
	title = {{POLYCHORD}: next-generation nested sampling},
	volume = {453},
	issn = {0035-8711},
	shorttitle = {{POLYCHORD}},
	url = {https://ui.adsabs.harvard.edu/abs/2015MNRAS.453.4384H},
	doi = {10.1093/mnras/stv1911},
	abstract = {POLYCHORD is a novel nested sampling algorithm tailored for high-dimensional parameter spaces. This paper coincides with the release of POLYCHORD v1.6, and provides an extensive account of the algorithm. POLYCHORD utilizes slice sampling at each iteration to sample within the hard likelihood constraint of nested sampling. It can identify and evolve separate modes of a posterior semi-independently, and is parallelized using OPENMPI. It is capable of exploiting a hierarchy of parameter speeds such as those present in COSMOMC and CAMB, and is now in use in the COSMOCHORD and MODECHORD codes. POLYCHORD is available for download from http://ccpforge.cse.rl.ac.uk/gf/project/polychord/.},
	urldate = {2022-01-08},
	journal = {Monthly Notices of the Royal Astronomical Society},
	author = {Handley, W. J. and Hobson, M. P. and Lasenby, A. N.},
	month = nov,
	year = {2015},
	note = {ADS Bibcode: 2015MNRAS.453.4384H},
	keywords = {Astrophysics - Instrumentation and Methods for Astrophysics, methods: data analysis, methods: statistical},
	pages = {4384--4398},
}
# ellipsoidal bounding
@article{mukherjeeNestedSamplingAlgorithm2006,
	title = {A {Nested} {Sampling} {Algorithm} for {Cosmological} {Model} {Selection}},
	volume = {638},
	issn = {0004-637X},
	url = {https://ui.adsabs.harvard.edu/abs/2006ApJ...638L..51M},
	doi = {10.1086/501068},
	abstract = {The abundance of cosmological data becoming available means that a wider range of cosmological models are testable than ever before. However, an important distinction must be made between parameter fitting and model selection. While parameter fitting simply determines how well a model fits the data, model selection statistics, such as the Bayesian evidence, are now necessary to choose between these different models, and in particular to assess the need for new parameters. We implement a new evidence algorithm known as nested sampling, which combines accuracy, generality of application, and computational feasibility, and we apply it to some cosmological data sets and models. We find that a five-parameter model with a Harrison-Zel'dovich initial spectrum is currently preferred.},
	urldate = {2022-01-08},
	journal = {The Astrophysical Journal},
	author = {Mukherjee, Pia and Parkinson, David and Liddle, Andrew R.},
	month = feb,
	year = {2006},
	note = {ADS Bibcode: 2006ApJ...638L..51M},
	keywords = {Astrophysics, Cosmology: Theory},
	pages = {L51--L54},
}
# multi-ellipsoid sampling
@article{ferozMultimodalNestedSampling2008,
	title = {Multimodal nested sampling: an efficient and robust alternative to {Markov} {Chain} {Monte} {Carlo} methods for astronomical data analyses},
	volume = {384},
	issn = {0035-8711},
	shorttitle = {Multimodal nested sampling},
	url = {https://ui.adsabs.harvard.edu/abs/2008MNRAS.384..449F},
	doi = {10.1111/j.1365-2966.2007.12353.x},
	abstract = {In performing a Bayesian analysis of astronomical data, two difficult problems often emerge. First, in estimating the parameters of some model for the data, the resulting posterior distribution may be multimodal or exhibit pronounced (curving) degeneracies, which can cause problems for traditional Markov Chain Monte Carlo (MCMC) sampling methods. Secondly, in selecting between a set of competing models, calculation of the Bayesian evidence for each model is computationally expensive using existing methods such as thermodynamic integration. The nested sampling method introduced by Skilling, has greatly reduced the computational expense of calculating evidence and also produces posterior inferences as a by-product. This method has been applied successfully in cosmological applications by Mukherjee, Parkinson \& Liddle, but their implementation was efficient only for unimodal distributions without pronounced degeneracies. Shaw, Bridges \& Hobson recently introduced a clustered nested sampling method which is significantly more efficient in sampling from multimodal posteriors and also determines the expectation and variance of the final evidence from a single run of the algorithm, hence providing a further increase in efficiency. In this paper, we build on the work of Shaw et al. and present three new methods for sampling and evidence evaluation from distributions that may contain multiple modes and significant degeneracies in very high dimensions; we also present an even more efficient technique for estimating the uncertainty on the evaluated evidence. These methods lead to a further substantial improvement in sampling efficiency and robustness, and are applied to two toy problems to demonstrate the accuracy and economy of the evidence calculation and parameter estimation. Finally, we discuss the use of these methods in performing Bayesian object detection in astronomical data sets, and show that they significantly outperform existing MCMC techniques. An implementation of our methods will be publicly released shortly.},
	urldate = {2021-11-25},
	journal = {Monthly Notices of the Royal Astronomical Society},
	author = {Feroz, F. and Hobson, M. P.},
	month = feb,
	year = {2008},
	note = {ADS Bibcode: 2008MNRAS.384..449F},
	keywords = {Astrophysics, methods: data analysis, methods: statistical},
	pages = {449--463},
}
# multi-ellipsoidal bounding
@article{ferozMULTINESTEfficientRobust2009,
	title = {{MULTINEST}: an efficient and robust {Bayesian} inference tool for cosmology and particle physics},
	volume = {398},
	issn = {0035-8711},
	shorttitle = {{MULTINEST}},
	url = {https://ui.adsabs.harvard.edu/abs/2009MNRAS.398.1601F},
	doi = {10.1111/j.1365-2966.2009.14548.x},
	abstract = {We present further development and the first public release of our multimodal nested sampling algorithm, called MULTINEST. This Bayesian inference tool calculates the evidence, with an associated error estimate, and produces posterior samples from distributions that may contain multiple modes and pronounced (curving) degeneracies in high dimensions. The developments presented here lead to further substantial improvements in sampling efficiency and robustness, as compared to the original algorithm presented in Feroz \& Hobson, which itself significantly outperformed existing Markov chain Monte Carlo techniques in a wide range of astrophysical inference problems. The accuracy and economy of the MULTINEST algorithm are demonstrated by application to two toy problems and to a cosmological inference problem focusing on the extension of the vanilla Λ cold dark matter model to include spatial curvature and a varying equation of state for dark energy. The MULTINEST software, which is fully parallelized using MPI and includes an interface to COSMOMC, is available at http://www.mrao.cam.ac.uk/software/multinest/. It will also be released as part of the SUPERBAYES package, for the analysis of supersymmetric theories of particle physics, at http://www.superbayes.org.},
	urldate = {2022-01-08},
	journal = {Monthly Notices of the Royal Astronomical Society},
	author = {Feroz, F. and Hobson, M. P. and Bridges, M.},
	month = oct,
	year = {2009},
	note = {ADS Bibcode: 2009MNRAS.398.1601F},
	keywords = {Astrophysics, methods: data analysis, methods: statistical},
	pages = {1601--1614},
}

GitHub Events

Total
  • Watch event: 1
  • Push event: 1
Last Year
  • Watch event: 1
  • Push event: 1

Issues and Pull Requests

Last synced: 4 months ago

All Time
  • Total issues: 19
  • Total pull requests: 81
  • Average time to close issues: about 1 month
  • Average time to close pull requests: 18 days
  • Total issue authors: 9
  • Total pull request authors: 9
  • Average comments per issue: 4.26
  • Average comments per pull request: 1.3
  • Merged pull requests: 33
  • Bot issues: 0
  • Bot pull requests: 37
Past Year
  • Issues: 1
  • Pull requests: 3
  • Average time to close issues: N/A
  • Average time to close pull requests: about 5 hours
  • Issue authors: 1
  • Pull request authors: 3
  • Average comments per issue: 0.0
  • Average comments per pull request: 0.33
  • Merged pull requests: 2
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • mileslucas (6)
  • yebai (3)
  • ParadaCarleton (2)
  • oschulz (2)
  • adam-coogan (1)
  • ptiede (1)
  • SaranjeetKaur (1)
  • JuliaTagBot (1)
  • ngiann (1)
Pull Request Authors
  • github-actions[bot] (37)
  • mileslucas (26)
  • SaranjeetKaur (8)
  • aplavin (4)
  • JaimeRZP (1)
  • torfjelde (1)
Top Labels
Issue Labels
help wanted (3) gsoc (2) good first issue (1) optimization (1) enhancement (1)
Pull Request Labels

Dependencies

.github/workflows/TagBot.yml actions
  • JuliaRegistries/TagBot v1 composite
.github/workflows/ci.yml actions
  • actions/cache v1 composite
  • actions/checkout v2 composite
  • codecov/codecov-action v1 composite
  • julia-actions/julia-buildpkg v1 composite
  • julia-actions/julia-processcoverage v1 composite
  • julia-actions/julia-runtest v1 composite
  • julia-actions/setup-julia v1 composite
.github/workflows/preview-cleanup.yml actions
  • actions/checkout v2 composite
.github/workflows/register.yml actions
  • julia-actions/RegisterAction latest composite
.github/workflows/compat.yml actions