Mirrors the C# GaussianMixtureModel class: fits a mixture of k multivariate normals by
expectation-maximization, initialized from a k-means fit. It generalizes ml_kmeans() by
carrying a full covariance per component rather than only a centre.
Usage
ml_gaussian_mixture(
x,
k,
seed = NULL,
kmeans_plus_plus = TRUE,
max_iterations = 1000,
tolerance = 1e-08
)Arguments
- x
a numeric matrix or data frame with one row per observation, or a numeric vector.
- k
the number of mixture components.
- seed
integer PRNG seed;
NULL(the default) uses the computer clock.- kmeans_plus_plus
use k-means++ initialization for the starting fit. Default
TRUE.- max_iterations
the EM iteration cap. Default 1000.
- tolerance
the relative convergence tolerance on the log-likelihood. Default 1e-8.
Value
a list with means (k by ncol(x)), sigmas (a length-k list of
ncol(x) by ncol(x) covariance matrices), weights, labels (0-based),
log_likelihood, and iterations.
Details
labels are 0-BASED, as in ml_kmeans(). log_likelihood is the full normalized mixture log
likelihood from the latest expectation step, including when the fit reaches max_iterations.