ngclearn.utils.density package
Submodules
ngclearn.utils.density.bernoulliMixture module
- class ngclearn.utils.density.bernoulliMixture.BernoulliMixture(K, max_iter=50, init_kmeans=False, key=None, **kwargs)[source]
Bases:
MixtureImplements a Bernoulli mixture model (BMM) – or mixture of Bernoullis (MoB). Adaptation of parameters is conducted via the Expectation-Maximization (EM) learning algorithm. Note that this Bernoulli mixture assumes that each component is a factorizable mutlivariate Bernoulli distribution. (A Categorical distribution is assumed over the latent variables).
- Parameters:
K – the number of components/latent variables within this BMM
max_iter – the maximum number of EM iterations to fit parameters to data (Default = 50)
init_kmeans – <Unsupported>
- calc_log_likelihood(X)[source]
Calculates the multivariate Bernoulli log likelihood of a design matrix/dataset X, under the current parameters of this Bernoulli mixture.
- Parameters:
X – the design matrix to estimate log likelihood values over under this BMM
- Returns:
(column) vector of individual log likelihoods, scalar for the complete log likelihood p(X)
- fit(X, tol=0.001, verbose=False)[source]
Run full fitting process of this BMM.
- Parameters:
X – the dataset to fit this BMM to
tol – the tolerance value for detecting convergence (via difference-of-means); will engage in early-stopping if tol >= 0. (Default: 1e-3)
verbose – if True, this function will print out per-iteration measurements to I/O
- init(X)[source]
Initializes this BMM in accordance to a supplied design matrix.
- Parameters:
X – the design matrix to initialize this BMM to
- sample(n_samples, mode_j=-1)[source]
Draw samples from the current underlying BMM model
- Parameters:
n_samples – the number of samples to draw from this BMM
mode_j – if >= 0, will only draw samples from a specific component of this BMM (Default = -1), ignoring the Categorical prior over latent variables/components
- Returns:
Design matrix of samples drawn under the distribution defined by this BMM
ngclearn.utils.density.exponentialMixture module
- class ngclearn.utils.density.exponentialMixture.ExponentialMixture(K, max_iter=50, init_kmeans=False, key=None, **kwargs)[source]
Bases:
MixtureImplements an exponential mixture model (EMM) – or mixture of exponentials (MoExp). Adaptation of parameters is conducted via the Expectation-Maximization (EM) learning algorithm. Note that this exponential mixture assumes that each component is a factorizable mutlivariate exponential distribution. (A Categorical distribution is assumed over the latent variables).
The exponential distribution of each component (dimension d) is assumed to be:
pdf(x_d; lmbda_d) = lmbda_d * exp(-lmbda_d x_d) for x >= 0, else 0 for x < 0;where lbmda is the rate parameter vector- Parameters:
K – the number of components/latent variables within this EMM
max_iter – the maximum number of EM iterations to fit parameters to data (Default = 50)
init_kmeans – <Unsupported>
- calc_log_likelihood(X)[source]
Calculates the multivariate exponential log likelihood of a design matrix/dataset X, under the current parameters of this exponential mixture.
- Parameters:
X – the design matrix to estimate log likelihood values over under this EMM
- Returns:
(column) vector of individual log likelihoods, scalar for the complete log likelihood p(X)
- fit(X, tol=0.001, verbose=False)[source]
Run full fitting process of this EMM.
- Parameters:
X – the dataset to fit this EMM to
tol – the tolerance value for detecting convergence (via difference-of-means); will engage in early-stopping if tol >= 0. (Default: 1e-3)
verbose – if True, this function will print out per-iteration measurements to I/O
- init(X)[source]
Initializes this EMM in accordance to a supplied design matrix.
- Parameters:
X – the design matrix to initialize this EMM to
- sample(n_samples, mode_j=-1)[source]
Draw samples from the current underlying EMM model
- Parameters:
n_samples – the number of samples to draw from this EMM
mode_j – if >= 0, will only draw samples from a specific component of this EMM (Default = -1), ignoring the Categorical prior over latent variables/components
- Returns:
Design matrix of samples drawn under the distribution defined by this EMM
ngclearn.utils.density.gaussianMixture module
- class ngclearn.utils.density.gaussianMixture.GaussianMixture(K, max_iter=50, assume_diag_cov=False, init_kmeans=False, key=None, **kwargs)[source]
Bases:
MixtureImplements a 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. (A Categorical distribution is assumed over the latent variables).
- 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 = 50)
assume_diag_cov – if True, assumes a diagonal covariance for each component (Default = False)
init_kmeans – <Unsupported>
- calc_log_likelihood(X)[source]
Calculates the multivariate Gaussian log likelihood of a design matrix/dataset X, under the current parameters of this Gaussian mixture model.
- Parameters:
X – the design matrix to estimate log likelihood values over under this GMM
- Returns:
(column) vector of individual log likelihoods, scalar for the complete log likelihood p(X)
- fit(X, tol=0.001, verbose=False)[source]
Run full fitting process of this GMM.
- Parameters:
X – the dataset to fit this GMM to
tol – the tolerance value for detecting convergence (via difference-of-means); will engage in early-stopping if tol >= 0. (Default: 1e-3)
verbose – if True, this function will print out per-iteration measurements to I/O
- init(X)[source]
Initializes this GMM in accordance to a supplied design matrix.
- Parameters:
X – the design matrix to initialize this GMM to
- sample(n_samples, mode_j=-1)[source]
Draw samples from the current underlying GMM model
- Parameters:
n_samples – the number of samples to draw from this GMM
mode_j – if >= 0, will only draw samples from a specific component of this GMM (Default = -1), ignoring the Categorical prior over latent variables/components
- Returns:
Design matrix of samples drawn under the distribution defined by this GMM
ngclearn.utils.density.mixture module
- class ngclearn.utils.density.mixture.Mixture(K, max_iter=50, **kwargs)[source]
Bases:
objectImplements a general mixture model template/structure. Effectively, this is the parent class/template for mixtures of distributions.
- Parameters:
K – the number of components/latent variables within this mixture model
max_iter – the maximum number of iterations to fit parameters to data (Default = 50)