GMMX: Gaussian Mixture Models in Jax
A minimal implementation of Gaussian Mixture Models in Jax
- Github repository: https://github.com/adonath/gmmx/
- Documentation https://adonath.github.io/gmmx/
Installation
gmmx can be installed via pip:
pip install gmmx
Or alternatively you can use conda/mamba:
conda install gmmx
Usage
from gmmx import GaussianMixtureModelJax, EMFitter
# Create a Gaussian Mixture Model with 16 components and 32 features
gmm = GaussianMixtureModelJax.create(n_components=16, n_features=32)
# Draw samples from the model
n_samples = 10_000
x = gmm.sample(n_samples)
# Fit the model to the data
em_fitter = EMFitter(tol=1e-3, max_iter=100)
gmm_fitted = em_fitter.fit(x=x, gmm=gmm)
If you use the code in a scientific publication, please cite the Zenodo DOI from the badge above.
Why Gaussian Mixture models?
What are Gaussian Mixture Models (GMM) useful for in the age of deep learning? GMMs might have come out of fashion for classification tasks, but they still have a few properties that make them useful in certain scenarios:
- They are universal approximators, meaning that given enough components they can approximate any distribution.
- Their likelihood can be evaluated in closed form, which makes them useful for generative modeling.
- They are rather fast to train and evaluate.
I would strongly recommend to read In Depth: Gaussian Mixture Models from the Python Data Science Handbook for a more in-depth introduction to GMMs and their application as density estimators.
One of these applications in my research is the context of image reconstruction, where GMMs can be used to model the distribution and pixel correlations of local (patch based)
image features. This can be useful for tasks like image denoising or inpainting. One of these methods I have used them for is Jolideco.
Speed up the training of O(10^6) patches was the main motivation for gmmx.
Benchmarks
Here are some results from the benchmarks in the examples/benchmarks folder comparing against Scikit-Learn. The benchmarks were run on an "Intel(R) Xeon(R) Gold 6338" CPU and a single "NVIDIA L40S" GPU.
Prediction Time
| Time vs. Number of Components | Time vs. Number of Samples | Time vs. Number of Features |
|---|---|---|
For prediction the speedup is around 5-6x for varying number of components and features and ~50x speedup on the GPU. For the number of samples the cross-over point is around O(10^3) samples.
Training Time
| Time vs. Number of Components | Time vs. Number of Samples | Time vs. Number of Features |
|---|---|---|
For training the speedup is around ~5-6x on the same architecture and ~50x speedup on the GPU. In the bechmark I have forced both fitters to evaluate exactly the same number of iterations. However in general there is no guarantee that GMMX converges to the same solution as Scikit-Learn. But there are some tests in the tests folder that compare the results of the two implementations which shows good agreement.
Metadata
Release files for gmmx 0.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| gmmx-0.7.tar.gz | 16.8 kB | Without provenance | Details for gmmx-0.7.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| gmmx-0.7-py3-none-any.whl | Python 3 | none | any | Details for gmmx-0.7-py3-none-any.whl |
Total release size: 29.9 kB
Release files / gmmx-0.7.tar.gz
| Download URL | gmmx-0.7.tar.gz |
|---|---|
| Size | 16.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4bf8274419cd84727155a043f2bf53307b30aff31c9d4dc51b5b41b65d7bec4d
|
|
BLAKE2b-256 checksum How to use checksums |
8e6b6023c93fe6b065bc1a397ec891f32557b7cd193dccce8431251188b89ce0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.11
|
Release files / gmmx-0.7-py3-none-any.whl
| Download URL | gmmx-0.7-py3-none-any.whl |
|---|---|
| Size | 13.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
222a2947ac3bc2f8139e261919792f642b19e615ee13e512c703fc57ba92ad70
|
|
BLAKE2b-256 checksum How to use checksums |
cb445a76e0baefa5dd504ae60f6ec0803625f5c07427b65d4782dec2d294ef9e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.11
|
Security for gmmx 0.7
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.