src/core/nested.js
text
MiniNest: a compact nested sampler in the spirit of UltraNest's
ReactiveNestedSampler (Buchner 2021).
What is the same as UltraNest:
* MLFriends region (Buchner 2016, 2019): live points are whitened with
their covariance, and the constrained prior is bounded by the union of
balls around every live point. The ball radius is found by bootstrapping
(leave-out cross-validation), so the region is robust rather than tuned.
* Cluster-aware whitening (UltraNest's AffineLayer): live points are grouped
by friends-of-friends at the ball radius, and the covariance is taken about
each group's own mean. Separated modes (period aliases) then keep tight
balls instead of one metric stretched across the gap between them. A new
region is used only if it is smaller than the last one.
* A wrapping ellipsoid, also bootstrapped, intersected with the balls.
* Uniform rejection sampling from that region inside the unit cube, drawn
from the balls, the ellipsoid or a bounding box, whichever wastes least.
* A slice step sampler (hit-and-run; Neal 2003) along a mixture of
directions: differences of live points of the same group and random
directions in the whitened space (generate_mixture_random_direction).
* Termination on the fraction of evidence left in the live points.
* Insertion-order test as a self-diagnostic (Buchner 2023).
What is different:
* The ellipsoid's enlargement is cross-validated with the ellipsoid re-fitted
to each bootstrap sample, which removes a bias in ln Z that grows with the
number of dimensions (+0.5 at 20 dimensions with 400 live points).
* The radius ignores groups that were left out whole and are far away, so a
mode down to its last point does not join all modes up again.
* The wrapping ellipsoid is tested against the likelihood during the run: a fifth
of the region proposals come from the balls alone, and a point accepted outside
the ellipsoid enlarges it for the rest of the run (_grow). Without this the
ellipsoid cut the wide end off funnel-shaped contours and ln Z came out 0.2 to
0.3 low with a clean insertion-order test (UltraNest: -0.30 on the same 4-D funnel).
* The choice between region and slice sampling is made during the run from
the measured cost of each, with hysteresis, in both directions.
* The insertion-order test is also used during the run: if the points drawn
with the help of the region fail it, the run starts again with plain slice
sampling (funnels do this).
* A budget of likelihood calls (and of seconds) ends the run cleanly, and the
result carries plain-language warnings (see diagnose below).
What is left out: the reactive tree (dynamic number of live points), a metric
per mode, warm starts, MPI.
The sampler is a stepper (call step(n) repeatedly) so it can run in a Web
Worker or be time-sliced on the main thread. For one seed the run is the same
every time: nothing depends on the clock except the optional time limit.Import: import { … } from './src/core/nested.js' — no DOM, runs in Node and the browser.
MiniNest
js
class MiniNestNo description in the source.
diagnose
js
function diagnose(res, usamples, opts = {})Plain-language warnings about a finished run. res is a MiniNest result, usamples the same points in the unit cube (n x ndim), opts.names / opts.labels the parameter keys and display names. Returns { warnings: [string], correlations: [{ i, j, r, rank }], edges: [{ i, side }], modes: [{ i, peaks: [{ at, weight }] }] }.