1. Gaussian mixture — single particle

The smallest thing nested sampling can be asked to do, and the best place to see what it is before any materials complexity arrives. One particle, a fixed landscape of Gaussian wells, no periodic cell, no pressure, no cell moves. It runs in about five seconds on a CPU.

The problem

The energy is a Gaussian mixture — a sum of wells in the xy-plane:

\[E(\mathbf{r}) = -\log \sum_k \exp\!\left( -\frac{\lVert \mathbf{r} - \boldsymbol{\mu}_k \rVert^2}{2\sigma^2} \right)\]

Three of the wells sit far apart and are degenerate. The other two are placed close enough that their Gaussians overlap and merge into a single deeper basin — so there is one unique global minimum, at E ≈ -0.92 against E ≈ -0.39 for the isolated wells.

That asymmetry is the whole exercise. Nested sampling has to find the deeper basin without being told where it is, by shrinking a contour of constant energy until only that basin survives inside it.

the Gaussian-mixture energy surface, with the five Gaussian centres marked

The five Gaussian centres are marked — note the two at the top right sitting almost on top of each other, which is what makes that basin deeper than the rest. Everything the log prints below is a number describing NS shrinking a contour down onto it; further down is what that contraction actually looks like.

The config

examples/tutorials/00_gaussian_2d/config.yaml:

# A single particle in a fixed 2-D landscape of Gaussian wells.
#
# The simplest thing nested sampling can be asked to do: no periodic cell, no
# pressure, no cell moves -- one point wandering a landscape with several
# minima, and NS shrinking a contour around them until only the deepest
# survives. Runs in a couple of seconds on a CPU.
#
#     jaxrens validate -c config.yaml --full
#     jaxrens run -c config.yaml

run:
  n_live: 200          # cheap here, so use enough walkers to resolve the modes
  max_iterations: 3000
  n_mcmc_steps: 20
  # Walkers MCMC-walked in parallel each iteration is 1 + n_extra, so this
  # is the batch width the GPU actually sees. Left at 0 only one chain
  # runs and the device idles; it does not change the population size.
  n_extra: 31
  seed: 42

backend:
  type: gaussian_mixture
  periodic: false      # no cell, no images -- the landscape is fixed in space
  sigma: 0.35
  # Four wells in the xy-plane. The energy is -log sum_k exp(-|r - mu_k|^2 /
  # 2 sigma^2), so overlapping wells merge and distant ones stay separate.
  # Three isolated wells of equal depth, plus a close-together pair whose
  # Gaussians overlap and merge into a single deeper basin -- so there is one
  # unique global minimum for NS to find, not a four-way tie.
  centers:
    - [-1.5, -1.5, 0.0]
    - [ 1.5, -1.5, 0.0]
    - [-1.5,  1.5, 0.0]
    - [ 1.60, 1.60, 0.0]
    - [ 2.00, 1.60, 0.0]

ensemble:
  type: nvt            # no P*V term: there is no volume to speak of

moves:
  # One particle and no cell, so a single displacement move is the whole
  # sampler. No volume / shear / stretch -- there is nothing for them to act on.
  - {type: random_walk, step_size: 0.5, weight: 1.0}

termination:
  - type: prior_mass
    threshold: 1.0e-6

adaptation:
  full_auto: true
  adjust_interval: 100
  defaults: {min_rate: 0.2, max_rate: 0.5, adjust_factor: 1.5, step_size_max: 2.0}

init:
  start_species: "1 1"            # one particle; the element is irrelevant
  random_initialise_pos: true
  pos_randomization_mode: uniform
  random_initialise_cell: false
  init_distance_criterion: 0.0    # only one particle -- no pair to constrain

cell:
  # Not sampled: it only bounds where the initial position is drawn from.
  min_volume_per_atom: 64.0
  max_volume_per_atom: 64.0
  min_aspect_ratio: 0.0

