Source-linked AI summary
dynesty: A Dynamic Nested Sampling Package for Estimating Bayesian Posteriors and Evidences
Joshua S Speagle
TL;DR
Complex astronomical models require numerical methods to estimate analytically intractable posteriors, while existing MCMC methods can struggle with multimodal distributions. The paper presents dynesty, a modular Python implementation of Dynamic Nested Sampling, and evaluates it on toy and astrophysical problems, including comparisons with MCMC. In one tested problem, dynesty with uniform sampling inside multiple bounding ellipsoids was roughly an order of magnitude more efficient than MH MCMC and emcee.
Problem
Complex data and models often have analytically intractable posteriors, while common MCMC implementations struggle with widely separated modes.
Method
dynesty implements Dynamic Nested Sampling in a modular Python package with multiple bounding and sampling methods.
Results
Roughly an order of magnitude greater sampling efficiency was achieved than MH MCMC and emcee in one compared problem.
Takeaways & Limitations
dynesty estimates challenging posterior distributions in toy problems and real astronomical applications.
Takeaways & Limitations
Dynamic Nested Sampling requires choices for live-point allocation and termination, introducing additional tuning parameters that affect run behavior.
Abstract
from arXiv · showhide
We present dynesty, a public, open-source, Python package to estimate Bayesian posteriors and evidences (marginal likelihoods) using Dynamic Nested Sampling. By adaptively allocating samples based on posterior structure, Dynamic Nested Sampling has the benefits of Markov Chain Monte Carlo algorithms that focus exclusively on posterior estimation while retaining Nested Sampling's ability to estimate evidences and sample from complex, multi-modal 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. 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.
1 INTRODUCTION
Modern astronomy increasingly uses Bayesian inference to estimate parameters and compare models from complex observational data. Because posterior estimation is often difficult, dynesty provides an accessible Dynamic Nested Sampling implementation alongside existing MCMC and Nested Sampling tools.
- Motivation: Large astronomical datasets and complex models have driven a shift from maximum-likelihood estimation toward Bayesian inference.Bayesian inference estimates parameter distributions consistent with data and current astrophysical knowledge.
- Motivation: For complicated data and models, the posterior is often analytically intractable and must be estimated numerically.Exact approaches approximate the posterior using weighted samples, while approximate approaches construct a nearby analytic distribution.
- Existing methods: MCMC directly generates posterior samples but commonly struggles when the posterior contains widely separated modes.Nested Sampling instead samples nested, possibly disjoint shells of increasing likelihood and can estimate both evidence and posterior distributions.
- Existing methods: Bayesian inference algorithms can become the primary bottleneck for testing hypotheses, estimating parameters, and performing model comparisons.Software packages reduce the need for users to implement these algorithms themselves.
- Contribution: dynesty is a public, open-source Python package implementing Dynamic Nested Sampling.It is designed to be modular and easy to use, with multiple sampling implementations, stopping criteria, plotting functions, and analysis utilities.
- Contribution: The paper covers Nested Sampling, Dynamic Nested Sampling, multimodal sampling strategies, toy problems, and real-world astrophysical applications.The package is publicly available through GitHub and PyPI, with documentation for installation and examples.
2 NESTED SAMPLING
Nested Sampling converts difficult posterior and evidence estimation into repeated sampling from constrained prior regions and integration over shrinking prior volume. It can estimate evidences, handle multimodal distributions, and provide evidence-focused stopping criteria alongside posterior samples.
- Nested Sampling replaces direct posterior sampling with slicing the posterior into simpler constrained distributions, sampling each, and recombining the results.
- The evidence integral over the full parameter domain is refactored into a one-dimensional integral over prior volume X.L(X) defines iso-likelihood contours, while X is the fraction of prior volume above a likelihood threshold.
- Sampling from the constrained prior is difficult for arbitrary priors, so a prior transform maps a uniform unit-cube prior into the parameters of interest.The transformed problem becomes repeated uniform sampling within the constrained prior; dynesty assumes a unit-cube prior unless specified otherwise.
- Static Nested Sampling initializes K live points, repeatedly removes the lowest-likelihood point, and replaces it with a constrained-prior sample.After termination, the remaining live points are added sequentially in increasing likelihood order.
- Nested Sampling estimates both evidence and posterior distributions, samples multimodal distributions, and uses stopping criteria motivated by evidence estimation.Unlike MCMC, it integrates smoothly from the prior toward the posterior rather than requiring posterior burn-in.
3 DYNAMIC NESTED SAMPLING
Dynamic Nested Sampling varies the number of live points during a run so dynesty can prioritize posterior or evidence estimation while retaining Nested Sampling’s broader capabilities. Its iterative implementation estimates where additional samples matter, allocates batches there, and merges them until stopping criteria are met.
- Motivation: Dynamic Nested Sampling varies the number of live points during runtime, unlike Static Nested Sampling’s constant allocation.The change permits different integration rates across prior volume.
- Motivation: It can focus on posterior estimation, evidence estimation, or a mixture of both while retaining Nested Sampling’s ability to estimate evidence and handle complex, multi-modal distributions.dynesty uses an 80%/20% posterior/evidence mixture by default.
- Practical considerations: Dynamic Nested Sampling introduces additional tuning parameters for allocating live points and determining when sampling terminates.dynesty supplies reasonable defaults, but these choices can affect a run’s behavior.
- Live-point allocation: The live-point count is increased where higher resolution is desired and reduced where the current prior-volume region should be traversed more quickly.Larger live-point counts correspond to a slower integration rate.
- Importance functions: Posterior importance allocates more live points where posterior mass is higher, whereas evidence importance emphasizes prior-volume-dominated regions before much posterior mass has been integrated.A mixture function balances these objectives through the posterior-weight parameter f_P.
- Iterative algorithm: Dynamic Nested Sampling first runs Static Nested Sampling to locate posterior mass, then evaluates importance and allocates additional batches in selected regions.Each new batch is sampled with Static Nested Sampling and merged into the existing samples.
- Practical considerations: The allocation scheme relies on noisy estimates of prior volume and importance that become available only after samples have been generated.This makes Dynamic Nested Sampling an iterative modification of Static Nested Sampling.
4 IMPLEMENTATION
dynesty constructs bounds from the current live points and samples within them using methods suited to different posterior geometries and dimensional regimes. Its options span simple unit-cube sampling, geometric bounds, random walks, and slice-based methods.
- Overview: dynesty separates constrained-prior sampling into constructing bounds and generating samples conditioned on those bounds.Bounds are intended to encompass remaining prior volume across multiple possible modes.
- Bounding distributions: Its five bounding options are the unit cube, a single ellipsoid, multiple ellipsoids, overlapping balls, and overlapping cubes.The current live points define the approximate shape and size of sampled prior-volume regions.
- Bounding distributions: Single ellipsoids suit roughly Gaussian, unimodal likelihoods, while clustered ellipsoids or overlapping balls and cubes address more complex structures.Overlapping balls or cubes can perform better in low dimensions when likelihood scales are sufficiently similar.
- Bounding distributions: dynesty expands bounds conservatively by a factor α, typically 1.25 or a value derived through bootstrapping.Accurate volume expansion is especially important for uniform sampling.
- Sampling methods: The four main sampling approaches are uniform sampling, random walks, multivariate slice sampling, and Hamiltonian slice sampling.The methods differ in how they generate proposals from or around the bounding distribution.
- Sampling methods: Uniform sampling is most effective in lower dimensions when bounds approximate the prior volume, whereas random walks are less sensitive to bound size in moderate dimensions.Uniform sampling can achieve acceptance rates of at least roughly 10% when bound and prior volumes are comparable.
- Sampling methods: Multivariate and Hamiltonian slice sampling often perform better in high-dimensional regimes by avoiding direct volume sampling and, for Hamiltonian methods, exploiting gradients.dynesty defaults to uniform sampling below 10 dimensions, random walks from 10 to 20, and slice methods above 20.
- Sampling methods: Uniform sampling uniquely depends on the bounds fully enclosing the constrained prior, an assumption that is never guaranteed.The other sampling methods are less directly tied to this enclosure assumption.
5 TESTS
The tests stress dynesty across multimodal, periodic, high-dimensional, and MCMC-comparison problems. Across these cases, it recovers target posteriors and evidences while showing task-dependent sampling efficiency.
- 5.1 Gaussian Shells: Gaussian-shell tests achieved roughly 10% sampling efficiency over approximately 20k iterations, with excellent posterior estimates.Multiple ellipsoidal bounds contracted as live points organized within the two shells.
- 5.2 Eggbox: Eggbox tests achieved average sampling efficiencies of 20–40% using multiple ellipsoids or overlapping balls.The distribution contained 13 localized modes within one periodic 2-D unit-cube period.
- 5.3 Exponential Wave: Exponential Wave tests robustly recovered both modes, including a solution near the boundary under periodic boundary conditions.The problem involved multiple scales and seven free parameters spanning amplitudes, frequencies, phases, and scatter.
- 5.4 200-D Gaussian: In a 200-D Gaussian with K = 50 live points, dynesty achieved unbiased recovery of the mean, covariance, and evidence.Hamiltonian Slice Sampling used analytic likelihood gradients without a bounding distribution.
- 5.5 Comparison to MCMC: Across 25 trials, uniform sampling within multiple ellipsoids was roughly an order of magnitude more efficient than MH MCMC and emcee, whereas internal random walks were comparable.The comparison targeted similar effective sample sizes, with dynesty’s default stopping criterion giving N_ESS approximately 17000.
6 APPLICATIONS
dynesty is applied to large-scale astronomical analyses spanning galaxies, molecular clouds, and other domains. These applications report efficient sampling and the ability to characterize diverse posterior structures.
- dynesty has been applied to gravitational waves, exoplanets, transients, galaxies, and three-dimensional dust mapping.
- In a 14-parameter galaxy SED analysis of roughly 60k galaxies, dynesty provided over an order of magnitude more efficient sampling than emcee.The analysis covered redshifts 0.5 < z < 2.5 and modeled stellar, dust, and active-galactic-nucleus properties.
- The galaxy application also characterized a wide variety of posterior distributions.
- dynesty was used to infer distances to dozens of local molecular clouds from stellar distance and reddening estimates combined with Gaia parallaxes.The inferred distances are sensitive to the number and distribution of foreground stars constraining each cloud’s extinction jump.
- These examples illustrate that dynesty can work well in both theoretical toy problems and professional astronomical analyses.
7 CONCLUSION
The paper motivates accessible Bayesian inference tools and presents dynesty as a public Python implementation of Dynamic Nested Sampling. Its broader validation spans toy problems and real astronomical applications, while its ultimate usefulness depends on user analyses.
- Modern astronomical analyses need tools that bridge underlying physical models and corresponding posterior estimation.
- dynesty is a public, open-source Python package implementing Dynamic Nested Sampling for flexible inference over complex, multi-modal distributions.The paper also describes bounding and sampling methods for efficient inference.
- The paper evaluates dynesty on toy problems and real astronomical applications, highlighting posterior estimation in both settings.
- The authors note that dynesty’s real test is whether users find it useful for their own analysis problems.
APPENDIX A: DETAILED NESTED SAMPLING RESULTS
The appendix supplies additional statistical background and results for Nested Sampling beyond the main text’s broad overview. It organizes this material from basic setup through multi-live-point behavior and error estimation.
- The appendix adds detailed statistical results and discussion because the main text glosses over much of Nested Sampling’s statistical background.
- It begins with the basic Nested Sampling setup and derives statistical properties for the single-live-point case.
- Later sections treat multiple and varying numbers of live points, then discuss Nested Sampling errors and schemes for estimating them.
A1 Setup
The setup defines posterior, likelihood, prior, and evidence, then reformulates evidence estimation as integration over prior volume. Nested Sampling approximates this one-dimensional integral with weighted samples.
- Bayes Rule defines the posterior P(Θ), likelihood L(Θ), prior π(Θ), and evidence Z.
- Nested Sampling transforms the evidence integral from parameter position Θ to prior volume X associated with iso-likelihood contours.
- The prior volume X lies between 0 and 1, representing the volume inside an iso-likelihood contour under integrable priors.
- Rewriting the evidence in terms of prior volume requires an inverse L(X), assuming there are no flat likelihood slabs.
- Nested Sampling approximates the resulting one-dimensional integral with a discrete set of N points and uses importance weights to approximate the posterior.
A2 Using a Single Live Point
The single-live-point derivation treats prior volume as a cumulative distribution over likelihood and uses the Probability Integral Transform to generate constrained-prior samples. It also shows that sufficiently covering correlated samples can satisfy Nested Sampling's requirements.
- Prior-volume estimation: The unknown prior volume X(λ) is estimated through a known statistical distribution derived from its CDF over likelihood levels.The estimator ˆX is therefore treated as noisy because the underlying uniform variables are unknown.
- Probability Integral Transform: The Probability Integral Transform converts likelihood draws into samples with the desired prior-volume distribution.This construction can be extended to sampling relative to a threshold λ.
- Constrained-prior sampling: Sampling directly from the constrained prior πλ(Θ) satisfies the transform without explicitly sampling λ or its likelihood PDF P(L).A suitable prior transform T is then used by the constrained-prior sampling methods described later.
- Correlated samples: Correlated samples can satisfy the Nested Sampling transform if they sufficiently probe the local prior volume and cover the possible likelihood range.This provides theoretical support for Nested Sampling when samples are not fully independent.
A3 Combining Live Points
Nested Sampling with multiple live points can be understood by combining ordered sample sequences from independent single-live-point runs. This duality explains both the resulting sampling procedure and the distributional complication for merged prior-volume estimates.
- Merged prior volumes: The merged prior-volume estimator cannot follow the same distribution as the estimators from the independent runs because the merged ordering couples their samples.Considering samples separately and considering them together impose different prior-volume relationships.
- Two live points: With two live points, replacing the lowest-likelihood point produces a sorted sequence whose individual live-point histories resemble independent ordered samples.Each live point evolves as an independent-sample sequence when considered separately.
- Combining runs: Combining the two ordered histories yields the same procedure as merging two independent Nested Sampling runs using one live point each.The construction generalizes directly to K live points and defines Static Nested Sampling.
A4 Using Many Live Points
Using K live points requires tracking their ordered prior volumes and the associated uniform order-statistic distributions. The resulting shrinkage and prior-volume estimates can be characterized analytically, including the final live points.
- Ordered live points: The K live points are uniformly distributed within the prior volume from the previous iteration, so their ordered positions determine the next shrinkage.The lowest-likelihood live point corresponds to the largest prior volume and is removed.
- Order statistics: The joint distribution of K uniform order statistics can be represented using exponential random variables, with marginal distributions available for each order statistic.These results provide the distributional basis for prior-volume evolution.
- Prior-volume evolution: For K live points, successive prior-volume shrinkages follow the Kth standard uniform order statistic, whose marginal distribution is Beta(K, 1).The arithmetic mean provides an estimator for the shrinkage-related prior volume.
- Final live points: After termination, the final K live points can be added as samples following the final set of uniform order statistics relative to ˆX_N.Their arithmetic and geometric mean estimators are characterized separately.
A5 Using a Varying Number of Live Points
Allowing the number of live points to vary makes Nested Sampling alternate between exponential and uniform shrinkage regimes. The prior-volume estimator remains tractable through bookkeeping over contiguous regions with different live-point counts.
- Variable live-point schedules: Adding the final live points is equivalent to continuing the run while progressively decreasing the number of live points.This gives a constant K over the main run followed by K+1−k live points during the continuation.
- Increasing live points: When the live-point count stays constant or increases, prior-volume shrinkage follows a Beta(K_i, 1) distribution.The procedure adds K_i−K_{i−1} points before replacing the worst-likelihood point.
- Shrinkage modes: Constant live-point counts produce exponential shrinkage, whereas removing live points produces variable-factor uniform shrinkage.These are the two modes through which Nested Sampling traverses the prior.
- Decreasing live points: When the live-point count decreases, the expected shrinkage is determined by an associated uniform order statistic from the previous live-point set.Iterative schemes typically need only one-point decreases, K_{i−1}−K_i=1.
- Estimation: Dynamic switching between shrinkage modes adds bookkeeping but leaves prior-volume estimation straightforward at each iteration.The mean estimate combines contiguous regions dominated by exponential or uniform shrinkage.
A6 Nested Sampling Errors
This section characterizes Nested Sampling’s sampling and statistical noise, then derives rough evidence-error estimates and simulation-based approaches for quantifying uncertainty. It also explains why naive bootstrapping fails and how strand-based resampling addresses those issues.
- Error sources: Nested Sampling has sampling noise from representing continuous distributions and integrals with a finite set of samples.These estimates become more accurate as the number of live points and total samples increase.
- Error sources: Statistical noise is an additional error source caused by estimating prior volumes, which propagates into importance weights, evidence, and posterior estimates.The prior-volume estimator ˆX_i approaches the true X_i as live-point and sample counts grow.
- Error sources: The two error types enter separately: sampling noise replaces an iso-likelihood contour average with one sampled point, while statistical noise replaces true weights with noisy prior-volume-based estimates.This decomposition is made through successive approximations of the posterior expectation integral.
- Evidence uncertainty: For static Nested Sampling, the total iteration count reflects both integration rate and prior-volume coverage, with N ∝ 1/K for constant live-point count K.The second contribution roughly scales with the Kullback-Leibler divergence, or information gain.
- Evidence uncertainty: A variable-live-point error estimator reduces to the original constant-K estimator when K_1 = · · · = K_N = K, although the modified form is less reliable.Its derivation assumes sufficiently slow changes in K_i and approximately independent evidence updates.
- Uncertainty simulation: Bootstrapping individual live-point strands and merging the resampled strands can simulate evidence and posterior estimates while preserving varying path lengths.Naive bootstrapping mishandles duplicate ordering, fixes N, and may remove prior-drawn samples needed for evidence normalization.