API Reference

NestedSampler

class jnesty.NestedSampler(loglikelihood: Callable[[Array], float], prior_transform: Callable[[Array], Array], ndim: int, nlive: int = 500, rwalk_K: int | None = None, rwalk_step_scale: float | None = None, target_acceptance: float = 0.5, scale_adapt_interval: int = 1, device: str = 'gpu', verbose: bool = True, bound: str = 'none', bound_update_interval: int | float | None = None, max_ellipsoids: int = 20, batch_size: int | None = None, queue_size: int | str | None = None, memory_frac: float = 0.9, unit_cube_batch_size: int = 200, min_eff: float = 10.0, min_ncall: int | None = None, context=None)

Bases: object

Simple nested sampler following Dynesty’s API design.

Parameters:
  • loglikelihood (callable) – Log-likelihood function. Signature: loglikelihood(x) -> float

  • prior_transform (callable) – Prior transform. Signature: prior_transform(u) -> array

  • ndim (int) – Number of dimensions.

  • nlive (int, optional) – Number of live points. Default: 500

  • rwalk_K (int or None, optional) – Random walk steps per iteration. Auto-tuned if None.

  • rwalk_step_scale (float or None, optional) – Initial proposal scale. Auto-tuned if None.

  • target_acceptance (float, optional) – Target acceptance rate for scale adaptation. Default: 0.5

  • scale_adapt_interval (int, optional) – Iterations between scale adaptation. Default: 1

  • device (str, optional) – Device to use (‘gpu’ or ‘cpu’). Default: ‘gpu’

  • verbose (bool, optional) – Print progress. Default: True

  • bound (str, optional) – Bounding method: ‘none’, ‘single’, ‘multi’. Default: ‘none’

  • bound_update_interval (int, float, or None, optional) – Controls periodic bound refitting, measured in likelihood calls. None (default): automatic — rwalk_K * nlive calls for bound=’multi’ (matching Dynesty’s walks * nlive), off otherwise. Set to 0 to disable, float in (0,1) for fraction of rwalk_K * nlive.

  • max_ellipsoids (int, optional) – Maximum ellipsoids for multi-ellipsoid. Default: 20

  • batch_size (int or None, optional) – Number of parallel walks for GPU-parallel likelihood evaluation. Only used when queue_size=0 (legacy mode). None (default): auto-tuned to ~5 steps/walk. Set to 1 to disable parallelism.

  • queue_size (int, 'auto', or None, optional) – Dynesty-style queue mode. None (default): automatic — 8 for bound=’multi’ (matching Dynesty’s multiprocessing), 0 otherwise. An integer sets the number of parallel walks directly. ‘auto’ picks the number of walks whose measured time per likelihood evaluation is the smallest (see auto_queue_size), which also keeps the batch inside the memory budget. Each queue entry gets full rwalk_K steps; scale adapts at queue drain.

  • memory_frac (float, optional) – Fraction of GPU memory to use for batch walks. Default: 0.9. Caps batch_size if it would exceed this fraction of GPU memory. Ignored on CPU.

context

Optional pytree passed to every traced function as an argument. With it, loglikelihood(x, context) / prior_transform(u, context) carry the dataset, so the compiled kernels do not embed it and are reused from one dataset to the next (see clear_compiled_units()).

get_logz() → tuple

Get (logZ, logZ_error).

get_samples(weights: bool = False) → ndarray

Get posterior samples in physical space.

plot_corner(truths=None, **kwargs)

Corner plot via Dynesty’s plotting.cornerplot().

plot_diagnostics(**kwargs)

Diagnostics via Dynesty’s plotting.runplot().

plot_run(lnz_truth=None, **kwargs)

Run plot via Dynesty’s plotting.runplot().

plot_trace(truths=None, dims=None, thin=1, **kwargs)

Trace plot via Dynesty’s plotting.traceplot().

print_summary() → None

Print a formatted summary of the results.

property results: Results

Results object following Dynesty’s format.

Raises RuntimeError if run_nested() has not been called.

run_nested(max_iterations: int = 100000, delta_logZ_threshold: float = 0.01, print_progress: bool = True, logl_min: float = -inf, logl_max: float = inf, init_live_x=None, init_live_logL=None, init_logvol: float = 0.0, init_logZ_val: float = -inf, init_logX: float = 0.0, init_ncall: int = 0, init_iter_offset: int = 0) → None

