nessai.utils

General utilities for nessai.

Submodules

Package Contents

Classes

NessaiJSONEncoder

Class to encode numpy arrays and other non-serialisable objects.

Functions

get_multivariate_normal(dims, var=1, device='cpu')

Return a Pytorch distribution that is normally distributed in n dims

get_uniform_distribution(dims, r, device='cpu')

Return a torch distribution that is uniform in the number of dims

auto_bins(x, max_bins=50)

Compute the number bins for a histogram using numpy.histogram_bin_edges

bonferroni_correction(p_values, alpha=0.05)

Apply the Bonferroni correction for multiple tests.

compute_indices_ks_test(indices, nlive, mode='D+')

Compute the two-sided KS test for discrete insertion indices for a given

is_jsonable(x)

Check if an object is JSON serialisable.

safe_file_dump(data, filename, module, save_existing=False)

Safely dump data to a .pickle file.

save_live_points(live_points, filename)

Save live points to a file using JSON.

setup_logger(output=None, label='nessai', log_level='WARNING')

Setup the logger.

configure_edge_detection(d, detect_edges)

Configure parameters for edge detection

detect_edge(x, x_range=None, percent=0.1, cutoff=0.5, nbins='auto', allow_both=False, allow_none=False, allowed_bounds=['lower', 'upper'], test=None)

Detect edges in input distributions based on the density.

determine_rescaled_bounds(prior_min, prior_max, x_min, x_max, invert=None, inversion=False, offset=0, rescale_bounds=[-1, 1])

Determine the values of the prior min and max in the rescaled

inverse_rescale_minus_one_to_one(x, xmin, xmax)

Rescale from -1 to 1 to xmin to xmax

inverse_rescale_zero_to_one(x, xmin, xmax)

Rescale from 0 to 1 to xmin to xmax

logit(x, fuzz=1e-12)

Logit function that also returns log Jacobian determinant.

rescale_minus_one_to_one(x, xmin, xmax)

Rescale a value to -1 to 1

rescale_zero_to_one(x, xmin, xmax)

Rescale a value to 0 to 1

sigmoid(x, fuzz=1e-12)

Sigmoid function that also returns log Jacobian determinant.

compute_radius(n, q=0.95)

Compute the radius that contains a fraction of the total probability in an n-dimensional unit Gaussian.

draw_gaussian(dims, r=1, N=1000, fuzz=1.0)

Wrapper for numpy.random.randn that deals with extra input parameters

draw_nsphere(dims, r=1, N=1000, fuzz=1.0)

Draw N points uniformly within an n-sphere of radius r

draw_surface_nsphere(dims, r=1, N=1000)

Draw N points uniformly from n-1 sphere of radius r using Marsaglia's

draw_truncated_gaussian(dims, r, N=1000, fuzz=1.0, var=1)

Draw N points from a truncated gaussian with a given a radius

draw_uniform(dims, r=(1, ), N=1000, fuzz=1.0)

Draw from a uniform distribution on [0, 1].

compute_minimum_distances(samples, metric='euclidean')

Compute the distance to the nearest neighbour of each sample

rolling_mean(x, N=10)

Compute the rolling mean with a given window size.

replace_in_list(target_list, targets, replacements)

Replace (in place) an entry in a list with a given element.

configure_threads(max_threads=None, pytorch_threads=None, n_pool=None)

Configure the number of threads available.

Attributes

rescaling_functions