cgmm
cgmm provides Conditional Gaussian Mixture Models that are fully compatible with scikit-learn.
It lets you fit a standard GaussianMixture on your data, then condition on a subset of variables
to obtain the posterior distribution of the remaining ones.
Typical applications:
- Multimodal regression (
E[y | X=x]and predictive bands) - Scenario simulation and stochastic forecasting
- Imputation of missing values
- Inverse problems (e.g. kinematics, finance, volatility)
Features
GMMConditioner- take a fittedGaussianMixture, choose conditioning indices, and get a new mixture over the target block.ConditionalGMMRegressor- sklearn-style regressor wrapper, exposes.predictand.predict_cov.- Compatible with scikit-learn pipelines & tools.
- Support for multi-modal posteriors (mixtures, not just means).
- Well-tested, BSD-3 licensed.
Installation
pip install cgmm
Quick Start
import numpy as np
from sklearn.mixture import GaussianMixture
from cgmm import GMMConditioner, ConditionalGMMRegressor
# Example data: 3 correlated features
rng = np.random.default_rng(0)
X = rng.normal(size=(1000, 3))
# --- Low-level: condition a fitted scikit-learn GaussianMixture ---
gmm = GaussianMixture(n_components=3, covariance_type="full", random_state=0).fit(X)
# Condition on the first coordinate; get a mixture over the remaining two
cond = GMMConditioner(gmm, cond_idx=[0]).precompute()
gmmy = cond.condition([0.5]) # returns a GaussianMixture over y
samples = gmmy.sample(5)[0] # sample from p(y | X0=0.5)
# --- Regressor: learns its own joint GMM over [features, targets] ---
feats, target = X[:, :1], X[:, 1:] # predict dims 1,2 from dim 0
reg = ConditionalGMMRegressor(n_components=3, random_state=0).fit(feats, target)
y_mean = reg.predict([[0.5]]) # E[y | X0=0.5]
Examples
- 2D conditional demo: scatter + contours + conditional slice.
https://cgmm.readthedocs.io/en/latest/examples/conditional_2d_gmm.html - VIX scenario generation: model daily log-VIX changes and simulate stochastic futures.
https://cgmm.readthedocs.io/en/latest/examples/vix_predictor.html
See the documentation for full tutorials: https://cgmm.readthedocs.io/
Documentation
Full documentation is hosted on Read the Docs: https://cgmm.readthedocs.io/
Includes:
- API reference
- Tutorials and examples
- Background on conditional GMMs
Contributing
Contributions are welcome! Typical workflow:
git clone https://github.com/your-org/cgmm.git
cd cgmm
poetry install -E docs --with dev
pre-commit install
- Format & lint:
make precommit - Build docs locally:
make docs - Bump version:
make bump-patch(or minor/major) - Push tags → GitHub Actions → PyPI release
Please open issues or pull requests on GitHub.
License
BSD-3-Clause License © 2025 Thijs van den Berg
Metadata
Release files for cgmm 0.5.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| cgmm-0.5.1.tar.gz | 39.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| cgmm-0.5.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 85.9 kB
Release files / cgmm-0.5.1.tar.gz
| Download URL | cgmm-0.5.1.tar.gz |
|---|---|
| Size | 39.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
02e6bb4b9e7821c3f725644e62a75b09d3b73737c7918c17dfa295b6f2459a3a
|
|
BLAKE2b-256 checksum How to use checksums |
58843fffd566492cf8514b3a29714ceeacbb28edc52ff524993bc9c0a9ec749c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 23, 2026.
Transparency logRelease files / cgmm-0.5.1-py3-none-any.whl
| Download URL | cgmm-0.5.1-py3-none-any.whl |
|---|---|
| Size | 46.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b45ef74cb16c5628a5151029d55f9343cbe0a6482a4b80c9af61b5732afb9dae
|
|
BLAKE2b-256 checksum How to use checksums |
cf98cd1539ec4221b76f2d7b075bfd7a488a3e4a1c436826b4462dfecd8acc5e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 23, 2026.
Transparency log