uadapy.distributions package
Submodules
Module contents
- class uadapy.distributions.ChiSquareComb(mean: ndarray, cov: ndarray, pseudo_cov: ndarray)
Bases:
objectThe ChiSquareComb class provides a consistent interface to a combination of chi-square distribution.
Currently, we only support the distribution created by summing up two squares of complex normal distributions.
- mu_complex
The complex mean of the distribution before squaring
- Type:
np.ndarray
- covariance
The complex covariance matrix of the distribution before squaring
- Type:
np.ndarray
- pseudo_covariance
The complex pseudo-covariance matrix of the distribution before squaring
- Type:
np.ndarray
- mu_real
The mean of the distribution where the first half corresponds to the real part and the second half to the imaginary part
- Type:
np.ndarray
- self.cov_real
The covariance matrix of the distribution where the first half corresponds to the real part and the second half to the imaginary part, it also contains the cross-correlation terms
- Type:
np.ndarray
- cov() ndarray
Returns the covariance matrix of the distribution.
- Returns:
The covariance matrix of the distribution
- Return type:
np.ndarray
- mean() ndarray
Returns the mean of the distribution.
- Returns:
The mean of the distribution
- Return type:
np.ndarray
- resample(size: int, seed: int = 0) ndarray
Resamples the distribution.
- Parameters:
size (int) – The number of samples to be drawn
seed (int, optional) – The seed for the random number generator, default is 0
- Returns:
The samples
- Return type:
np.ndarray
- class uadapy.distributions.DiracDelta(mean, tol=0.0)
Bases:
objectDirac Delta distribution class. To actually be able to work with this distribution, a very small tolerance can be specified and the distribution will then mimick a tiny uniform distribution. This class is intended to be used when a variable has no uncertainty but the input needs to be specified in terms of a distribution.
- mean
The mean of the distribution (the location of the peak).
- Type:
float
- tol
The tolerance for the distribution. If tol is 0, the distribution is a true Dirac Delta. If tol > 0, the distribution is a uniform distribution centered at mean with width tol.
- Type:
float
- cdf(x, tol=None)
Computes the cumulative distribution function of the distribution at the given points x.
- Parameters:
x (array-like, shape (n_samples,) or scalar) – Points at which to evaluate the CDF.
tol (float, optional) – The tolerance for the distribution. If tol is None, the tolerance specified in the constructor is used. Default is None. When tol is 0, the CDF is 0 for x < mean and 1 for x >= mean. When tol > 0, the CDF is that of the corresponding uniform distribution.
- pdf(x, tol=None)
Computes the probability density function of the Dirac Delta distribution at the given points x.
- Parameters:
x (array-like, shape (n_samples,) or scalar) – Points at which to evaluate the PDF.
tol (float, optional) – The tolerance for the distribution. If tol is None, the tolerance specified in the constructor is used. Default is None. When tol is 0, the PDF is infinite at the mean and 0 elsewhere. When tol > 0, the PDF is uniform.
- Returns:
pdfs – Probability density values at the given points x.
- Return type:
ndarray or scalar
- sample(n, seed=None, tol=None)
Draws n samples from the Dirac Delta distribution. If tol is None, the tolerance specified in the constructor is used. If tol is 0, all samples will be equal to the mean.
- Parameters:
n (int) – Number of samples to draw.
seed (int or np.random.Generator, optional) – Random seed or random number generator for reproducibility. Default is None.
tol (float, optional) – The tolerance for the distribution. If tol is 0, all samples will be equal to the mean. Default is None.
- Returns:
samples – The drawn samples from the distribution.
- Return type:
ndarray, shape (n,)
- var()
Returns the variance of the distribution.
- Returns:
variance – The variance of the distribution. For a true Dirac Delta (tol=0), the variance is 0. For a uniform distribution (tol>0), the variance is (tol^2)/12.
- Return type:
float
- class uadapy.distributions.IndependentJoint(distributions, permutation=None)
Bases:
objectJoint Distribution of independent continuous distributions. This class allows to combine multiple independent distributions into a single multivariate joint distribution. Univariate as well as multivariate distributions can be joined. The resulting joint distribution will have a dimensionality equal to the sum of the dimensionalities of the individual distributions.
Example usage:
import scipy.stats as stats from uadapy.distributions import IndependentJoint a = stats.norm() b = stats.t(5) j = IndependentJoint([a, b])
- cov()
Builds the covariance matrix of the joint distribution.
- Returns:
cov – Covariance matrix of the joint distribution.
- Return type:
ndarray, shape (dim, dim)
- marginal(dims)
Extracts the marginal distribution for the specified dimensions.
- Parameters:
dims (array-like of int or int) – Dimensions for which to extract the marginal distribution. Can be a single dimension or a list of dimensions.
- Returns:
marginal – Marginal distribution for the specified dimensions. If the marginal consists only of a single original distribution object, that object is returned. If the marginal consists of multiple distributions, a new IndependentJoint object is returned.
- Return type:
underlying distribution object or IndependentJoint
- mean()
Builds the mean of the joint distribution.
- Returns:
mean – Mean of the joint distribution.
- Return type:
ndarray, shape (dim,)
- pdf(x)
Computes the probability density function of the joint distribution at the given points x.
- sample(n, seed=None)
Draws n samples from the joint distribution.
- Parameters:
n (int) – Number of samples to draw.
seed (int or np.random.Generator, optional) – Random seed or random number generator for reproducibility. Default is None.
- Returns:
samples – Samples drawn from the joint distribution.
- Return type:
ndarray, shape (n, dim)
- class uadapy.distributions.MultivariateGMM(gmm: GaussianMixture)
Bases:
objectWrapper around sklearn’s GaussianMixture providing a consistent interface for use with the Distribution class.
This class supports all sklearn covariance types of sklearn’s GaussianMixture. Covariances are always converted to full format if necessary for consistent handling.
- Parameters:
gmm (GaussianMixture) – A fitted sklearn GaussianMixture model.
- gmm
The underlying fitted GaussianMixture model.
- Type:
GaussianMixture
- n_components
Number of mixture components.
- Type:
int
- n_dims
Dimensionality of the distribution.
- Type:
int
- covariance_type
Type of covariance parameters: “full”, “tied”, “diag”, or “spherical”.
- Type:
str
- means_
Means of each mixture component, shape (n_components, n_dims).
- Type:
np.ndarray
- covariances_
Covariances of each mixture component in “full” format, shape (n_components, n_dims, n_dims).
- Type:
np.ndarray
- weights_
Weights of each mixture component, shape (n_components,).
- Type:
np.ndarray
- cov() ndarray
Compute the overall covariance of the Gaussian Mixture Model.
- Returns:
Overall covariance matrix.
- Return type:
np.ndarray
- marginal(dimensions)
Computes the marginal distribution over specified dimensions.
- Parameters:
dimensions (list of int or int) – Indices of the dimensions to keep.
- Returns:
A new MultivariateGMM representing the marginal distribution. In case of a single dimension, returns a univariate scipy.stats.Mixture of Normals.
- Return type:
MultivariateGMM or Mixture
- mean() ndarray
Compute the overall mean of the Gaussian Mixture Model.
- Returns:
Overall mean vector.
- Return type:
np.ndarray
- pdf(x: ndarray) ndarray | float
Computes the probability density function.
- Parameters:
x (np.ndarray or float) – The position(s) where the pdf should be evaluated.
- Returns:
Probability values of the distribution at the given sample point(s).
- Return type:
np.ndarray or float
- sample(n: int, seed: int = None) ndarray
Creates samples from the Gaussian Mixture Model.
- Parameters:
n (int) – Number of samples.
seed (int, optional) – Seed for the random number generator for reproducibility, default is None.
- Returns:
Samples of the Gaussian Mixture Model.
- Return type:
np.ndarray