pyriemann.clustering.GaussianMixture¶
- class pyriemann.clustering.GaussianMixture(n_components=1, metric='riemann', weights_init=None, means_init=None, tol=1e-05, maxiter=100, random_state=None, verbose=False)[source]¶
Gaussian mixture model.
Representation of a Gaussian mixture model (GMM) probability distribution for SPD matrices by expectation-maximization (EM) algorithm [1].
- Parameters:
- n_componentsinteger, default=1
Number of mixture components.
- metricstring | dict, default=”riemann”
Metric used for mean update (for the list of supported metrics, see
pyriemann.geometry.mean.gmean()) and for tangent space map (seepyriemann.geometry.tangent_space.tangent_space()). The metric can be a dict with two keys, “mean” and “map” in order to pass different metrics.- weights_initNone | ndarray, shape (n_components,), defaut=None
Initial weights. If None, it uses equal weights.
- means_initNone | ndarray, shape (n_components,), defaut=None
Initial means of Gaussians. If None, it randomly selects training matrices.
- tolfloat, default=1e-5
Tolerance to stop the EM algorithm.
- maxiterint, default=100
Maximum number of iterations of EM algorithm.
- random_stateNone | integer | np.RandomState, default=None
The generator used to initialize the Gaussian models. If an integer is given, it fixes the seed. Defaults to the global numpy random number generator.
- verbosebool, default=False
Verbose flag.
- Attributes:
- weights_ndarray, shape (n_components,)
Weight of each mixture component.
- means_ndarray, shape (n_components, n_channels, n_channels)
Mean of each mixture component.
- covariances_ndarray, shape (n_components, n_ts, n_ts)
Covariance of each mixture component.
Notes
Added in version 0.11.
References
[1]Gaussian mixture regression on symmetric positive definite matrices manifolds: Application to wrist motion estimation with sEMG N. Jacquier & S. Calinon. IEEE IROS, 2017
- __init__(n_components=1, metric='riemann', weights_init=None, means_init=None, tol=1e-05, maxiter=100, random_state=None, verbose=False)[source]¶
Init.
- fit(X, y=None)[source]¶
Fit the mixture with EM.
- Parameters:
- Xndarray, shape (n_matrices, n_channels, n_channels)
Set of SPD matrices.
- yNone
Not used, here for compatibility with sklearn API.
- Returns:
- selfGaussianMixture instance
The GaussianMixture instance.
- fit_predict(X, y=None)¶
Fit and predict in a single function.
- Parameters:
- Xndarray, shape (n_matrices, n_channels, n_channels)
Set of SPD matrices.
- yNone
Not used, here for compatibility with sklearn API.
- Returns:
- predndarray of int, shape (n_matrices,)
Prediction for each matrix according to the closest cluster.
- get_metadata_routing()¶
Get metadata routing of this object.
Please check User Guide on how the routing mechanism works.
- Returns:
- routingMetadataRequest
A
MetadataRequestencapsulating routing information.
- get_params(deep=True)¶
Get parameters for this estimator.
- Parameters:
- deepbool, default=True
If True, will return the parameters for this estimator and contained subobjects that are estimators.
- Returns:
- paramsdict
Parameter names mapped to their values.
- predict(X)[source]¶
Get the predictions.
- Parameters:
- Xndarray, shape (n_matrices, n_channels, n_channels)
Set of SPD matrices.
- Returns:
- predndarray of int, shape (n_matrices,)
Predictions for each matrix.
- predict_proba(X)[source]¶
Predict probabilities.
- Parameters:
- Xndarray, shape (n_matrices, n_channels, n_channels)
Set of SPD matrices.
- Returns:
- probndarray, shape (n_matrices, n_components)
Probabilities for each component.
- sample(n_matrices=1)[source]¶
Generate random matrices from the fitted Gaussian distribution.
Warning: GMM is calibrated using the Gaussian model [1], while this sampling uses the wrapped Gaussian model [2].
- Parameters:
- n_matricesint, default=1
Number of matrices to generate.
- Returns:
- Xarray, shape (n_matrices, n_channels, n_channels)
Randomly generated matrices.
- yarray, shape (n_matrices,)
Component labels.
References
[1]Intrinsic statistics on Riemannian manifolds: Basic tools for geometric measurements X. Pennec. Journal of Mathematical Imaging and Vision, 2006
[2]Wrapped gaussian on the manifold of symmetric positive definite matrices T. de Surrel, F. Lotte, S. Chevallier, and F. Yger. ICML, 2025
- score(X, y=None)[source]¶
Compute the average log-likelihood of the given matrices.
- Parameters:
- Xndarray, shape (n_matrices, n_channels, n_channels)
Set of SPD matrices.
- yNone
Not used, here for compatibility with sklearn API.
- Returns:
- scorefloat
Log-likelihood of matrices under the Gaussian mixture model.
- set_params(**params)¶
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as
Pipeline). The latter have parameters of the form<component>__<parameter>so that it’s possible to update each component of a nested object.- Parameters:
- **paramsdict
Estimator parameters.
- Returns:
- selfestimator instance
Estimator instance.