Run the nested sampling algorithm.

Parameters:
  • max_iterations (int, optional) – Maximum number of iterations. Default: 100000

  • delta_logZ_threshold (float, optional) – Convergence threshold. Default: 0.01

  • print_progress (bool, optional) – Show progress bar. Default: True

  • logl_min (float, optional) – Batch log-likelihood bounds (used by DynamicNestedSampler).

  • logl_max (float, optional) – Batch log-likelihood bounds (used by DynamicNestedSampler).

  • init_live_x (array-like, optional) – Pre-sampled seed live points (unit cube) and their logL values. If provided, Phase 1 uniform rejection is skipped.

  • init_live_logL (array-like, optional) – Pre-sampled seed live points (unit cube) and their logL values. If provided, Phase 1 uniform rejection is skipped.

  • init_logvol (float, optional) – Starting log-volume (path-A fallback when -inf-logL points were rejected).

to_dynesty_results()

Convert results to a Dynesty Results object for use with Dynesty’s plotting functions.

DynamicNestedSampler

class jnesty.DynamicNestedSampler(loglikelihood, prior_transform, ndim, nlive=500, bound='none', **static_kwargs)

Bases: object

Dynesty-style dynamic nested sampler.

Wraps JNesty’s static engine for both the base run and each batch.

Parameters:
  • loglikelihood (callable) – Log-likelihood in physical parameter space.

  • prior_transform (callable) – Maps a unit-cube sample to physical space.

  • ndim (int)

  • nlive (int, default 500)

  • bound ({'none', 'single', 'multi'}, default 'none')

  • **static_kwargs – Forwarded to NestedSampler.

run_nested(nlive_init=None, dlogz_init=0.01, nlive_batch=None, maxbatch=100, max_iterations=100000, pfrac=0.8, maxfrac=0.8, pad=1, n_effective=None, evid_thresh=0.1, n_mc=0, use_stop=True, print_progress=True, seed=None)

Run the dynamic nested sampling loop.

max_iterations is forwarded to every internal static sub-run (the base run and each batch) as the per-run hard iteration cap; convergence is controlled by dlogz_init.

to_dynesty_results()

Convert the dynamic results dict to a dynesty Results object.

Needed so dynesty.plotting.runplot/traceplot/cornerplot can be used directly on JNesty dynamic output.

Dynamic Module Functions

jnesty.dynamic.compute_integrals(logl, logvol, reweight=None)

Compute weights, logz, logz variance, and H using the trapezoidal estimator.

Faithful port of dynesty.utils.compute_integrals.

jnesty.dynamic.kish_ess(logwt)

Kish ESS from unnormalised log-weights. Matches dynesty.

jnesty.dynamic.weight_function(results, args=None, return_weights=False)

Default weight function. Faithful port of dynesty.

jnesty.dynamic.stopping_function(results, args=None, rstate=None, M=None, return_vals=False)

Default stopping function. Faithful port of dynesty.

jnesty.dynamic.combine_saved_and_new(saved_results, new_results, logl_min, logl_max)

Merge a new batch run into the saved run.

Faithful port of dynesty.dynamicsampler.combine_runs including the plateau-aware logvol recompute.

Results

class jnesty.Results(data: dict)

Bases: object

Dynesty-compatible results object wrapping a dict.

Supports both dict-style access (results[‘logz’]) and attribute access (results.logz) for convenience.

samples_equal()

Return equal-weight posterior samples via resampling.

summary()

Print formatted summary of results.

jnesty.results.format_results(raw_result, prior_transform, ndim, nlive, rwalk_K, delta_logZ_threshold, context=None)

Convert raw sampler output (WhileLoopNSResult) into a Results object.

Handles JAX-to-numpy conversion, trapezoidal weight computation, live point addition, and efficiency calculation.

Parameters:
  • raw_result (WhileLoopNSResult) – Raw output from the nested sampling loop.

  • prior_transform (callable) – Prior transform function (unit cube -> physical space).

  • ndim (int) – Number of dimensions.

  • nlive (int) – Number of live points.

  • rwalk_K (int) – Number of random walk steps per iteration.

  • delta_logZ_threshold (float) – Convergence threshold used.

