Native Python reimplementation of mclust (Gaussian mixture modelling for clustering, classification, and density estimation)
Project description
pymclust-native
Native Python reimplementation of the R package mclust for Gaussian mixture modelling.
Note: This project is under active development. APIs are stabilizing; expect minor changes until v0.1.
Highlights
- Models: EII, VII, EEI, VEI, EVI, VVI, EEE, VEE, EVE, VVE, EVV, EEV, VEV, VVV
- Selection: BIC and ICL (mclust-style BIC = 2loglik - mlog(n))
- Stability: configurable var_floor (diagonal floors) and full_jitter (full-cov jitter)
- Initialization: k-means with multiple restarts, deterministic seeds
- Performance: accelerated E-step via shared-orientation rotation (VEE/EVE/VVE) and per-component Cholesky caching (VVV/EVV/EEV/VEV); predict_proba uses the same fast paths
Install (editable)
- Python >= 3.9
- Dependencies: numpy, scipy
- From repo root:
- pip install -e ./pymclust-native
Quickstart
BIC selection:
from pymclust_native.api import fit_mclust
from pymclust_native.models import ModelName
import numpy as np
# synthetic 2D two-cluster data
data = np.vstack([
np.random.default_rng(0).normal([0,0], 0.3, size=(150,2)),
np.random.default_rng(1).normal([3,3], 0.4, size=(170,2)),
])
# fit VVV over G in {1,2,3} using BIC selection
res = fit_mclust(data, G_list=[1,2,3], models=[ModelName.VVV], selection_criterion="BIC")
print(res.model_name, res.means.shape, res.loglik)
# probabilities and labels
P = res.predict_proba(data)
labels = res.predict(data)
ICL selection (example):
res = fit_mclust(data, G_list=[1,2,3], models=[ModelName.VVV], selection_criterion="ICL")
Tutorials
- See dev_docs/DEVELOPMENT.md for architecture and options
- See dev_docs/API_MAPPING.md for mapping vs R mclust
- Validation and benchmarks: dev_docs/VALIDATION.md and scripts/bench
Benchmarks vs R mclust (optional)
- ARI/NMI: compare_results.py will compute ARI/NMI if the JSON results include labels or posterior for both runs (posterior is argmax'ed to labels).
- Generate small datasets
- python pymclust-native/scripts/bench/generate_reference_data.py --outdir pymclust-native/.bench_data --seeds 1 2 --sizes 300 --dims 2 3 --components 2 3
- Run Python benchmark
- python pymclust-native/scripts/bench/run_pymclust_bench.py --manifest pymclust-native/.bench_data/manifest.jsonl --out pymclust-native/.bench_results/pymclust_results.jsonl --restarts 3 --var-floor 1e-6 --full-jitter 1e-9
- Run R benchmark
- Rscript pymclust-native/scripts/bench/run_mclust_bench.R pymclust-native/.bench_data/manifest.jsonl pymclust-native/.bench_results/mclust_results.jsonl
- Compare summaries
- python pymclust-native/scripts/bench/compare_results.py --r pymclust-native/.bench_results/mclust_results.jsonl --py pymclust-native/.bench_results/pymclust_results.jsonl --out pymclust-native/.bench_results/compare_summary.jsonl
Run tests
- pytest -q pymclust-native/tests
- Optional slow regression against R: pytest -q -m "slow and mclust" pymclust-native/tests/test_regression_against_mclust.py
Backend & integration (planned)
- Backend abstraction for NumPy/PyTorch/JIT will be introduced to ease integration with data science and deep learning frameworks.
License
- Reimplementation inspired by mclust (GPL-licensed)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pymclust_native-0.0.1.tar.gz.
File metadata
- Download URL: pymclust_native-0.0.1.tar.gz
- Upload date:
- Size: 16.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
26b7d2cd3b5204f5f2043b911931c70f881c694f9b6d513f59f5f4929e668dcb
|
|
| MD5 |
41f2fae06b41385cc7d87cc56fe4b9ad
|
|
| BLAKE2b-256 |
800b396dd6216203b701bd6439c8e423647548b038c1243a50addd9b6530d638
|
File details
Details for the file pymclust_native-0.0.1-py3-none-any.whl.
File metadata
- Download URL: pymclust_native-0.0.1-py3-none-any.whl
- Upload date:
- Size: 13.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a7f5976c4919bdfde85a4a87d437aea357b720f25eb64a8af5323b00493e8b04
|
|
| MD5 |
e26b407d7a8b0143b6ee8fbc5eb5bf99
|
|
| BLAKE2b-256 |
581651acdc70564600bb29f80e7d58318a1e86068269cb3bb5991aec3b432bb7
|