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: 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

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.5.0.tar.gz (39.3 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.5.0-py3-none-any.whl (46.0 kB view details)

Uploaded Python 3

File details

Details for the file cgmm-0.5.0.tar.gz.

File metadata

  • Download URL: cgmm-0.5.0.tar.gz
  • Upload date:
  • Size: 39.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for cgmm-0.5.0.tar.gz
Algorithm Hash digest
SHA256 1f92e6b09a4f02a5743676cb4e45256240fa1912445bbe89b7ce55be3d3be0d1
MD5 6c57e91404f963ac8f1fc1e8e6c17873
BLAKE2b-256 74c7c9a1afa885be4e78622973180b3ea2dac8f403404026832230d8cfad217c

See more details on using hashes here.

Provenance

The following attestation bundles were made for cgmm-0.5.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.5.0-py3-none-any.whl.

File metadata

  • Download URL: cgmm-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 46.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for cgmm-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6bfbddcee57db2c48921287d8c893206df71da0ea892719933a1388848328d4d
MD5 b8bc48af851e765b55484b5aa9aac7b7
BLAKE2b-256 e9f80652ba34c08635836e4072563d670c4a2fbd167462ef401d6465b574a32f

See more details on using hashes here.

Provenance

The following attestation bundles were made for cgmm-0.5.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