ParameterSpace

class cosmic.sample.stroopwafel.ParameterSpace(params)[source]

Bases: object

An ordered collection of Parameters with vectorized operations.

All methods operate on (N, D) numpy arrays whose columns follow the order in which the parameters were supplied.

Parameters:
paramslist of Parameter

List of parameter definitions. The column order of every (N, D) array produced by this class matches the order of this list.

Methods Summary

compute_prior(samples)

Compute the prior probability for each row.

compute_sigma(hit_samples, ...)

Compute per-hit, per-dimension Gaussian widths (sigma).

idx(name)

Get the column index for a parameter by name.

in_bounds(samples)

Check which rows of an (N, D) array are within parameter bounds.

sample(n[, rng])

Draw n samples from the prior distribution.

to_physical(samples)

Convert an (N, D) array from sampling space to physical space.

to_sampling(samples)

Convert an (N, D) array from physical space to sampling space.

Methods Documentation

compute_prior(samples)[source]

Compute the prior probability for each row.

The joint prior is the product of the marginal priors across all dimensions.

Parameters:
samplesnumpy.ndarray

(N, D) array in sampling space.

Returns:
numpy.ndarray

(N,) array of prior probabilities.

compute_sigma(hit_samples, average_density_one_dim)[source]

Compute per-hit, per-dimension Gaussian widths (sigma).

Parameters:
hit_samplesnumpy.ndarray

(K, D) array of hit locations in sampling space.

average_density_one_dimfloat

Characteristic inter-sample spacing, typically 1 / num_explored ** (1 / D).

Returns:
numpy.ndarray

(K, D) array of sigma values.

idx(name)[source]

Get the column index for a parameter by name.

Parameters:
namestr

Parameter name.

Returns:
int

Column index in the (N, D) sample arrays.

in_bounds(samples)[source]

Check which rows of an (N, D) array are within parameter bounds.

Parameters:
samplesnumpy.ndarray

(N, D) array of samples in sampling space.

Returns:
numpy.ndarray

(N,) boolean mask where True means the sample is in bounds.

sample(n, rng=None)[source]

Draw n samples from the prior distribution.

Parameters:
nint

Number of samples to draw.

rngnumpy.random.Generator, optional

Random number generator, by default None

Returns:
samplesnumpy.ndarray

(N, D) array of samples in sampling space.

masknumpy.ndarray

(N,) boolean array indicating which samples are in bounds.

to_physical(samples)[source]

Convert an (N, D) array from sampling space to physical space.

Parameters:
samplesnumpy.ndarray

(N, D) array in sampling space.

Returns:
numpy.ndarray

(N, D) array in physical space.

to_sampling(samples)[source]

Convert an (N, D) array from physical space to sampling space.

Parameters:
samplesnumpy.ndarray

(N, D) array in physical space.

Returns:
numpy.ndarray

(N, D) array in sampling space.