uadapy.distributions.multivariate_gmm module

class uadapy.distributions.multivariate_gmm.MultivariateGMM(gmm: GaussianMixture)

Bases: object

Wrapper 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

uadapy.distributions.multivariate_gmm.gmm_from_kde(kde: gaussian_kde)

Converts a scipy gaussian_kde object to MultivariateGMM. KDE consists of gaussians at every point of the dataset it was estimated from. Each gaussian shares the same covariance matrix which makes it easy to convert to GMM.

Returns:

The mGMM equivalent to specified KDE.

Return type:

MultivariateGMM