Returns:

Dynesty-compatible results object.

Return type:

Results

FITS I/O

jnesty.save_results(results, filepath)

Save a Results object to a FITS file.

Parameters:
  • results (Results) – Results object to save.

  • filepath (str) – Output file path.

jnesty.load_results(filepath)

Load a Results object from a FITS file.

Parameters:

filepath (str) – Path to the FITS file.

Returns:

Loaded Results object.

Return type:

Results

Plotting

All plotting functions accept a results dict (or Results object) as the first argument and return (fig, axes).

jnesty.runplot(results: Dict[str, Any], lnz_truth: float | None = None, fig: Figure | None = None, axes: ndarray | None = None, color: str = 'blue', lnz_color: str = 'red', truth_color: str = 'gray', plot_kwargs: Dict | None = None, **kwargs) → Tuple[Figure, ndarray]

Plot summary of the nested sampling run (Dynesty-style).

Creates a 4x1 subplot grid showing: 1. Live Points vs -ln X 2. Likelihood (normalized) vs -ln X 3. Importance Weight vs -ln X 4. Cumulative log evidence (ln Z) vs -ln X

Parameters:
  • results (dict) – Results dictionary from JAXNS (e.g., sampler.results).

  • lnz_truth (float, optional) – True log evidence for comparison.

  • fig (Figure, optional) – Figure to plot on.

  • axes (ndarray, optional) – Array of axes to plot on (4x1).

  • color (str) – Color for main plots.

  • lnz_color (str) – Color for evidence plot.

  • truth_color (str) – Color for truth values.

  • plot_kwargs (dict, optional) – Additional plotting arguments.

Returns:

  • fig (Figure) – Matplotlib figure.

  • axes (ndarray) – Array of matplotlib axes (4x1).

Examples

>>> fig, axes = plotting.runplot(sampler.results, lnz_truth=-10.5)
>>> plt.savefig('run_plot.png')
jnesty.traceplot(results: Dict[str, Any], dims: Tuple[int, ...] | None = None, truths: ndarray | None = None, truth_color: str = 'red', show_titles: bool = True, trace_cmap: str = 'plasma', connect: bool = False, quantiles: Tuple[float, ...] | None = None, fig: Figure | None = None, axes: ndarray | None = None, max_samples: int = 5000, **kwargs) → Tuple[Figure, ndarray]

Plot trace plots for each parameter.

Shows particle evolution over iterations (top panel) and 1D marginal posterior distribution (bottom panel) for each dimension.

Parameters:
  • results (dict) – Results dictionary from JAXNS.

  • dims (tuple of int, optional) – Which dimensions to plot (default: first min(ndim, 5) dimensions).

  • truths (array_like, optional) – True parameter values for overplotting.

  • truth_color (str) – Color for truth values.

  • show_titles (bool) – Show parameter labels in titles.

  • trace_cmap (str) – Colormap for trace points (colors by importance weight).

  • connect (bool) – Connect points to show particle paths (not yet implemented).

  • quantiles (tuple of float, optional) – Quantiles to show on 1D marginals (default: (0.16, 0.5, 0.84)).

  • fig (Figure, optional) – Figure to plot on.

  • axes (ndarray, optional) – Array of axes to plot on (ndim x 2).

  • max_samples (int) – Maximum samples to plot (downsample if larger).

Returns:

  • fig (Figure) – Matplotlib figure.

  • axes (ndarray) – Array of matplotlib axes (ndim x 2).

Examples

>>> fig, axes = plotting.traceplot(sampler.results, truths=np.zeros(ndim))
>>> plt.savefig('trace_plot.png')
jnesty.cornerplot(results: Dict[str, Any], dims: Tuple[int, ...] | None = None, truths: ndarray | None = None, truth_color: str = 'red', show_titles: bool = True, quantiles: Tuple[float, ...] | None = None, levels: Tuple[float, ...] | None = None, title_kwargs: Dict | None = None, color: str = 'blue', quiet: bool = False, fig: Figure | None = None, weights: ndarray | None = None, max_samples: int = 10000, **kwargs) → Tuple[Figure, ndarray]

Make a corner plot showing 1D and 2D marginal posteriors.

Uses the ‘corner’ package if available, otherwise falls back to a simple implementation using matplotlib.

