Gaussian Mixture Regression (gmr)

raw JSON →
2.0.3 verified Fri May 01 auth: no python

Gaussian Mixture Regression (GMR) for learning and inferring multivariate probability distributions from data. Version 2.0.3 supports Python >=3.7, NumPy 2 compatibility, and sklearn-compatible GaussianMixtureRegressor. Low release cadence (last release 2024-06-03).

pip install gmr
error AttributeError: module 'gmr' has no attribute 'GMM'
cause Incorrect import path (tried `from gmr import GMM` but installed old version <1.6 or import shadowed by file named gmr.py).
fix
Install gmr>=1.6 (pip install gmr==2.0.3) and ensure no local file named gmr.py.
error ValueError: operands could not be broadcast together with shapes ...
cause Condition indices or values vector length mismatch with data dimensions.
fix
Verify that condition indices are within range [0, n_features-1] and values length equals len(indices).
error LinAlgError: Singular matrix
cause Covariance matrix became singular due to duplicate data points or insufficient samples per component.
fix
Increase n_components, add noise to data, or set random_state to a different seed.
breaking `GMM.condition` now returns an `MVN` object (not tuple of mean/covariance). Code assuming tuple will break.
fix Access `.mean` and `.covariance` attributes on the returned MVN.
breaking Probability density scaling fixed in v2.0.0; marginal densities may differ from v1.x by factor that ensures integration to 1.
fix If you relied on original scaling, normalize outputs or use v1.6.1.
gotcha `GMM.from_samples` does not check if the data has sufficient rank; singular covariance matrices cause runtime errors unless using oracle approximating shrinkage (enabled by default).
fix Use `oracle_approximating_shrinkage=True` (default) or regularize via `GMM.priors`. See docstring.
deprecated Python 2.7 support ended silently; no compatibility guarantees for Python 2.
fix Upgrade to Python >=3.7 and gmr >=2.0.0.

Basic usage: create GMM, fit data, condition on a slice.

import numpy as np
from gmr import GMM, MVN

# Create a simple GMM with 2 components random init
random_state = np.random.RandomState(0)
gmm = GMM(n_components=2, random_state=random_state)
X = np.random.randn(100, 3)
gmm.from_samples(X)

# Condition on first dimension
mvn_conditional = gmm.condition(np.array([0.5]), [0])
print("Conditional mean:", mvn_conditional.mean)