Conditional Gaussian Mixture Models compatible with scikit-learn
Project description
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
rng = np.random.default_rng(0)
X = rng.normal(size=(1000, 3))
# Fit a scikit-learn GMM on all features
gmm = GaussianMixture(n_components=3, covariance_type="full", random_state=0).fit(X)
# Condition on the first coordinate (X), predict the rest (y)
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 | X=0.5)
# Regressor interface for posterior mean
reg = ConditionalGMMRegressor(gmm, cond_idx=[0]).fit(X=np.zeros((1, 1)))
y_mean = reg.predict([[0.5]]) # E[y | X=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
Project details
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 cgmm-0.4.0.tar.gz.
File metadata
- Download URL: cgmm-0.4.0.tar.gz
- Upload date:
- Size: 20.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7ef5230a38e2bbdf467244cfb1fc1cdf2a26dad2abd8701c1510699bdbfad380
|
|
| MD5 |
62625dec20e24cf3aa75b55ad0a461ac
|
|
| BLAKE2b-256 |
903e7b5dda2b0a716637fb46df05498a0700ba33c29c02487e4da4ba5008e852
|
Provenance
The following attestation bundles were made for cgmm-0.4.0.tar.gz:
Publisher:
release.yml on sitmo/cgmm
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cgmm-0.4.0.tar.gz -
Subject digest:
7ef5230a38e2bbdf467244cfb1fc1cdf2a26dad2abd8701c1510699bdbfad380 - Sigstore transparency entry: 576830849
- Sigstore integration time:
-
Permalink:
sitmo/cgmm@5593e56642aeb0638d4f3226088dff6f4ed9be1a -
Branch / Tag:
refs/tags/v0.4.0 - Owner: https://github.com/sitmo
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@5593e56642aeb0638d4f3226088dff6f4ed9be1a -
Trigger Event:
push
-
Statement type:
File details
Details for the file cgmm-0.4.0-py3-none-any.whl.
File metadata
- Download URL: cgmm-0.4.0-py3-none-any.whl
- Upload date:
- Size: 23.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
21abc4edd5541b69afede589b602b237e949e705bbd7fd3f112d3270a24a42ca
|
|
| MD5 |
897894551200213dec01e2687b753096
|
|
| BLAKE2b-256 |
0fc585488849cca02b45a75b1777c5557d89b4e90cc76d857c2805afd0a290d0
|
Provenance
The following attestation bundles were made for cgmm-0.4.0-py3-none-any.whl:
Publisher:
release.yml on sitmo/cgmm
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cgmm-0.4.0-py3-none-any.whl -
Subject digest:
21abc4edd5541b69afede589b602b237e949e705bbd7fd3f112d3270a24a42ca - Sigstore transparency entry: 576830851
- Sigstore integration time:
-
Permalink:
sitmo/cgmm@5593e56642aeb0638d4f3226088dff6f4ed9be1a -
Branch / Tag:
refs/tags/v0.4.0 - Owner: https://github.com/sitmo
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@5593e56642aeb0638d4f3226088dff6f4ed9be1a -
Trigger Event:
push
-
Statement type: