ultranest.simbase.minisbi package

Submodules

ultranest.simbase.minisbi.logistic module

Kumaraswamy-Logistic chained distribution defined on a unit hypercube.

ultranest.simbase.minisbi.logistic.sigmoid(x)[source]

Numerically stable sigmoid function.

Parameters:

x (numpy.ndarray or float)

Returns:

Sigmoid of x, clipped to avoid overflow.

Return type:

numpy.ndarray or float

ultranest.simbase.minisbi.logistic.logit(p)[source]

Logit (inverse sigmoid) function.

Parameters:

p (numpy.ndarray or float) – Probability value(s) in (0, 1).

Returns:

Log-odds of p.

Return type:

numpy.ndarray or float

ultranest.simbase.minisbi.logistic.kuma_log_prob(u, a, b)[source]

Log-density of Kumaraswamy(a, b) at u in (0, 1).

log p(u) = log(a) + log(b) + (a-1)*log(u) + (b-1)*log(1 - u^a)

Parameters:
  • u (torch.Tensor) – Values in (0, 1).

  • a (torch.Tensor) – Shape parameter, > 0.

  • b (torch.Tensor) – Shape parameter, > 0.

Returns:

Log-density at u.

Return type:

torch.Tensor

ultranest.simbase.minisbi.logistic.kuma_icdf(u, a, b)[source]

Inverse CDF (quantile function) of Kumaraswamy(a, b).

Maps u in (0, 1) to v in (0, 1) via:

v = (1 - (1 - u)^{1/b})^{1/a}

Parameters:
  • u (torch.Tensor) – Values in (0, 1).

  • a (torch.Tensor) – Shape parameter, > 0.

  • b (torch.Tensor) – Shape parameter, > 0.

Returns:

Quantile values in (0, 1).

Return type:

torch.Tensor

ultranest.simbase.minisbi.logistic.kuma_icdf_np(u, a, b)[source]

Inverse CDF (quantile function) of Kumaraswamy(a, b) — NumPy version.

Maps u in (0, 1) to v in (0, 1) via:

v = (1 - (1 - u)^{1/b})^{1/a}

Parameters:
  • u (numpy.ndarray) – Values in (0, 1).

  • a (numpy.ndarray) – Shape parameter, > 0.

  • b (numpy.ndarray) – Shape parameter, > 0.

Returns:

Quantile values in (0, 1).

Return type:

numpy.ndarray

ultranest.simbase.minisbi.logistic.logistic_log_cdf(x, loc, scale)[source]

Log CDF of Logistic(loc, scale).

Computes log sigmoid((x - loc) / scale).

Parameters:
  • x (torch.Tensor)

  • loc (torch.Tensor)

  • scale (torch.Tensor)

Returns:

Log CDF evaluated at x.

Return type:

torch.Tensor

ultranest.simbase.minisbi.logistic.nll_kuma_logistic_product(u, loc, scale, a, b)[source]

Negative log-likelihood of Kumaraswamy-Logistic unit distribution.

The generative model per dimension is:

v ~ TruncatedLogistic(loc, scale) on (0, 1) u = Kuma_CDF(v; a, b) = 1 - (1 - v^a)^b

The density of u is obtained by the change of variables v = Kuma_ICDF(u):

log p_U(u) = log p_L(v; loc, scale) - log Z(loc, scale) + log|dv/du|

where log|dv/du| = -log p_Kuma(v; a, b) (the Kumaraswamy log-density evaluated at v gives the magnitude of the Jacobian of the inverse map).

Parameters:
  • u (torch.Tensor) – Shape (batch, n_params), values in (0, 1).

  • loc (torch.Tensor) – Shape (batch, n_params).

  • scale (torch.Tensor) – Shape (batch, n_params), > 0.

  • a (torch.Tensor) – Shape (batch, n_params), > 0. Kumaraswamy shape parameter.

  • b (torch.Tensor) – Shape (batch, n_params), > 0. Kumaraswamy shape parameter.

Returns:

Scalar mean NLL.

Return type:

torch.Tensor

ultranest.simbase.minisbi.logistic.sample_kuma_logistic_product(loc, scale, a, b, n_samples, rng)[source]

Sample from unit Kumaraswamy-Logistic distribution.

The inverse CDF of U = Kuma_CDF(V) where V ~ TruncLogistic is:
  1. Draw uniform w in (0, 1).

  2. v = TruncLogistic_ICDF(w; loc, scale) via standard inversion.

  3. u = Kuma_CDF(v; a, b) = 1 - (1 - v^a)^b.

Parameters:
  • loc (numpy.ndarray) – Shape (n_params,).

  • scale (numpy.ndarray) – Shape (n_params,).

  • a (numpy.ndarray) – Shape (n_params,), Kumaraswamy shape parameter, > 0.

  • b (numpy.ndarray) – Shape (n_params,), Kumaraswamy shape parameter, > 0.

  • n_samples (int) – Number of samples to draw.

  • rng (numpy.random.Generator) – Random number generator.

Returns:

Shape (n_samples, n_params), values in (0, 1).

Return type:

numpy.ndarray

ultranest.simbase.minisbi.logistic.kuma_logistic_cdf(x_val, loc, scale, a, b)[source]

CDF of the Kumaraswamy-Logistic chained distribution at a scalar point.

The generative model is:

v ~ TruncatedLogistic(loc, scale) on (0, 1) u = 1 - (1 - v^a)^b

The CDF of u at x is P(u <= x) = P(v <= Kuma_ICDF(x; a, b)) under the truncated logistic.

Parameters:
  • x_val (float) – Point in [0, 1].

  • loc (float)

  • scale (float) – Must be > 0.

  • a (float) – Kumaraswamy shape parameter, > 0.

  • b (float) – Kumaraswamy shape parameter, > 0.

Returns:

CDF value in [0, 1].

Return type:

float

ultranest.simbase.minisbi.logistic.kuma_logistic_cdf_vec(u_vec, loc, scale, a, b)[source]

Cumulative distribution function of the Kumaraswamy-Logistic distribution.

The CDF is evaluated element-wise over a vector of points.

Parameters:
  • u_vec (numpy.ndarray) – Shape (d,), points at which to evaluate the CDF, each in (0, 1).

  • loc (numpy.ndarray) – Shape (d,).

  • scale (numpy.ndarray) – Shape (d,), must be positive.

  • a (numpy.ndarray) – Shape (d,), Kumaraswamy shape parameter, must be positive.

  • b (numpy.ndarray) – Shape (d,), Kumaraswamy shape parameter, must be positive.

Returns:

Shape (d,), CDF values in [0, 1].

Return type:

numpy.ndarray

ultranest.simbase.minisbi.logistic.kuma_logistic_icdf_vec(t_vec, loc, scale, a, b)[source]

Inverse CDF (quantile function) of the Kumaraswamy-Logistic distribution.

Parameters:
  • t_vec (numpy.ndarray) – Shape (d,), quantile levels in (0, 1).

  • loc (numpy.ndarray) – Shape (d,).

  • scale (numpy.ndarray) – Shape (d,), must be positive.

  • a (numpy.ndarray) – Shape (d,), Kumaraswamy shape parameter, must be positive.

  • b (numpy.ndarray) – Shape (d,), Kumaraswamy shape parameter, must be positive.

Returns:

Shape (d,), quantile values in (0, 1).

Return type:

numpy.ndarray

ultranest.simbase.minisbi.logistic.kuma_logistic_logpdf_vec(u_vec, loc, scale, a, b)[source]

Log-density of the Kumaraswamy-Logistic distribution, summed over dimensions.

This equals the log Jacobian log|du/dt| needed to correct the nested-sampling likelihood when the prior is this distribution.

Parameters:
  • u_vec (numpy.ndarray) – Shape (d,), values in (0, 1).

  • loc (numpy.ndarray) – Shape (d,).

  • scale (numpy.ndarray) – Shape (d,).

  • a (numpy.ndarray) – Shape (d,), Kumaraswamy shape parameter.

  • b (numpy.ndarray) – Shape (d,), Kumaraswamy shape parameter.

Returns:

Sum of per-dimension log-densities.

Return type:

float

ultranest.simbase.minisbi.nested module

Helpers for using nested sampling on top of an auxiliary distribution.

ultranest.simbase.minisbi.nested.get_distribution_parameters(model, observed_data)[source]

Query neural network model for Kumaraswamy-logistic distribution parameters.

Parameters:
  • model (torch.nn.Module) – A trained neural posterior estimator that returns the tuple (loc, scale, a, b) when called with an input tensor.

  • observed_data (array_like) – The observed data to condition on. Will be converted to a torch.float32 tensor and given a batch dimension of 1.

Returns:

A dictionary with keys 'loc', 'scale', 'a', and 'b', each mapping to a Python list of floats representing the corresponding distribution parameter for each dimension.

Return type:

dict

class ultranest.simbase.minisbi.nested.KLPTransform(loc, scale, a, b)[source]

Bases: object

Coordinate transform for a Kumaraswamy-logistic distribution (KLP).

Provides mappings between nested-sampler unit-cube coordinates t and prior unit-cube coordinates u, along with the associated log Jacobian and CDF evaluation.

Parameters:
  • loc (array_like) – Location parameters of the Kumaraswamy-logistic distribution, shape (n_params,).

  • scale (array_like) – Scale parameters of the Kumaraswamy-logistic distribution, shape (n_params,).

  • a (array_like) – First shape parameters of the Kumaraswamy distribution, shape (n_params,).

  • b (array_like) – Second shape parameters of the Kumaraswamy distribution, shape (n_params,).

Initialise.

transform(t)[source]

Map unit-cube coordinates t to prior unit-cube coordinates u via inverse CDF.

Parameters:

t (np.ndarray) – Uniformly distributed sample from the nested sampler, shape (n_params,).

Returns:

u – Corresponding unit-cube coordinates of shape (n_params,) and dtype float32; pass to prior_transform to get physical parameters.

Return type:

np.ndarray

log_jacobian(t)[source]

Compute log-Jacobian.

This is for the transform t -> u, equal to the log-density of the KLP distribution at u = transform(t).

Add this value to the true log-likelihood when passing to the nested sampler so that the sampler correctly targets the posterior.

Parameters:

t (np.ndarray) – Nested-sampler unit-cube coordinates, shape (n_params,).

Returns:

log_q – log q(u(t) | x_obs) – always finite.

Return type:

float

cdf(u)[source]

Evaluate the CDF.

Parameters:

u (np.ndarray) – Prior unit-cube coordinates, shape (n_params,).

Returns:

t – Nested-sampler unit-cube coordinates corresponding to u, shape (n_params,).

Return type:

np.ndarray

logpdf(u)[source]

Evaluate log-density.

This is used by importance sampling to compute the log proposal density log q(u | x_obs) for each sample drawn from the NPE approximate posterior.

Parameters:

u (np.ndarray) – Prior unit-cube coordinates, shape (n_params,).

Returns:

log_q – Sum of log-densities across all dimensions, sum_i log q(u_i | x_obs).

Return type:

float

ultranest.simbase.minisbi.norm module

Input data standardization layers.

class ultranest.simbase.minisbi.norm.ZScoreNorm(n_features: int, eps: float = 1e-08)[source]

Bases: Module

Per-feature z-score normalisation layer.

For each feature, computes the sample mean and standard deviation from a calibration set. At forward time the raw input is whitened feature-wise: z = (x - mean) / std.

Parameters:
  • n_features (int) – Dimensionality of the input.

  • eps (float) – Small constant added to the standard deviation for numerical stability.

Initialise the layer and register per-feature statistic buffers.

Parameters:
  • n_features (int) – Dimensionality of the input.

  • eps (float) – Small constant added to the standard deviation for numerical stability.

fit(x_np: ndarray) → None[source]

Compute per-feature mean and std from a numpy array.

Parameters:

x_np (np.ndarray) – Array of shape (N, n_features) used to compute the statistics.

Return type:

None

forward(x: Tensor) → Tensor[source]

Apply per-feature z-score normalisation to the input tensor.

Parameters:

x (torch.Tensor) – Input tensor of shape (…, n_features).

Returns:

Tensor of the same shape as x, z-score normalised per feature. If the layer has not been fitted, x is returned unchanged.

Return type:

torch.Tensor

ultranest.simbase.minisbi.npe module

Neural Posterior Estimation (NPE) training.

class ultranest.simbase.minisbi.npe.CascadeNet(input_dim, output_dim, hidden_widths, activation_cls)[source]

Bases: Module

Cascade MLP architecture.

Each hidden layer forwards half of its output neurons directly to the final layer (skip connection) and the other half to the next hidden layer.