Parameters:
  • results (dict) – Results dictionary from JAXNS.

  • dims (tuple of int, optional) – Which dimensions to plot.

  • truths (array_like, optional) – True parameter values.

  • truth_color (str) – Color for truth values.

  • show_titles (bool) – Show titles on 1D marginal plots.

  • quantiles (tuple of float, optional) – Quantiles to show on 1D plots (default: (0.16, 0.5, 0.84)).

  • levels (tuple of float, optional) – Credible levels for 2D contours (default: (0.68, 0.95)).

  • title_kwargs (dict, optional) – Keyword arguments for titles.

  • color (str) – Color for plots.

  • quiet (bool) – Suppress warnings about corner module.

  • fig (Figure, optional) – Figure to plot on.

  • weights (array_like, optional) – Sample weights for plotting (default: use results[‘logwt’]).

  • max_samples (int) – Maximum samples to plot (downsample if larger).

Returns:

  • fig (Figure) – Matplotlib figure.

  • axes (ndarray) – Array of matplotlib axes.

Examples

>>> fig, axes = plotting.cornerplot(sampler.results, truths=np.zeros(ndim))
>>> plt.savefig('corner_plot.png')
jnesty.cornerpoints(results: Dict[str, Any], dims: Tuple[int, ...] | None = None, truths: ndarray | None = None, truth_color: str = 'red', show_titles: bool = True, color: str = 'blue', alpha: float = 0.3, fig: Figure | None = None, max_samples: int = 10000, **kwargs) → Tuple[Figure, ndarray]

Make a corner plot showing sample positions (no KDE, faster).

Faster alternative to cornerplot() for large sample sets.

Parameters:
  • results (dict) – Results dictionary from JAXNS.

  • dims (tuple of int, optional) – Which dimensions to plot.

  • truths (array_like, optional) – True parameter values.

  • truth_color (str) – Color for truth values.

  • show_titles (bool) – Show titles on plots.

  • color (str) – Color for points.

  • alpha (float) – Transparency for points.

  • fig (Figure, optional) – Figure to plot on.

  • max_samples (int) – Maximum samples to plot (downsample if larger).

Returns:

  • fig (Figure) – Matplotlib figure.

  • axes (ndarray) – Array of matplotlib axes.

Examples

>>> fig, axes = plotting.cornerpoints(sampler.results)
>>> plt.savefig('corner_points.png')
jnesty.diagnostics(results: Dict[str, Any], fig: Figure | None = None, **kwargs) → Tuple[Figure, ndarray]

Comprehensive diagnostic plot showing convergence and efficiency.

Creates a 2x2 subplot grid showing: 1. Evidence evolution (logZ vs iteration) 2. Convergence metric (delta_logZ vs iteration) 3. Acceptance rate evolution 4. Sampling efficiency

Parameters:
  • results (dict) – Results dictionary from JAXNS.

  • fig (Figure, optional) – Figure to plot on.

Returns:

  • fig (Figure) – Matplotlib figure.

  • axes (ndarray) – Array of matplotlib axes (2x2).

Examples

>>> fig, axes = plotting.diagnostics(sampler.results)
>>> plt.savefig('diagnostics.png')

Core Sampling Loop

Configuration

class jnesty.WhileLoopNSConfig(nlive: int = 500, max_iterations: int = 10000, delta_logZ_threshold: float = 0.01, rwalk_K: int = 25, rwalk_step_scale: float = 1.0, target_acceptance: float = 0.5, prior_bounds: Array | None = None, verbose: bool = True, print_progress: bool = True, bound: str = 'none', bound_update_interval: int = 0, max_ellipsoids: int = 20, batch_size: int = 1, queue_size: int = 0, memory_frac: float = 0.9, ncdim: int = None, unit_cube_batch_size: int = 200, min_eff: float = 10.0, min_ncall: int = None, logl_min: float = -inf, logl_max: float = inf, init_live_x: Array | None = None, init_live_logL: Array | None = None, init_logvol: float = 0.0, init_logZ_val: float = -inf, init_logX: float = 0.0, init_ncall: int = 0, init_iter_offset: int = 0)

Configuration for the nested sampling run.

batch_size: int

Alias for field number 12

bound: str

Alias for field number 9

bound_update_interval: int

Alias for field number 10

delta_logZ_threshold: float

Alias for field number 2

init_iter_offset: int

Alias for field number 27

init_live_logL: Array | None

Alias for field number 22

init_live_x: Array | None

Alias for field number 21

init_logX: float

Alias for field number 25

init_logZ_val: float

Alias for field number 24

init_logvol: float

Alias for field number 23

init_ncall: int

Alias for field number 26

logl_max: float

Alias for field number 20

logl_min: float

Alias for field number 19

max_ellipsoids: int

Alias for field number 11

max_iterations: int

Alias for field number 1

memory_frac: float

Alias for field number 14

min_eff: float

Alias for field number 17

min_ncall: int

Alias for field number 18

ncdim: int

Alias for field number 15

nlive: int

Alias for field number 0

print_progress: bool

Alias for field number 8

prior_bounds: Array | None

Alias for field number 6

queue_size: int

Alias for field number 13

rwalk_K: int

Alias for field number 3

rwalk_step_scale: float

Alias for field number 4

target_acceptance: float

Alias for field number 5

unit_cube_batch_size: int

Alias for field number 16

verbose: bool

Alias for field number 7

Result

class jnesty.WhileLoopNSResult(logZ: float, logZ_error: float, H: float, delta_logZ: float, n_iterations: int, runtime: float, samples: Array, logL_samples: Array, delta_logZ_trajectory: Array, scale_trajectory: Array, acceptance_rate: float, live_x: Array = None, live_logL: Array = None, samples_u: Array = None, init_logX: float = 0.0, init_iter_offset: int = 0)

Raw results from the nested sampling loop.

H: float

Alias for field number 2

acceptance_rate: float

Alias for field number 10

delta_logZ: float

Alias for field number 3

delta_logZ_trajectory: Array

Alias for field number 8

init_iter_offset: int

Alias for field number 15

init_logX: float

Alias for field number 14

live_logL: Array

Alias for field number 12

live_x: Array

Alias for field number 11

logL_samples: Array

Alias for field number 7

logZ: float

Alias for field number 0

logZ_error: float

Alias for field number 1

n_iterations: int

Alias for field number 4

runtime: float

Alias for field number 5

samples: Array

Alias for field number 6

samples_u: Array

Alias for field number 13

scale_trajectory: Array

Alias for field number 9

Run Function

jnesty.run_nested_sampling(loglikelihood_fn, prior_sample_fn, ndim, config, key=None, prior_transform_fn=None, context=None)

Run nested sampling with iteration-granular adaptive termination.

Two-phase approach matching Dynesty: 1. Phase 1: Uniform rejection sampling until efficiency < min_eff 2. Transition: Fit initial bound from live points 3. Phase 2: Random walk sampling with adaptive bounding

Parameters:
  • loglikelihood_fn (callable) – Log-likelihood function (physical space).

  • prior_sample_fn (callable) – Prior sampling function (returns unit cube samples).

  • ndim (int) – Problem dimensionality.

  • config (WhileLoopNSConfig) – Run configuration.

  • key (jax.random.PRNGKey, optional)

  • prior_transform_fn (callable, optional)

Return type:

WhileLoopNSResult

Memory Estimation

jnesty.sampler.estimate_batch_size_from_memory(loglikelihood_fn, live_x, bound_axes, ndim, rwalk_K, requested_batch_size, memory_frac=0.9, verbose=True, context=None)

Cap batch_size based on available GPU memory.

Compiles a vmapped walk (batch_size=2) with the actual likelihood, uses XLA’s memory_analysis() to get peak memory, then caps batch_size to fit within memory_frac of total GPU memory.

Returns the capped (or unchanged) batch_size.

Bounding Methods

class jnesty.bounding.Bound(ndim, **kwargs)

Bases: object

Base class for bounding distributions.

contains(point)

Check if point is inside the bound.

fit(points)

Fit the bound to a set of live points. Returns self.

get_axes()

Return (ndim, ndim) axes matrix for proposal generation.

sample(key, n=1)

Sample point(s) from the bound.

class jnesty.bounding.UnitCube(ndim, **kwargs)

Bases: Bound

No bounding — sample uniformly from unit cube.

contains(point)

Check if point is inside the bound.

fit(points)

