API reference¶
pyRiemann provides a three-part API: Modules with scikit-learn compatible estimators and transformers, Geometry Functions implementing low-level Riemannian geometry operations on SPD/HPD matrices, and Utility Functions for visualization and miscellaneous helpers.
Modules
Scikit-learn compatible estimators and transformers for BCI and SPD matrix pipelines.
Geometry Functions
Low-level Riemannian geometry functions for distances, means, geodesics, kernels, and matrix operations on SPD/HPD matrices.
Utility Functions
Visualization and miscellaneous helpers.
SPD Matrices Estimation¶
|
Estimation of covariance matrices. |
|
Estimate special form covariance matrices for ERP. |
|
Estimate special form covariance matrices for ERP combined with Xdawn. |
|
Estimation of block covariance matrices. |
|
Estimation of cross-spectral matrices. |
|
Estimation of co-spectral matrices. |
|
Estimation of squared coherence matrices. |
|
Estimation of covariance matrices with time delay matrices. |
|
Estimation of kernel matrices between channels of time series. |
|
Regularization of SPD/HPD matrices by shrinkage. |
Embedding¶
|
Perform a Locally Linear Embedding (LLE) of SPD matrices. |
|
Compute barycenter weights of X from Y along the first axis. |
|
Spectral Embedding of SPD/HPD matrices. |
|
Locally Linear Embedding of SPD matrices. |
|
T-distributed Stochastic Neighbor Embedding (t-SNE) of SPD/HPD matrices. |
Classification¶
|
Classification by Minimum Distance to Mean. |
|
Classification by Minimum Distance to Mean with geodesic filtering. |
|
Classification in the tangent space. |
|
Classification by k-nearest neighbors. |
|
Classification by support-vector machine. |
|
Classification by Mean Field. |
|
Classification by Nearest Convex Hull. |
|
Measure class distinctiveness between classes of SPD/HPD matrices. |
Regression¶
|
Regression by k-nearest-neighbors. |
|
Regression by support-vector machine. |
Clustering¶
|
Clustering by k-means with SPD/HPD matrices as inputs. |
|
Clustering by k-means for each class with SPD/HPD matrices as inputs. |
|
Clustering by mean shift with SPD/HPD matrices as inputs. |
|
Gaussian mixture model. |
|
Artifact detection with the Riemannian Potato. |
|
Artifact detection with the Riemannian Potato Field. |
Tangent Space¶
|
Tangent space projection. |
|
Fisher geodesic discriminant analysis. |
Spatial Filtering¶
|
Xdawn algorithm. |
|
CSP spatial filtering with covariance matrices as inputs. |
|
SPoC spatial filtering with covariance matrices as inputs. |
|
Bilinear spatial filter. |
|
AJDC algorithm. |
Preprocessing¶
|
Whitening, and optional unsupervised dimension reduction. |
Channel selection¶
|
Channel selection based on a Riemannian geometry criterion. |
Flat channel removal. |
Transfer Learning¶
|
Encode the domains of the data in the labels. |
|
Decode the domains of the data in the labels. |
|
Class for handling the cross-validation splits of multi-domain data. |
|
Transfer learning wrapper for estimators. |
|
Transfer learning wrapper for classifiers. |
|
Transfer learning wrapper for regressors. |
|
No transformation for transfer learning. |
|
Centering for transfer learning. |
|
Scaling for transfer learning. |
|
Rotation for transfer learning. |
|
Classification by Minimum Distance to Weighted Mean. |
Stats¶
|
Permutation test based on distance. |
|
Permutation test using any scikit-learn model for scoring. |
Datasets¶
|
Generate SPD matrices for two classes. |
|
Generate outlier matrices. |
|
Generate matrices with specific properties. |
|
Generate masks defined as semi-orthogonal matrices. |
|
Sample a Riemannian Gaussian distribution. |
|
Generate 2x2 SPD matrices for two classes in source and target domains. |
|
Random over-sampling for SPD/HPD matrices. |
Geometry Functions¶
Geometry functions are low-level building blocks that implement the core
Riemannian geometry operations on SPD/HPD matrices (covariance estimation,
distances, means, medians, geodesics, kernels, tangent space mappings, base
matrix functions, approximate joint diagonalization, and matrix property
predicates). They live in the standalone pyriemann.geometry subpackage.
Covariance processing¶
|
Estimation of covariance matrices. |
|
Robust M-estimators. |
Schaefer-Strimmer shrunk covariance estimator. |
|
|
Sample covariance estimator. |
|
Special form covariance matrix, concatenating a prototype P. |
|
|
|
Compute block diagonal covariance. |
|
Compute the complex cross-spectral matrices of a real signal. |
|
|
|
Compute squared coherence. |
|
Normalize a set of square matrices, using corr, trace or determinant. |
Compute non-diagonality weights of a set of square matrices. |
Distances¶
|
Distance between matrices according to a metric. |
|
Cholesky distance between SPD/HPD matrices. |
|
Euclidean distance between matrices. |
|
Harmonic distance between invertible matrices. |
|
Kullback-Leibler divergence between SPD/HPD matrices. |
|
Symmetrized Kullback-Leibler divergence between SPD/HPD matrices. |
|
Log-Cholesky distance between SPD/HPD matrices. |
|
Log-det distance between SPD/HPD matrices. |
|
Log-Euclidean distance between SPD/HPD matrices. |
|
Power Euclidean distance between SPD/HPD matrices. |
|
Affine-invariant Riemannian distance between SPD/HPD matrices. |
|
Thompson distance between SPD/HPD matrices. |
|
Wasserstein distance between SPSD/HPSD matrices. |
|
Pairwise distance matrix. |
|
Mahalanobis distance between vectors and a Gaussian distribution. |
Means¶
|
Mean of matrices according to a metric. |
|
AJD-based log-Euclidean (ALE) mean of SPD/HPD matrices. |
|
Ando-Li-Mathias (ALM) mean of SPD/HPD matrices. |
|
Bini-Meini-Poloni (BMP) mean of SPD/HPD matrices. |
|
Cheap mean of SPD/HPD matrices. |
|
Mean of SPD/HPD matrices according to the Cholesky metric. |
|
|
|
Mean of matrices according to the Euclidean metric. |
|
Harmonic mean of invertible matrices. |
|
Mean of SPD/HPD matrices according to Kullback-Leibler divergence. |
|
Mean of SPD/HPD matrices according to the log-Cholesky metric. |
|
Mean of SPD/HPD matrices according to the log-det metric. |
|
Mean of SPD/HPD matrices according to the log-Euclidean metric. |
|
Power mean of SPD/HPD matrices. |
|
Mean of SPD/HPD matrices according to the power Euclidean metric. |
|
Mean of SPD/HPD matrices according to the Riemannian metric. |
|
Mean of SPD/HPD matrices according to the Thompson metric. |
|
Mean of SPD/HPD matrices according to the Wasserstein metric. |
|
Masked Riemannian mean of SPD/HPD matrices. |
|
Riemannian NaN-mean of SPD/HPD matrices. |
Medians¶
|
Euclidean geometric median of matrices. |
|
Affine-invariant Riemannian geometric median of SPD/HPD matrices. |
Geodesics¶
|
Geodesic between matrices according to a metric. |
|
Cholesky geodesic between SPD/HPD matrices. |
|
Euclidean geodesic between matrices. |
|
Log-Cholesky geodesic between SPD/HPD matrices. |
|
Log-Euclidean geodesic between SPD/HPD matrices. |
|
Affine-invariant Riemannian geodesic between SPD/HPD matrices. |
|
Thompson geodesic between SPD/HPD matrices. |
|
Wasserstein geodesic between SPD/HPD matrices. |
Kernels¶
|
Kernel matrix between matrices according to a specified metric. |
|
Euclidean kernel between two sets of matrices. |
|
Log-Euclidean kernel between two sets of SPD matrices. |
|
Affine-invariant Riemannian kernel between two sets of SPD matrices. |
Tangent Space¶
|
Project matrices back to manifold by exponential map. |
|
Project matrices back to manifold by Euclidean exponential map. |
|
Project matrices back to manifold by log-Cholesky exponential map. |
|
Project matrices back to manifold by log-Euclidean exponential map. |
|
Project matrices back to manifold by Riemannian exponential map. |
|
Project matrices back to manifold by Wasserstein exponential map. |
|
Project matrices in tangent space by logarithmic map. |
|
Project matrices in tangent space by Euclidean logarithmic map. |
|
Project matrices in tangent space by log-Cholesky logarithmic map. |
|
Project matrices in tangent space by log-Euclidean logarithmic map. |
|
Project matrices in tangent space by Riemannian logarithmic map. |
|
Project matrices in tangent space by Wasserstein logarithmic map. |
|
Return the weighted upper triangular part of matrices. |
|
Inverse upper function. |
|
Transform matrices into tangent vectors. |
|
Transform tangent vectors back to matrices. |
|
Inner product according to a specified metric. |
|
Euclidean inner product. |
|
Log-Euclidean inner product. |
|
Affine-invariant Riemannian inner product. |
|
Norm according to a specified metric. |
|
Parallel transport according to a specified metric. |
|
Parallel transport for Euclidean metric. |
|
Parallel transport for log-Cholesky metric. |
|
Parallel transport for log-Euclidean metric. |
|
Parallel transport for affine-invariant Riemannian metric. |
Base¶
|
Conjugate transpose operator. |
|
Exponential of SPD/HPD matrices. |
|
Inverse square root of SPD/HPD matrices. |
|
Logarithm of SPD/HPD matrices. |
|
Power of SPD/HPD matrices. |
|
Square root of SPD/HPD matrices. |
|
Find the nearest SPD matrices. |
|
Directional derivative of the matrix exponential. |
|
Directional derivative of the matrix logarithm. |
Aproximate Joint Diagonalization¶
|
Aproximate joint diagonalization (AJD) according to a method. |
|
Approximate joint diagonalization based on Pham's algorithm. |
|
Approximate joint diagonalization based on JADE. |
|
Approximate joint diagonalization based on UWEDGE. |
Matrix Tests¶
|
Check if matrices are square. |
|
Check if all matrices are symmetric. |
|
Check if all matrices are skew-symmetric. |
|
Check if all matrices are strictly real. |
|
Check if matrices are real type. |
|
Check if all matrices are Hermitian. |
|
Check if all matrices are positive definite (PD). |
Check if all matrices are positive semi-definite (PSD). |
|
|
Check if all matrices are symmetric positive-definite (SPD). |
Check if all matrices are symmetric positive semi-definite (SPSD). |
|
|
Check if all matrices are Hermitian positive-definite (HPD). |
Check if all matrices are Hermitian positive semi-definite (HPSD). |
Utility Functions¶
Visualization and miscellaneous helpers.
Visualization¶
|
Plot histogram of bi-class predictions. |
|
Plot scatter of bi-class predictions. |
|
Plot cospectral matrices. |
|
Plot 2x2 covariance matrix as an ellipse. |
|
Plot embedding of SPD matrices. |
|
Plot repetitions of a multichannel waveform. |