Tutorials¶
Interactive Jupyter notebook tutorials demonstrating various features of tgmm, numbered in the suggested reading order.
1. Foundations¶
- 1. Gaussian Mixture Models (GMM) - Basic introduction to fitting GMMs with tgmm: initialization strategies (means, weights, covariances), training controls (
n_init,warm_start, ...), MAP priors, constrained sampling and save/load. How the covariance structure is chosen and estimated now has its own tutorial, 15. Covariance Structures - 2. EM Algorithm Walkthrough - Step-by-step visualization of how the EM algorithm updates responsibilities and parameters each iteration
- 3. Visualization Techniques - Comprehensive guide to
plot_gmm, the toolkit every later tutorial uses
2. Fitting Variants¶
- 4. Classification EM (CEM) - Comparing the hard-assignment CEM algorithm against standard EM
- 5. Supervised Fitting - Comparing EM, CEM, and label-supervised fitting on the same synthetic data
3. Evaluation & Utilities¶
- 6. Clustering Metrics - Evaluating GMM performance with various metrics
- 7. Sampling from GMMs - Generating synthetic data from fitted models
- 8. PCA Plotting - Visualizing high-dimensional GMM results with PCA
4. Bayesian Priors¶
- 9. Prior Distributions - Using priors for regularization and MAP estimation
- 10. NIW Priors Comparison - Detailed comparison of Normal-Inverse-Wishart priors
5. Advanced / Nonparametric Methods¶
- 11. Dirichlet Process Mixtures: Stick-Breaking and Gibbs Sampling - The math (stick-breaking, Chinese Restaurant Process), a step-by-step sampler walkthrough, then validating
GaussianMixture(n_components=None, ...)against classical EM at scale - 12. HDBSCAN Clustering - Density-based clustering with a PyTorch HDBSCAN implementation, including using it to remove noise before fitting a GMM
6. Model Selection and Algorithms¶
- 13. Model Selection (BIC, AIC, ICL) - Choosing the number of components and the covariance structure with
select_model, and how the three criteria differ on overlapping clusters - 14. Stochastic EM, Annealing & SAEM - Escaping poor local optima: SEM, deterministic annealing (DAEM) and SAEM compared against EM and CEM from the same bad initialization
7. Covariance Structures¶
- 15. Covariance Structures: the 6 classic types and the 14 GPCM models - What each covariance type assumes, how its parameters are estimated in the M-step (the equations), the Celeux & Govaert volume/shape/orientation decomposition behind the 14 mclust models, and model selection among all 14
8. Other Families and Supervision¶
- 16. Student-t Mixtures - Heavy-tailed components, the scale-mixture view and robustness weights \(u_{ik}\), and resisting contamination with
StudentTMixture - 17. Von Mises-Fisher Mixtures - Directional data: the vMF distribution on the circle and sphere, the EM updates for \(\mu_k\) and \(\kappa_k\),
plot_vmf/plot_vmf_cosine, and clustering unit-norm embeddings withVonMisesFisherMixture - 18. Semi-Supervised and Positive-Unlabeled Fitting - Fitting with partially known labels and
PositiveUnlabeledMixture
9. Around the Fit¶
- 19. Noise, Missing Values and Conditioning - A uniform noise component (
noise=True), EM with missing values andimpute,marginal/conditionand Gaussian mixture regression,frozen_componentsandsample_weight, andGenericMixturewith your own component classes
Interactive explainers¶
Five short pages teach the ideas behind tgmm with sliders and buttons that run in your browser (no install, no tgmm or PyTorch involved):
- GPCM Covariance Shapes -- volume, shape and orientation, and the mclust code they spell
- EM Step by Step -- the E- and M-steps of EM, CEM and SEM on a 1-D mixture
- Deterministic Annealing -- how a temperature escapes a collapsed initialization
- Clustering Metrics and Model Selection -- internal indices, BIC and ICL live
- Design Your Own Mixture -- move and reshape Gaussian blobs, choose how many points each has, and watch EM and BIC respond
Running Tutorials¶
The tutorials are marimo notebooks (notebooks/NN_name.py), published here as static
pages. Each page has an Open in molab badge at the top that runs the real notebook, PyTorch included, on a
free hosted server (no setup; the full-size runs, not the shortened ones used to build this site).
Locally¶
git clone https://github.com/adriansousapoza/tgmm.git && cd tgmm
pip install -e . marimo
marimo edit notebooks/01_gmm.py # interactive editor
python notebooks/01_gmm.py # or run it as a plain script
Or, without installing anything yourself, in an isolated environment built from the notebook's own header:
uvx marimo edit --sandbox notebooks/01_gmm.py. See notebooks/README.md for the conventions every notebook follows.
Requirements¶
All tutorials require:
pip install torch numpy scipy matplotlib seaborn tqdm
pip install tgmm # or, from a source checkout: pip install -e .
Some tutorials additionally use scikit-learn (datasets, PCA), pandas (select_model(...).to_dataframe()) or mpltern; see Installation. The notebooks declare all of their dependencies in a header, so marimo edit --sandbox installs them for you.