nessai.utils.sampling

Utilities related to drawing samples.

Module Contents

Classes

NDimensionalTruncatedGaussian

Class for sampling from a radially truncated n-dimensional Gaussian

Functions

compute_radius(n[, q])

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

draw_surface_nsphere(dims[, r, N])

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

draw_nsphere(dims[, r, N, fuzz])

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

draw_uniform(dims[, r, N, fuzz])

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

draw_gaussian(dims[, r, N, fuzz])

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

draw_truncated_gaussian(dims, r[, N, fuzz, var])

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

nessai.utils.sampling.compute_radius(n, q=0.95)

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

Uses the inverse CDF of a chi-distribution with n degrees of freedom.

Parameters:
nint

Number of dimensions

qfloat

Fraction of the total probability

Returns:
float

Radius

nessai.utils.sampling.draw_surface_nsphere(dims, r=1, N=1000)

Draw N points uniformly from n-1 sphere of radius r using Marsaglia’s algorithm. E.g for 3 dimensions returns points on a ‘regular’ sphere.

See Marsaglia (1972)

Parameters:
dimsint

Dimension of the n-sphere

rfloat, optional

Radius of the n-sphere, if specified it is used to rescale the samples

Nint, optional

Number of samples to draw

Returns:
ndarray

Array of samples with shape (N, dims)

nessai.utils.sampling.draw_nsphere(dims, r=1, N=1000, fuzz=1.0)

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

Parameters:
dimsint

Dimension of the n-sphere

rfloat, optional

Radius of the n-ball

Nint, optional

Number of samples to draw

fuzzfloat, optional

Fuzz factor by which to increase the radius of the n-ball

Returns:
ndarray

Array of samples with shape (N, dims)

nessai.utils.sampling.draw_uniform(dims, r=(1,), N=1000, fuzz=1.0)

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

Deals with extra input parameters used by other draw functions

Parameters:
dimsint

Dimension of the n-sphere

rfloat, optional

Radius of the n-ball. (Ignored by this function)

Nint, ignored

Number of samples to draw

fuzzfloat, ignored

Fuzz factor by which to increase the radius of the n-ball. (Ignored by this function)

Returns:
ndarraay

Array of samples with shape (N, dims)

nessai.utils.sampling.draw_gaussian(dims, r=1, N=1000, fuzz=1.0)

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

Parameters:
dimsint

Dimension of the n-sphere

rfloat, optional

Radius of the n-ball

Nint, ignored

Number of samples to draw

fuzzfloat, ignored

Fuzz factor by which to increase the radius of the n-ball

Returns:
ndarray

Array of samples with shape (N, dims)

nessai.utils.sampling.draw_truncated_gaussian(dims, r, N=1000, fuzz=1.0, var=1)

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

Parameters:
dimsint

Dimension of the n-sphere

rfloat

Radius of the truncated Gaussian

Nint, ignored

Number of samples to draw

fuzzfloat, ignored

Fuzz factor by which to increase the radius of the truncated Gaussian

Returns:
ndarray

Array of samples with shape (N, dims)

class nessai.utils.sampling.NDimensionalTruncatedGaussian(dims: int, radius: float, fuzz: float = 1.0)

Class for sampling from a radially truncated n-dimensional Gaussian

Parameters:
dims

The number of dimensions

radius

The radius for the truncation

fuzzfloat

The fuzz factor

sample(N: int) numpy.ndarray

Sample from the distribution.

Parameters:
nint

Number of samples to draw

Returns:
numpy.ndarray

Array of samples of shape [n, dims].