Mixture-Models: a one-stop Python Library for Model-based Clustering using various Mixture Models

Siva Rajesh Kasa, Yijie Hu, Santhosh Kumar Kasa, Vaibhav RajanarXiv 2024 · DOI

Abstract

Mixture-Models is an open-source Python library that leverages Automatic Differentiation (AD) to provide a flexible framework for model-based clustering. Unlike traditional implementations that rely solely on the Expectation-Maximization (EM) algorithm, this library supports a variety of gradient-based optimizers, enabling the estimation of complex mixture models even in high-dimensional scenarios where EM often fails. The library includes implementations for Gaussian Mixture Models (GMM), Parsimonious GMMs (PGMM), and Mixtures of Factor Analyzers (MFA), offering a unified API for researchers.

Introduction

Clustering high-dimensional data remains a significant challenge in statistical learning. While Gaussian Mixture Models (GMMs) are a standard approach for model-based clustering, their traditional fitting method—the Expectation-Maximization (EM) algorithm—encounters severe limitations when the number of features ($p$) approaches or exceeds the number of observations ($n$). In such cases, covariance matrices often become singular, leading to algorithmic failure unless restrictive constraints are applied. Furthermore, Python's ecosystem has lacked the specialized GMM variants available in R packages like mclust or pgmm. The Mixture-Models library addresses these gaps by providing a robust, extensible platform for advanced clustering.

The Mixture-Models Framework

The library is designed with a modular architecture that separates model definition from optimization. This allows users to experiment with different distributions and constraints without re-deriving complex update steps.

The modular workflow of the Mixture-Models library, from model initialization to analysis.

As shown in Figure 1, the workflow consists of four primary stages: initializing the model (e.g., GMM, MFA, PGMM), setting initial parameters (via K-Means or random assignment), selecting an optimizer, and finally fitting the model to analyze results like log-likelihood, AIC/BIC, and cluster labels.

Methodology: Beyond Expectation-Maximization

The core innovation of Mixture-Models is the shift from hand-coded EM updates to Gradient-Based Inference powered by Automatic Differentiation (AD). By utilizing the autograd package, the library can automatically compute gradients for any defined objective function.

Key technical features include:

  • Diverse Optimizers: Support for first-order (Gradient Descent, Adam) and second-order (Newton-CG) methods.
  • Numerical Stability: Implementation of the logsumexp trick for cluster weights and Cholesky-style decompositions to ensure covariance matrices remain positive definite.
  • Extensibility: New distributions or constraints can be added simply by defining the objective function, bypassing the need for manual mathematical derivations.

Experimental Evaluation

The library was evaluated using both synthetic and real-world datasets. Large-scale simulations varied the number of points ($n \in \{32, \dots, 512\}$), dimensions ($p \in \{2, \dots, 9\}$), and clusters ($K \in \{2, \dots, 5\}$). Additionally, the library was tested on classic benchmarks such as the Iris, Italian Wine, and Khan Gene datasets, the latter representing a typical high-dimensional challenge.

Performance Analysis

Benchmarking against standard EM implementations revealed several key insights into the efficacy of gradient-based optimization in clustering.

Comparative performance (ARI) of different optimizers across varying dimensions (p), cluster counts (K), and sample sizes (n).

As illustrated in Figure 2, gradient-based methods like Newton-CG, Adam, and Gradient Descent (GD) often outperform the EM algorithm, particularly as dimensionality ($p$) and the number of clusters ($K$) increase. While EM is efficient in low-dimensional settings, it struggles with singular matrices in high dimensions. In contrast, gradient-based methods maintain stability and often achieve higher Adjusted Rand Index (ARI) scores. However, these methods can exhibit higher variability across runs, suggesting a greater sensitivity to parameter initialization compared to the more stable but limited EM approach.

Conclusion and Future Directions

Mixture-Models provides a powerful alternative to traditional EM-based clustering tools in Python. By embracing Automatic Differentiation, it offers the flexibility to fit complex models that were previously difficult to implement. Future development aims to transition the backend to PyTorch to leverage GPU acceleration and improve integration with modern deep learning workflows. While gradient-based methods introduce new hyperparameter tuning requirements, their ability to handle high-dimensional data makes them an essential addition to the researcher's toolkit.

Summary updated

BibTeX
@misc{kasa2024mixture,
  author = {Siva Rajesh Kasa and Yijie Hu and Santhosh Kumar Kasa and Vaibhav Rajan},
  title = {{Mixture-Models: a one-stop Python Library for Model-based Clustering using various Mixture Models}},
  year = {2024},
  eprint = {2402.10229},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2402.10229},
}
Figure