Skip to main content

Conditional Gaussian Mixture Models compatible with scikit-learn

Project description

cgmm

PyPI version Documentation Status Tests codecov

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 fitted GaussianMixture, choose conditioning indices, and get a new mixture over the target block.
  • ConditionalGMMRegressor — sklearn-style regressor wrapper, exposes .predict and .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

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

cgmm-0.4.0.tar.gz (20.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cgmm-0.4.0-py3-none-any.whl (23.8 kB view details)

Uploaded Python 3

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

Hashes for cgmm-0.4.0.tar.gz
Algorithm Hash digest
SHA256 7ef5230a38e2bbdf467244cfb1fc1cdf2a26dad2abd8701c1510699bdbfad380
MD5 62625dec20e24cf3aa75b55ad0a461ac
BLAKE2b-256 903e7b5dda2b0a716637fb46df05498a0700ba33c29c02487e4da4ba5008e852

See more details on using hashes here.

Provenance

The following attestation bundles were made for cgmm-0.4.0.tar.gz:

Publisher: release.yml on sitmo/cgmm

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for cgmm-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 21abc4edd5541b69afede589b602b237e949e705bbd7fd3f112d3270a24a42ca
MD5 897894551200213dec01e2687b753096
BLAKE2b-256 0fc585488849cca02b45a75b1777c5557d89b4e90cc76d857c2805afd0a290d0

See more details on using hashes here.

Provenance

The following attestation bundles were made for cgmm-0.4.0-py3-none-any.whl:

Publisher: release.yml on sitmo/cgmm

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page