output:
  format: extxyz
  working_dir: ./output
  out_file_prefix: gauss2d
  info_interval: 250
  traj_interval: 1
  # Non-periodic: the cell only bounds the initial draw, so wrapping
  # positions into it would just obscure where the walkers actually are.
  wrap_atoms: false
  checkpoint_interval: 1000
  # Dump the whole live population periodically and keep every dump, so the
  # contraction can be replayed afterwards (the docs plot these over the
  # energy surface). snapshot_clean would otherwise keep only the latest.
  snapshot_interval: 500
  snapshot_clean: false

Notice how much is absent. There is one move, because with a single particle and no cell there is nothing else to move — no volume, shear or stretch, since there is no cell to act on. ensemble: nvt because there is no volume for a P·V term to multiply. backend.periodic: false, so no images and no cutoff. The cell: section is present only to bound where the initial position is drawn from; it is never sampled.

Run it

cd examples/tutorials/00_gaussian_2d
jaxrens validate -c config.yaml --full
jaxrens run -c config.yaml
tail -f gauss2d.log     # from a second shell; `run` prints nothing
Starting NS run: 200 walkers, 1 atoms, max_iter=3000, n_mcmc=20
iter=0     Emax=85.4479    log_Z=-90.7462  dt=1.7s  nE=7.90e+02
iter=250   Emax=18.3548    log_Z=-22.5746  dt=0.6s  nE=5.93e+03
iter=500   Emax=6.76157    log_Z=-10.8761  dt=0.2s  nE=1.12e+04
iter=1000  Emax=0.852648   log_Z=-5.5240   dt=0.2s  nE=2.17e+04
iter=2000  Emax=-0.870357  log_Z=-4.5496   dt=0.3s  nE=4.78e+04
iter=2750  Emax=-0.913359  log_Z=-4.5468   dt=0.3s  nE=5.82e+04
NS finished: 3000 iterations, log_Z=-4.5466, elapsed=5s

This is the clearest place to read the two columns that matter.

Emax is the energy contour. It starts at 85 — walkers scattered anywhere — and falls monotonically to -0.913, just above the true minimum of -0.9225. It cannot go back up: that is the defining constraint of the algorithm.

log_Z is the accumulated log-evidence, and it does the opposite. It climbs steeply while the contour is still sweeping up huge volumes of configuration space, then flattens — by iteration 2000 it has moved less than 0.01. That flattening is convergence: the remaining prior mass is too small to contribute regardless of how deep the energy goes. It is what termination.prior_mass detects.

The final 200 dead points sit at x = 1.80 ± 0.03, y = 1.60 ± 0.02 — the bottom of the merged basin. NS found it among five wells without gradients and without being told it existed.

Plotting diagnostics

jaxrens plot output/gauss2d.energies
jaxrens plot output/gauss2d.adaptation.h5
dead-point energy trail for the 2-D Gaussian mixture

The energy trail is the ladder of dead points — every walker that was culled, in order. The staircase is NS working: long flat stretches where the contour grinds through a wide, shallow region, then drops as it clears a barrier into something deeper.

step-size and acceptance-rate traces

The adaptation plot is the diagnostic you will reach for most often. The step size shrinks as the accessible region does — that is correct and expected. What you are checking is the acceptance rate: it should sit inside the band set by adaptation.defaults.min_rate/max_rate. Pinned at zero means the move is too large to ever be accepted; pinned at one means it is so small the walker is not going anywhere.

Visualizing walker populations and NS trajectory

The diagnostics above are numbers; this is the same run in space. The snapshots dumped every output.snapshot_interval iterations show the live population as it is at that moment:

walker population snapshots contracting onto the deepest basin, one panel per snapshot

At iteration 500 the population is spread across all four basins; by 1500 each basin holds a tight cluster; by 2500 only the merged one is still occupied. That contraction is the algorithm.

The population snapshots are stills; the full *.traj.extxyz is every dead point the run ever produced, one per iteration, coloured by when it was culled:

every culled point across the run, coloured by NS iteration

Early (dark) points are scattered everywhere; late (bright) points pile up almost entirely in the merged basin — the whole history of the contraction in one picture, rather than five slices through it.

Next