NestedSamplers.jl

Implementations of single and multi-ellipsoid nested sampling
Popularity
41 Stars
Updated Last
5 Months Ago
Started In
December 2019

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> ]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

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.

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

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

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

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

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.