uadapy.distribution module

class uadapy.distribution.Distribution(model, name='', n_dims=1)

Bases: object

The Distribution class provides a consistent interface to a variety of distributions.

model

The underlying concrete distribution model, a scipy.stats distribution object or an array of samples

name

Name of the distribution type, e.g. ‘Normal’

Type:

str

n_dims

Dimensionality of the distribution

Type:

int

cdf(x: ndarray | float) ndarray | float

Computes the cumulative density function.

Parameters:

x (np.ndarray or float) – The position where the cdf should be evaluated.

Returns:

Cumulative probability values of the distribution at the given sample points.

Return type:

np.ndarray or float

cov() ndarray | float

Covariance of the distribution.

Returns:

Covariance of the distribution.

Return type:

np.ndarray or float

kurt() ndarray | float

Kurtosis of the distribution.

Returns:

Kurtosis of the distribution.

Return type:

np.ndarray or float

marginal(dims, kde=None, n_samples_kde=1000, noise_level=0.0, seed=None)

Marginalizes the distribution retaining the specified dimensions.

Parameters:
  • dims (int or list of int or ndarray) – The dimensions to retain in the marginal distribution.

  • kde (str, optional) – If ‘KDE’ or ‘kde’, a KDE estimation of the marginal is performed. If ‘KDE?’ or ‘kde?’, a fallback to KDE is performed if the model does not have a marginal method. Default is None, and an error is raised if the model does not have a marginal method.

  • n_samples_kde (int, optional) – Number of samples to use for the marginal estimation via KDE. Default is 1000.

  • noise_level (float, optional) – Level of uniform noise to be applied to the samples before KDE estimation. Default is 0.0.

  • seed (int, optional) – Seed for the random number generator for reproducibility. Default is None.

mean() ndarray | float

Expected value of the distribution.

Returns:

Expected value of the distribution.

Return type:

np.ndarray or float

pdf(x: ndarray | float) ndarray | float

Computes the probability density function.

Parameters:

x (np.ndarray or float) – The position where the pdf should be evaluated.

Returns:

Probability values of the distribution at the given sample points.

Return type:

np.ndarray or float

sample(n: int, seed=None) ndarray

Creates samples from the distribution.

Parameters:
  • n (int) – Number of samples.

  • seed (int | rng, optional) – Seed for downstream RNG, or specific RNG to be used. Default is None.

Returns:

Samples of the distribution.

Return type:

np.ndarray

skew() ndarray | float

Skewness of the distribution.

Returns:

Skewness of the distribution.

Return type:

np.ndarray or float