Gaussian Mixture Model
A Gaussian Mixture Model (GMM) is a GPU-accelerated probabilistic clustering and density-estimation algorithm. It models a dataset as a weighted sum of n_components Gaussian components, learning a weight, mean, and covariance for each one with the Expectation-Maximization (EM) algorithm.
Use a GMM when you want soft cluster assignments (a probability that each row belongs to each component), a generative density model you can score new points against, or clusters that are elliptical rather than spherical. Unlike K-Means, which assigns every row to exactly one centroid, a GMM returns a full responsibility distribution over components and captures per-component shape through its covariance. Its primary outputs are the component weights, means, covariances (and their Cholesky-factored precisions), per-row labels, and the converged log-likelihood lower bound.
Example API Usage
Fitting a mixture
Fitting learns the component weights, means, and covariances from a dataset on the device. The covariance-shaped outputs (covariances, precisions_chol, precisions) have a layout that depends on covariance_type; see the Covariance types section below for the exact shapes.
Assigning labels and scoring
After fitting, reuse the learned weights, means, and precisions_chol to assign hard labels (predict), produce per-component responsibilities (predict_proba), or evaluate the per-row log-likelihood of new data (score_samples).
How GMM works
EM alternates between two steps until the average log-likelihood stops improving:
- E-step: given the current parameters, compute the responsibility of each component for each row — the posterior probability that the row was generated by that component.
- M-step: given the responsibilities, update each component’s weight, mean, and covariance to the responsibility-weighted statistics of the data.
The algorithm repeats until it reaches max_iter or the per-sample average log-likelihood changes by less than tol. Because both steps reduce to dense linear algebra over many rows and components, the GPU is well suited to the work.
Covariance types
covariance_type controls how much shape each component can express, trading flexibility for parameters and cost. The covariance-shaped buffers (covariances, precisions_chol, precisions) are passed as flat device vectors because their logical shape depends on the covariance type. With K = n_components and d = n_features the expected lengths are (row-major):
For full/tied, precisions_chol holds the upper-triangular factor U of each precision matrix (precision = U @ Uᵀ); for diag/spherical it holds reciprocal standard deviations. These conventions match scikit-learn’s GaussianMixture.
When to use
Use a GMM when soft, probabilistic assignments matter, when components are elliptical or have different shapes, or when you need a density model to score or compare new points. Prefer full or diag covariances when component shape is informative, and spherical or tied when data is limited or speed matters more than per-component shape. If you only need hard, roughly spherical partitions, K-Means is simpler and faster.
Configuration parameters
Tuning
Start with n_components and covariance_type. More components and richer covariances capture more structure but cost more memory and time, and can overfit when data is limited; raise reg_covar if covariances become ill-conditioned. Use kmeans initialization for robust default seeding, and increase n_init when different seeds produce noticeably different log-likelihoods. Tune max_iter and tol together: if n_iter regularly reaches max_iter, increase max_iter or relax tol.
Memory footprint
Fitting streams the E and M steps over tiles of rows, so it never materializes the full (n_samples, n_components) responsibility matrix — peak device memory stays bounded by the input data, the model parameters, and one responsibility tile, independent of n_samples. predict and score_samples likewise avoid the full responsibility matrix; only predict_proba materializes the (n_samples, n_components) output because that matrix is its result.