---
title: Dynamic Nested Sampling (DNS)
url: https://www.emergentmind.com/topics/dynamic-nested-sampling-dns
type: topic
---

# Dynamic Nested Sampling (DNS)

Dynamic Nested Sampling (DNS) is an advanced Monte Carlo algorithm for Bayesian inference, enabling robust estimation of both the posterior distribution and the marginal likelihood (evidence) in complex, potentially high-dimensional and multi-modal parameter spaces. DNS generalizes the classic Nested Sampling (NS) approach by allowing the number of “live points”—the set of samples maintained during the algorithm—to adapt dynamically according to the structure of the likelihood landscape. This adaptive allocation yields large gains in sampling efficiency and accuracy for both evidence calculation and posterior estimation, particularly in scenarios where information is concentrated in small, intricate regions of parameter space.

## 1. Foundations: Classic Nested Sampling

Traditional NS targets two principal Bayesian objectives: the posterior,
\[
p(\theta \mid D) \propto L(\theta)\,\pi(\theta),
\]
and the marginal likelihood (“evidence”),
\[
Z = \int_\Omega L(\theta)\,\pi(\theta)\,d\theta.
\]
NS recasts this as a one-dimensional integral over the “prior volume”,
\[
X(\lambda) = \int_{L(\theta) \geq \lambda} \pi(\theta)\,d\theta, \quad X(0)=1,\; X(\infty)=0,
\]
yielding
\[
Z = \int_0^1 L(X)\,dX,
\]
where $L(X)$ is the inverse of $X(\lambda)$.

The algorithm maintains a set of $K$ live points sampled from the prior subject to a likelihood constraint. At each iteration, the live point with minimum likelihood is replaced by a new point sampled from the prior, also under the current hard likelihood threshold. The prior volume shrinks with each iteration as
\[
X_i \approx e^{-i/K}
\]
for constant $K$. Quadrature approximates $Z$ as
\[
Z \approx \sum_{i=1}^N w_i L_i, \quad w_i = X_{i-1} - X_i,
\]
and posterior samples are recoverable via suitable reweighting of the dead-point set.

A fixed live-point count $K$, while simple, enforces uniform prior-volume resolution throughout the run, which is suboptimal if regions contributing most to the posterior or evidence require finer or coarser treatment.

## 2. Dynamic Nested Sampling: Adaptive Allocation

The central innovation of DNS is to let the number of live points $K_i$ (sometimes denoted $n_i$ or $N_j$ per step) vary in response to the sampled likelihood and evidence structure. This adaptive allocation enables the algorithm to expend more computational effort in regions where the posterior mass is concentrated or where evidence uncertainty is greatest, and less where these quantities are negligible.

To operationalize this, DNS defines an importance function $\mathcal{I}(X)$ over the prior volume, with a typical form:
\[
\mathcal{I}(X) = f_{\rm post}\,p(X) + (1-f_{\rm post})\,q(X),
\]
where $p(X) \propto L(X)X$ represents posterior mass density in $X$ and $q(X)$ quantifies evidence-contribution uncertainty. The user-specified trade-off parameter $f_{\rm post}\in[0,1]$ balances posterior versus evidence focus. In regions where $\mathcal{I}(X)$ is high, more live points are allocated, reducing local resolution $\Delta\ln X \approx -1/K_i$.

Thus, DNS treats the live-point count as a dynamically reallocated resource, focusing effort on parts of parameter space that most influence the quantities of interest.

## 3. Algorithmic Structure and Key Steps

The standard iterative DNS routine proceeds as follows:

1. **Baseline Run:** Conduct a static NS run with a baseline live-point count $K_{\rm base}$, collecting dead-point samples $\{L_i, X_i\}$.

2. **Importance Evaluation:** Estimate per-sample importances (e.g., $\hat p_i \approx L_i (X_{i-1} - X_i)$ for posterior, or evidence-uncertainty) and compute a combined importance function.

3. **Region Selection:** Identify contiguous ranges over $i$ where the importance exceeds a defined fraction $f_{\rm max}$ of its maximum, possibly with padding, mapping to corresponding likelihood bounds.

4. **Batch Run:** Within these bounds, perform additional static NS runs ("threads" or "batches") with increased live-point counts $K_{\rm batch}$ restricted by hard likelihood constraints.

5. **Merging:** Integrate new samples and update the live-point schedule, recalculating $X_i$ via:
    - If $K_i \geq K_{i-1}$: $\Delta\ln X_i = -1/K_i$
    - If $K_i < K_{i-1}$: $\Delta X_i = 1 / (K_{i-1} + 1)$

6. **Stopping Criteria:** Continue until a hybrid variance-based threshold is met,
\[
s\,\varepsilon_{\rm post} + (1-s)\,\varepsilon_{\rm evid} < \epsilon,
\]
using error criteria for posterior (e.g., KL divergence) and for evidence (fractional $\ln Z$ error).

Alternative “agent” and “schedule” approaches, including single-pass allocations and tree-based implementations, have been formulated, often using diagnostic metrics (e.g., effective sample size, insertion-rank tests).

## 4. Mathematical Characterization

Prior volume shrinkage under variable $K_i$ is generalizable. For each volume contraction $i$:
\[
X_i = t_i X_{i-1}, \qquad t_i \sim \mathrm{Beta}(K_i, 1),
\]
with
\[
E[\ln X_i] = -\frac{1}{K_i}, \qquad
\mathrm{Var}[\ln X_i] = \frac{1}{K_i^2}.
\]
For evidence estimation:
\[
Z \approx \sum_{i=1}^N L_i w_i,\quad w_i = X_{i-1} - X_i,
\]
with error estimates adapting via
\[
\mathrm{Var}(Z) \approx \sum_{i=1}^N \frac{L_i^2 X_{i-1}^2}{K_i^2}.
\]
Effective sample size (ESS) diagnostics and bootstrap schemes are recommended for robust error assessment.

Posterior estimation is carried out by recasting the weighted sample set as a discrete measure supported on $\{\theta_i\}$ with normalized weights $p_i \propto L_i w_i$.

## 5. Practical Implementation and Comparative Performance

Any NS code that can generate samples subject to a hard likelihood constraint is readily extended to DNS, provided it can merge and manage live-point schedules and dynamically update $X_i$. Recommended initial live-point counts are modest ($n_{\rm init} = 10$–$20\%$ of peak) to traverse all modes cheaply; larger values may be necessary to capture highly multi-modal targets.

Termination can be by fixed sample budget, error target, or open-ended improvement. Parameters such as the threshold fraction $f$ for region selection and the trade-off $G$ (aka $f_{\rm post}$) should be tuned for joint optimization of evidence and posterior estimation (typical values: $f \approx 0.9$, $G = 0.25$–$0.5$).

Available open-source implementations include dynesty (Python), dyPolyChord (C++/Fortran/Python), and perfectns (analytical benchmarks).

Empirical studies report order-of-magnitude efficiency improvements—up to $\sim 72\times$ for parameter estimation in high dimensions and $\sim 7\times$ for evidence estimation relative to static NS or popular MCMC algorithms, particularly in settings with high information gain or severe multi-modality [1704.03459], [1904.02180], [2101.09675].

## 6. Applications, Strengths, and Limitations

DNS is robust to multi-modal likelihoods—iso-likelihood shells are tracked naturally, with live-point allocation increasing in each region as it is discovered. Astronomical analyses demonstrate DNS’s ability to sample efficiently and accurately in low- and high-dimensional spaces, with dynamical allocation critical for handling bi-modal and otherwise complex likelihood structures. Examples include galaxy SED fitting (14-parameter models), 200-dimensional Gaussians, and multi-modal periodic parameter models [1904.02180].

DNS retains the favorable properties of standard NS: unsupervised navigation of posteriors, reliable evidence estimation, and rigorous Bayesian error estimation. However, realization efficiency ultimately remains bounded by the likelihood-restricted prior sampling (LRPS) step; performance in very high-dimensional or highly degenerate spaces is still determined by the efficiency of the LRPS implementation [2101.09675].

## 7. Comparison, Diagnostics, and Future Research

### Static NS vs. DNS: Algorithmic and Empirical Features

| Feature              | Static NS                 | Dynamic NS (DNS)                                              |
|----------------------|--------------------------|---------------------------------------------------------------|
| Live-point count     | Fixed $N$                | $N(\ell)$ adaptive to structure                               |
| Shrinkage control    | Uniform steps            | Locally refined via increased live points                     |
| Evidence error       | $\sim 1/N^2$ scaling     | Reduced locally via dynamic increase in $N$                   |
| Sampling cost        | $O(NH C_{\rm LRPS}(d))$  | Reallocated efficiency; often $2\times$–$5\times$ faster      |
| Multi-modality       | Requires large $N$       | Mode-local increase possible                                  |
| High-dimensionality  | $O(d^2)$–$O(d^3)$        | Still LRPS-limited; improved reallocation                    |

Active diagnostics are essential. The insertion-rank test (batch uniformity for new points among live points) and the subsample-bootstrap (comparative spread in $Z$ or posterior from resampled subsets) are endorsed [2101.09675]. Over-aggressive live-point increases can waste effort in narrow bands; insufficient initial $N_0$ risks missing posterior mass.

Future research directions include formal convergence proofs (e.g., within a Sequential Monte Carlo framework), agent-based live-point allocation schemes, hybrid DNS/SMC methods, and improved LRPS proposals (e.g., NUTS/NoGUTS, neural-flow models) [2101.09675]. DNS remains an active area for methodology and application development, with ongoing work on robust diagnostics, parallelization, and advanced target geometries.

Source: https://www.emergentmind.com/topics/dynamic-nested-sampling-dns