ns_interfaces#
Wrappers for external nested samplers.
- gpry.ns_interfaces.ensure_scalar(x)#
- exception gpry.ns_interfaces.NestedSamplerNotInstalledError[source]#
Bases:
ExceptionException to be raised at initialization of any of the interfaces if the NS failed to be imported.
- class gpry.ns_interfaces.NSInterface(bounds, verbosity=None)[source]#
Bases:
ABCMeta-class for Nested Sampler interfaces.
- abstract run(logp_func, param_names=None, out_dir=None, seed=None)[source]#
Runs the nested sampler.
param_names (optional, otherwise x_[i] will be used) should be a list of sampled parameter names, or a list of (name, label) tuples. Labels are interpreted as LaTeX but should not include ‘$’ signs.
Must return a tuple (X_MC, y_MC, w_MC, logZ, logZstd).
- abstract delete_output(out_dir=None)[source]#
Deletes the last sampler output.
If
out_dirspecified, deletes the one stored there instead.
- static process_out_dir(out_dir, default_prefix='ns_samples', random_if_undefined=True)[source]#
Given an output root
out_dirasfolder/orfolder/prefix, returns separately the folder path and the file name prefix.If
random_if_undefinedis True (default), it returns a random temp folder. Otherwise it raisesValueError.
- class gpry.ns_interfaces.InterfacePolyChord(bounds, verbosity=3)[source]#
Bases:
NSInterfaceInterface for the PolyChord nested sampler, by W. Handley, M. Hobson & A. Lasenby.
- class gpry.ns_interfaces.InterfaceNessai(bounds, verbosity=3)[source]#
Bases:
NSInterfaceInterface for the
nessainested sampler, by M.J. Williams, J. Veitch and C. Messenger.See https://nessai.readthedocs.io
- set_precision(nlive=None, precision_criterion=None, **kwargs)[source]#
Sets precision parameters for the nested sampler.
- class gpry.ns_interfaces.InterfaceUltraNest(bounds, verbosity=3)[source]#
Bases:
NSInterfaceInterface for the
ultranestnested sampler, by J. Buchner.See https://johannesbuchner.github.io/UltraNest
- set_precision(nlive=None, precision_criterion=None, num_repeats=None, max_ncalls=None, **kwargs)[source]#
Sets precision parameters for the nested sampler.
- class gpry.ns_interfaces.InterfaceBlackJAX(bounds, verbosity=3)[source]#
Bases:
NSInterfaceInterface for the BlackJAX nested sampler (Handley-lab fork with NS support).
Uses Nested Slice Sampling (NSS) with Hit-and-Run Slice Sampling as the inner kernel. Fully JAX-native, JIT-compilable, and GPU-compatible.
- set_precision(nlive=None, num_repeats=None, max_ncalls=None, precision_criterion=None, nprior=None, num_inner_steps=None, max_steps=None, num_delete=None, **kwargs)[source]#
Sets precision parameters for the nested sampler.
- run(logp_func, param_names=None, out_dir=None, seed=None)[source]#
Runs the BlackJAX nested sampler.
- Parameters:
logp_func (callable) – Log-likelihood function. Takes array X of shape (d,) or (n, d) and returns scalar or array.
param_names (list, optional) – Parameter names.
out_dir (str, optional) – Not used (BlackJAX is in-memory), but kept for interface compatibility.
seed (int, optional) – Random seed.
- Returns:
(X_MC, y_MC, w_MC)
- Return type:
arrays of samples, log-likelihoods, and normalized weights.