Fit the bound to a set of live points. Returns self.

get_axes()

Return (ndim, ndim) axes matrix for proposal generation.

sample(key, n=1)

Sample point(s) from the bound.

class jnesty.bounding.SingleEllipsoid(ndim, scale=1.0, **kwargs)

Bases: Bound

Single bounding ellipsoid fitted to live points.

contains(point)

Check if point is inside the bound.

fit(points)

Fit ellipsoid using covariance matrix eigenvalue decomposition.

get_axes()

Return (ndim, ndim) axes matrix for proposal generation.

sample(key, n=1)

Sample uniformly from the ellipsoid.

class jnesty.bounding.MultiEllipsoidBound(ndim, max_ellipsoids=20, enlarge=1.25, **kwargs)

Bases: Bound

Multi-ellipsoid decomposition using recursive k-means splitting.

Wraps the JIT-compiled multi-ellipsoid fitting from multi_ellipsoid.py. Stores state as a MultiEllipsoidState NamedTuple for JAX compatibility.

contains(point)

Check if point is inside the bound.

fit(points)

Fit multi-ellipsoid decomposition to live points.

get_axes()

Return axes for the largest-volume ellipsoid (for rwalk proposals).

get_walk_schedule(rwalk_K)

Compute a Bresenham interleaving schedule for rwalk proposals.

Returns an array of length rwalk_K with ellipsoid indices, proportional to each ellipsoid’s volume.

sample(key, n=1)

Sample uniformly from the union of ellipsoids (with overlap correction).

jnesty.bounding.get_bound(name, ndim, **kwargs)

Instantiate a bound by name string.

Parameters:
  • name (str) – One of ‘none’, ‘single’, ‘multi’.

  • ndim (int) – Number of dimensions.

  • **kwargs – Additional arguments passed to the bound constructor.

Returns:

Instantiated bound object.

Return type:

Bound

Internal Samplers

class jnesty.internal_samplers.InternalSampler(ndim, **kwargs)

Bases: object

Base class for proposal samplers.

sample(key, x_start, logL_constraint, loglikelihood_fn, axes, scale, n_steps, prior_bounds=None)

Generate a replacement point via the sampling strategy.

Parameters:
  • key (jax.random.PRNGKey)

  • x_start ((ndim,) starting point)

  • logL_constraint (float, minimum log-likelihood for the new point)

  • loglikelihood_fn (callable, log-likelihood function)

  • axes ((ndim, ndim) axes matrix from the current bound)

  • scale (float, current proposal scale)

  • n_steps (int, number of walk/slice steps)

  • prior_bounds (optional (2, ndim) array for rejection)

Return type:

(x_new, logL_new, n_accepted) tuple

tune(acceptance_rate, ndim)

Adapt scale based on acceptance rate. Returns new scale.

class jnesty.internal_samplers.RWalkSampler(ndim, target_acceptance=0.5, batch_size=1, ncdim=None, **kwargs)

Bases: InternalSampler

Random walk sampler with n-ball proposals and adaptive scale.

Matches Dynesty’s generic_random_walk / propose_ball_point: - Clustered dimensions (first n_cluster): perturbed via axes transform - Non-clustered dimensions: resampled uniformly from [0,1] - Boundary rejection (matches Dynesty default) - Scale adapted via Robbins-Munro using ncdim

When batch_size > 1, runs batch_size independent walks in parallel (vmap across GPU), each with n_steps // batch_size steps. Each batch walk can start from a different point and use different axes.

sample(key, x_starts, logL_constraint, loglikelihood_fn, axes, scale, n_steps, prior_bounds=None, walk_schedule=None, context=None)

K-step random walk using randsphere proposals.