Concretely, layer i produces hidden_widths[i] neurons. We split them evenly: the first half (skip_size = hidden_widths[i] // 2) accumulates in a “cascade buffer” that is concatenated to the input of the final linear layer; the second half (pass_size) is forwarded to the next hidden layer.

Parameters:
  • input_dim (int) – Dimensionality of the network input.

  • output_dim (int) – Dimensionality of the network output.

  • hidden_widths (list of int) – Number of neurons in each hidden layer.

  • activation_cls (type) – Activation class (e.g. nn.ReLU); instantiated per layer.

Initialise.

forward(x)[source]

Forward pass through the cascade network.

Parameters:

x (torch.Tensor) – Input tensor of shape (..., input_dim).

Returns:

Output tensor of shape (..., output_dim).

Return type:

torch.Tensor

class ultranest.simbase.minisbi.npe.NPENetwork(n_data, n_params, depth, width, activation_name, layer_shape: str)[source]

Bases: Module

Network that outputs a product of Kumaraswamy-Logistic chained distributions living on the unit cube [0, 1]^d.

For each parameter dimension the network predicts 4 values:
  • loc (via sigmoid, in (0,1))

  • log_scale (unconstrained; exponentiated -> scale > 0)

  • log_a (unconstrained; exponentiated -> a > 0, Kumaraswamy shape)

  • log_b (unconstrained; exponentiated -> b > 0, Kumaraswamy shape)

Parameters:
  • n_data (int) – Raw input dimension.

  • n_params (int) – Number of model parameters.

  • depth (int) – Number of hidden layers.

  • width (int) – Width of each hidden layer.

  • activation_name (str) – Activation name (e.g. 'ReLU').

  • layer_shape (str) – Architecture shape: 'rectangular', 'triangular', or 'cascade'.

Initialise.

fit_norm(x_np: ndarray) → None[source]

Fit the moment-matching normalisation layer on a representative sample.

Parameters:

x_np (numpy.ndarray) – Array of shape (n_samples, n_data) used to compute the normalisation statistics.

Return type:

None

forward(x_raw)[source]

Map raw data to per-parameter distribution parameters.

Parameters:

x_raw (torch.Tensor (batch, n_data))

Returns:

  • loc (torch.Tensor (batch, n_params) in (0,1))

  • scale (torch.Tensor (batch, n_params) > 0)

  • a (torch.Tensor (batch, n_params) > 0)

  • b (torch.Tensor (batch, n_params) > 0)

ultranest.simbase.minisbi.npe.sample_posterior(model, observed_data, prior_transform, n_params, n_posterior_samples)[source]

Draw posterior samples for a single observed dataset.

Parameters:
  • model (NPENetwork) – Trained NPE model.

  • observed_data (numpy.ndarray) – 1-D array of observed data values, shape (n_data,).

  • prior_transform (callable) – Function (u) -> theta mapping unit-cube samples to the physical parameter space.

  • n_params (int) – Number of model parameters.

  • n_posterior_samples (int) – Number of posterior samples to return.

Returns:

  • posterior_samples_u (numpy.ndarray) – Samples in unit-cube space, shape (n_posterior_samples, n_params).

  • posterior_samples_theta (numpy.ndarray) – Samples in physical parameter space, shape (n_posterior_samples, n_params).

ultranest.simbase.minisbi.npe.train_npe(*, folder, generate_noiseless_batch, inject_noise, n_params, fresh_sim_batch_size, npe_lr, base_seed, max_model_evals, num_processes=1, patience=30, patience_min_delta=0.0001, npe_batches_epoch=8, npe_width=1024, npe_activation_cls='ReLU', npe_depth=6, val_size=1024, norm_size=2000, layer_shape='cascade', fresh_example_fraction=0.5)[source]

Train a Neural Posterior Estimator (NPE) with a product-of-Kumaraswamy-Logistic output.

Parameters:
  • folder (str) – Directory in which to save or load the trained model.

  • generate_noiseless_batch (callable) – Simulation function with signature (batch_idx, n_sim, seed, n_params) -> dict.

  • inject_noise (callable) – Function (props, rng) -> noisy_vector.

  • n_params (int) – Number of model parameters.

  • fresh_sim_batch_size (int) – Number of fresh simulator draws requested per sub-batch. This is the number of new simulations run each time the simulator is called; it is not the number of examples seen by the neural network in one gradient step (see effective_train_batch_size).

  • npe_lr (float) – Learning rate for the Adam optimiser.

  • base_seed (int) – Base random seed used throughout training.

  • max_model_evals (int) – Maximum total number of simulator evaluations to generate across all training batches.

  • num_processes (int, optional) – Number of parallel worker processes. Default is 1.

  • patience (int, optional) – Number of epochs without improvement before early stopping. Default is 30.

  • patience_min_delta (float, optional) – Minimum validation-loss improvement to reset the patience counter. Default is 1e-4.

  • npe_batches_epoch (int, optional) – Number of simulation batches drawn per epoch. Default is 8.

  • npe_width (int, optional) – Width of each hidden layer. Default is 1024.

  • npe_activation_cls (str) – Activation function name. Default is 'ReLU'.

  • npe_depth (int, optional) – Number of hidden layers. Default is 6.

  • val_size (int, optional) – Number of samples in the fixed validation set. Default is 1024.

  • norm_size (int, optional) – Number of samples for determining the input normalisation validation set. Default is 2000.

  • layer_shape (str, optional) – Architecture shape: 'rectangular' (default), 'triangular', or 'cascade'.

  • fresh_example_fraction (float, optional) – Fraction of each training mini-batch that consists of freshly simulated examples. The remainder (1 - fresh_example_fraction) is filled by replaying examples from the history buffer, so the effective batch size seen by the network (effective_train_batch_size) is larger than fresh_sim_batch_size. Must be in (0, 1]. When set to 1.0 no replay is used and effective_train_batch_size == fresh_sim_batch_size. Default is 0.5.

Notes

The relationship between the key batch-size quantities is:

replay_example_count    = fresh_sim_batch_size
                          * (1 - fresh_example_fraction)
                          / fresh_example_fraction
effective_train_batch_size = fresh_sim_batch_size
                             + replay_example_count

fresh_simulator_evals counts the cumulative number of simulator calls made so far (i.e. the total number of freshly generated parameter–data pairs, excluding replayed examples).

Returns:

model – Trained NPE model in eval mode.

Return type:

NPENetwork

ultranest.simbase.minisbi.plot module

Validation / diagnostic utilities.

ultranest.simbase.minisbi.plot.rank_histogram(*, model, generate_noiseless_batch, inject_noise, n_params, folder, n_test=500, n_posterior_samples=200, seed=98765, param_names=None, prior_transform=None, n_bins=20)[source]

Rank-histogram (Tallagrand / PIT) test.

For each of n_test test simulations, the rank of the true parameter value is computed analytically from the Kumaraswamy-Logistic CDF, then converted to a discrete rank in [0, n_posterior_samples]. A well-calibrated posterior yields a flat histogram.

Results are saved to <folder>/rank_histograms.pdf.

Parameters:
  • model (NPENetwork) – The trained neural posterior estimation network.

  • generate_noiseless_batch (callable) – Cached generator that produces noiseless simulation batches.

  • inject_noise (callable) – Noise injector applied to each noiseless simulation.

  • n_params (int) – Number of model parameters.

  • folder (str) – Output directory in which to save the rank histogram PDF.

  • n_test (int, optional) – Number of test simulations. Default is 500.

  • n_posterior_samples (int, optional) – Posterior draws per simulation, used to discretise the CDF rank. Default is 200.

  • seed (int, optional) – RNG seed. Default is 98765.

  • param_names (list of str or None, optional) – Names for each parameter. If None, defaults to [‘param_0’, ‘param_1’, …].

  • prior_transform (optional) – not used

  • n_bins (int, optional) – Number of histogram bins. Default is 20.

Returns:

ranks – Rank of the true value in [0, n_posterior_samples]. Shape: (n_test, n_params).

Return type:

np.ndarray

ultranest.simbase.minisbi.plot.parameter_coverage_test(*, model, generate_noiseless_batch, inject_noise, n_params, folder, n_test=500, credible_levels=None, seed=11223, param_names=None, prior_transform=None)[source]

Expected-coverage (parameter coverage) test.

For each test simulation, the rank of the true parameter under the approximate posterior is computed analytically from the Kumaraswamy-Logistic CDF. The rank (a value in [0, 1]) is then compared against the nominal credible levels to determine coverage.

Results are saved to <folder>/coverage_test.pdf.

Parameters:
  • model (NPENetwork)

  • generate_noiseless_batch (callable)

  • inject_noise (callable)

  • n_params (int)

  • folder (str)

  • n_test (int, optional)

  • credible_levels (list of float or None, optional)

  • seed (int, optional)

  • param_names (list of str or None, optional)

  • prior_transform (optional) – not used

Returns:

coverage – Empirical coverage fraction at each credible level.

Return type:

np.ndarray, shape (len(credible_levels), n_params)

ultranest.simbase.minisbi.plot.posterior_predictive_check(*, posterior_samples_theta, observed_data, generate_mean_and_noise, inject_noise, folder, n_mean_curves=200, n_realisation_curves=50, seed=77777, x_coords=None)[source]

Posterior predictive check.

Draws parameter samples from the posterior and generates:
  • posterior mean curves (noiseless signal for each sample)

  • posterior data realisations (noisy draws)

then plots them together with the true observed data and saves the result to <folder>/posterior.pdf.

Parameters:
  • posterior_samples_theta (np.ndarray) – Physical parameter samples from the posterior. Shape: (n_posterior, n_params).

  • observed_data (np.ndarray) – The actual observed dataset. Shape: (n_data,).

  • generate_mean_and_noise (callable) – Same function used during simulation; generates noiseless signal properties given a parameter vector.

  • inject_noise (callable) – Noise injector that takes simulation properties and an RNG instance and returns a noisy realisation.

  • folder (str) – Output directory in which to save the posterior predictive PDF.

  • n_mean_curves (int, optional) – How many posterior mean curves to overlay. Default is 200.

  • n_realisation_curves (int, optional) – How many noisy realisations to overlay. Default is 50.

  • seed (int, optional) – RNG seed for noise injection. Default is 77777.

  • x_coords (np.ndarray or None, optional) – x-axis coordinates for the data. If None, defaults to np.linspace(-5, 5, n_data).

Returns:

Saves the figure to <folder>/posterior.pdf and prints the path.

Return type:

None

ultranest.simbase.minisbi.utils module

Utilities for sampling and wrapping functions.

ultranest.simbase.minisbi.utils.sample_prior_u(rng, n_params)[source]

Sample a single draw from a uniform prior over the unit hypercube.

Parameters:
  • rng (numpy.random.Generator) – Random number generator used to draw samples.

  • n_params (int) – Number of parameters (dimensionality of the hypercube).

Returns:

1-D array of shape (n_params,) with dtype float32, containing values sampled uniformly from [0.0, 1.0).

Return type:

numpy.ndarray

ultranest.simbase.minisbi.utils.make_memory(folder)[source]

Create a joblib Memory object for caching results to disk.

Parameters:

folder (str or os.PathLike) – Path to the directory where cached results will be stored.

Returns:

A Memory instance configured to use folder as its cache location, with verbosity set to 0.

Return type:

joblib.Memory

ultranest.simbase.minisbi.utils.make_cached_generate(memory, prior_transform, generate_mean_and_noise)[source]

Create a cached function that generates noiseless simulation batches.

The returned function is decorated with memory.cache so that repeated calls with identical arguments are served from disk rather than recomputed.

Parameters:
  • memory (joblib.Memory) – Joblib memory object used to cache the inner function.

  • prior_transform (callable) – Function that maps a unit-hypercube sample u (1-D array of shape (n_params,)) to a parameter vector theta in the model space.

  • generate_mean_and_noise (callable) – Function with signature (idx, seed, theta) that returns the noiseless (mean) summary properties for a single simulation.

Returns:

A cached function generate_noiseless_batch(batch_idx, n_sim, seed, n_params) that returns a dict with keys:

'u_samples'

2-D float32 array of shape (n_sim, n_params) containing unit-hypercube draws.

'mean_props'

List of length n_sim containing the noiseless summary properties for each simulation.

Return type:

callable

ultranest.simbase.minisbi.utils.inject_noise_batch(batch_dict, rng, inject_noise)[source]

Inject noise into a pre-generated batch of noiseless simulations.

Parameters:
  • batch_dict (dict) –

    Dictionary returned by generate_noiseless_batch, containing:

    'u_samples'

    2-D float32 array of shape (n_sim, n_params).

    'mean_props'

    List of length n_sim with noiseless summary properties.

  • rng (numpy.random.Generator) – Random number generator used by inject_noise to draw noise realisations.

  • inject_noise (callable) – Function with signature (props, rng) that takes noiseless summary properties and returns a 1-D array of noisy data values.

Returns:

  • u_samples (numpy.ndarray) – 2-D float32 array of shape (n_sim, n_params) containing the unit-hypercube parameter draws.

  • raw_data (numpy.ndarray) – 2-D float32 array of shape (n_sim, n_data) containing the noisy simulation outputs, where n_data is the length of the array returned by inject_noise.

ultranest.simbase.minisbi.utils.random_derangement(n, device=None)[source]

Generate a uniformly random derangement (permutation without fixed points).

The function resamples until a valid derangement is found.

Parameters:
  • n (int) – Number of elements to permute.

  • device (torch.device or None, optional) – Device on which to create the permutation tensor.

Returns:

1-D integer tensor of length n with no element equal to its index.

Return type:

torch.Tensor

Module contents

Simulation-based inference (SBI) tools.