ngclearn.density package¶
Submodules¶
ngclearn.density.gmm module¶
- class ngclearn.density.gmm.GMM(k, max_iter=5, assume_diag_cov=False, init_kmeans=True)[source]¶
Bases:
object
Implements a custom/pure-TF Gaussian mixture model (GMM) – or mixture of Gaussians, MoG. Adaptation of parameters is conducted via the Expectation-Maximization (EM) learning algorithm and leverages full covariance matrices in the component multivariate Gaussians.
Note this is a TF wrapper model that houses the sklearn implementation for learning. The sampling process has been rewritten to utilize GPU matrix computation.
- Parameters
k – the number of components/latent variables within this GMM
max_iter – the maximum number of EM iterations to fit parameters to data (Default = 5)
assume_diag_cov – if True, assumes a diagonal covariance for each component (Default = False)
init_kmeans – if True, first learn use the K-Means algorithm to initialize the component Gaussians of this GMM (Default = True)
- calc_gaussian_logpdf(X)[source]¶
Calculates log densities/probabilities of data X under each component given this GMM
- Parameters
X – the dataset to calculate the log likelihoods from
- calc_prob(X)[source]¶
Computes probabilities p(z|x) of data samples in X under this GMM
- Parameters
X – the dataset to estimate the probabilities from
- calc_w_log_prob(X)[source]¶
Calculates weighted log probabilities of data X under each component given this GMM
- Parameters
X – the dataset to calculate the weighted log probabilities from
- init_from_ScikitLearn(gmm)[source]¶
Creates a GMM from a pre-trained Scikit-Learn model – conversion sets things up for a row-major form of sampling, i.e., s ~ mu_k + eps * (L_k^T) where k is the sampled component index
- Parameters
gmm – the pre-trained GMM (from scikit-learn) to load in
- predict(X)[source]¶
Chooses which component samples in X are likely to belong to given p(z|x)
- Parameters
X – the input data to compute p(z|x) from
- sample(n_s, mode_i=- 1, samples_modes_evenly=False)[source]¶
(Efficiently) Draw samples from the current underlying GMM model
- Parameters
n_s – the number of samples to draw from this GMM
mode_i – if >= 0, will only draw samples from a specific component of this GMM (Default = -1), ignoring the Categorical prior over latent variables/components
samples_modes_evenly – if True, will ignore the Categorical prior over latent variables/components and draw an approximately equal number of samples from each component