Parameters:
  • x_starts (array) – If batch_size=1: (ndim,) single starting point. If batch_size>1: (batch_size, ndim) diverse starting points.

  • axes (array) – If batch_size=1: (ncdim, ncdim) single axes matrix. If batch_size>1: (batch_size, ncdim, ncdim) per-walk axes.

  • (x_new (Returns)

  • logL_new

  • n_accepted

  • includes (n_total) where n_total)

  • semantics). (boundary rejections (matches Dynesty's acceptance rate)

tune(scale, acceptance_rate, ndim, iteration)

Robbins-Munro scale adaptation (matches Dynesty).

Uses ncdim (number of clustered dimensions) instead of full ndim, matching Dynesty’s RWalkSampler.tune() at internal_samplers.py:491.

jnesty.internal_samplers.get_sampler(name, ndim, **kwargs)

Instantiate a sampler by name string.

Parameters:
  • name (str) – One of ‘rwalk’ (future: ‘slice’, ‘rslice’).

  • ndim (int) – Number of dimensions.

  • **kwargs – Additional arguments passed to the sampler constructor.

Returns:

Instantiated sampler object.

Return type:

InternalSampler

Queue Mode

jnesty.internal_samplers.vmap_queue_refill(refill_key, live_x, live_logL, loglstar, loglikelihood_fn, me_axes, me_logvol_ells, bound_axes, scale, rwalk_K, ndim, ncdim, queue_size, use_multi_ellipsoid, prior_bounds=None, context=None)

Generate queue_size candidate points in parallel via vmap.

Each candidate is produced by a FULL rwalk_K-step random walk from a random starting point (live point above loglstar) using a random ellipsoid (or bound_axes if not multi-ellipsoid). Matches Dynesty’s pool.map batch: every worker does a full walk independently.

Return type:

(queue_x, queue_logL, queue_nacc, queue_ntot) each of leading dim queue_size.

Utilities

jnesty.utils.randsphere(key, n)

Draw a point uniformly within an n-dimensional unit ball.

Matches Dynesty’s randsphere() implementation exactly. Formula: xhat = z * (U^(1/n) / ||z||) where z ~ N(0, I) and U ~ Uniform(0,1)

jnesty.utils.logsubexp(a, b)

Compute log(exp(a) - exp(b)) safely, assuming a > b.

jnesty.utils.logvol_prefactor(n)

Log of volume constant for n-dimensional unit sphere.

jnesty.utils.mean_and_cov(samples, weights)

Compute weighted mean and covariance (matches Dynesty’s dyutils.mean_and_cov).

Parameters:
  • samples (array, shape (nsamples, ndim)) – Parameter samples.

  • weights (array, shape (nsamples,)) – Importance weights.

Returns:

  • mean (array, shape (ndim,)) – Weighted sample mean.

  • cov (array, shape (ndim, ndim)) – Weighted sample covariance with Bessel-like correction.

Multi-Ellipsoid Fitting

jnesty.multi_ellipsoid.fit_multi_ellipsoid(points, max_ellipsoids=20, enlarge=1.25)

Fit a set of bounding ellipsoids using recursive k-means splitting.

Algorithm (matching Dynesty’s _bounding_ellipsoids): 1. Fit initial bounding ellipsoid to all points 2. Split into 2 clusters via k-means along major axis 3. Accept split if BIC criterion satisfied 4. Recursively split sub-clusters 5. Enlarge all ellipsoids by the given factor (matches Dynesty’s bound_enlarge)

JIT-compiled internally using masked operations and lax.while_loop.

Parameters:
  • points – (npoints, ndim) live points

  • max_ellipsoids – maximum number of ellipsoids

  • enlarge – volume enlargement factor (default 1.25, matches Dynesty)

Returns:

MultiEllipsoidState with fitted ellipsoids

jnesty.multi_ellipsoid.fit_bounding_ellipsoid(points)

Fit a bounding ellipsoid to a set of points.

Computes the minimum-volume ellipsoid containing all points by: 1. Computing the covariance matrix 2. Expanding to contain the farthest point (Mahalanobis distance)

Returns center, cov, axes, precision, logvol.

jnesty.multi_ellipsoid.get_axes_for_rwalk(key, state)

Select one ellipsoid proportional to volume and return its axes.

jnesty.multi_ellipsoid.sample_from_union(key, state)

Sample uniformly from the union of ellipsoids.

Algorithm (matching Dynesty’s MultiEllipsoid.sample()): 1. Select ellipsoid proportional to volume 2. Sample point from that ellipsoid 3. Count how many ellipsoids contain the point (q) 4. Accept with probability 1/q (for uniform over union)

jnesty.multi_ellipsoid.contains(state, point)

Check if point is inside any of the active ellipsoids.

jnesty.multi_ellipsoid.contains_all(state, points)

Check if all points are inside at least one active ellipsoids.