NestedSamplers.jl

Implementations of single and multi-ellipsoid nested sampling
Author TuringLang
Popularity
17 Stars
Updated Last
1 Year Ago
Started In
December 2019

NestedSamplers.jl

Build Status PkgEval Coverage

Stable Dev DOI

A Julian implementation of single- and multi-ellipsoidal nested sampling algorithms using the AbstractMCMC interface.

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

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

logl(X) = exp(-(X - [1, -1]) / 2)
prior(X) = 4 .* (X .- 0.5)
# or equivalently
prior = [Uniform(-2, 2), Uniform(-2, 2)]
model = NestedModel(logl, prior)

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.MultiElliipsoid
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 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, 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

Contributing

Primary Author: Miles Lucas (@mileslucas)

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