Sampling

unite_toolbox.utils.sampling.get_samples(func: collections.abc.Callable, limits: list[list[float]], n_samples: int, seed: int | None = None, **kwargs: dict[str, Any]) numpy.ndarray

Get samples.

The algorithm obtains samples \(y\) from the distribution \(X\) defined in func with density \(f\), using samples from \(Y\) with density \(g\) using rejection sampling with \(Y\) being a uniform proposal distribution. In the first step samples from Y are generated. Then those samples are evaluated in \(X\) using func. We use a naive scaling value \(M\) by taking the ratio of highest sampled density in \(X\) and dividing it by the density in \(Y\) which, being a uniform distribution, is a constant. Samples are accepted only if:

\[u < \frac{f(y)}{M\,g(y)}\]

NOTE: This started as a function for Monte Carlo integration (main reason for uniform proposal distribution) and ended up being used for directly taking the samples. Therefore the implementation is not ideal.

Parameters

funcCallable

function defining a distribution to sample from

limitslist[lists[floats]]

a list of lists with contains the limits to sample from, the number of lists should match the dimensionality of func

n_samplesint

number of samples to obtain

seedint, optional

seed for random number generator

**kwargsdict[str, Any]

additional arguments for func

Returns

samplesnp.ndarray

samples of func