Skip to content

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

3. Evaluation & Utilities

4. Bayesian Priors

5. Advanced / Nonparametric Methods

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

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 with VonMisesFisherMixture
  • 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 and impute, marginal / condition and Gaussian mixture regression, frozen_components and sample_weight, and GenericMixture with 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):

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.