Minimum distance to mean (MDM)
The simplest manifold classifier is almost embarrassingly direct. In training, compute one mean covariance per class. To classify a new trial's covariance, assign it to whichever class mean is closest in AIRM distance. That is the entire minimum distance to mean (MDM) algorithm — no spatial filters to learn, no features to select, no regularization parameter to grid-search.
\hat{y} = \arg\min_{k \in \{1,\dots,K\}} \; \delta_R\big( C, \, \bar{C}_k \big)The MDM decision rule: label a trial by the nearest class-mean covariance under the Riemannian distance.
The simplest manifold classifier: compute each class's average covariance once, then label a new trial by whichever class-average it is closest to — measured with the curved Riemannian distance.
- C
- The covariance of the trial being classified.
- \bar{C}_k
- The mean covariance of class k.
- \delta_R
- The Riemannian distance used to judge closeness.
- \hat{y}
- The predicted class label.
This minimum-distance-to-mean rule needs no training beyond forming the class means.
Because AIRM is affine-invariant, MDM inherits that invariance for free: it needs no CSP, no re-referencing, no per-session gain normalization. That is why a bare MDM is so hard to beat as a baseline and so forgiving with tiny training sets — with only a handful of trials per class you can already estimate a usable mean.
The Fréchet (Karcher) mean
MDM hides one real subtlety: what is the mean of a set of covariance matrices? Not the arithmetic average (swelling, wrong geometry). The right object is the Fréchet mean — the point that minimizes the sum of squared geodesic distances to all the samples. It is the manifold's version of 'the point that best represents the cloud.'
\bar{C} = \arg\min_{C \succ 0} \; \sum_{i=1}^{N} \delta_R^2\big( C, \, C_i \big)The Fréchet / Karcher mean generalizes the centroid to the SPD manifold. No closed form in general (except N=2 or commuting matrices).
The "average" covariance on the curved space is the point that minimizes total squared Riemannian distance to all trials — just like an ordinary mean minimizes squared distance, but respecting the geometry. Usually found by iteration.
- C_i
- The individual trial covariances being averaged.
- \bar{C}
- Their Fréchet / Karcher mean on the manifold.
- \delta_R^2
- The squared Riemannian distance being summed.
The Karcher mean has no closed form in general, except for two matrices or matrices that commute.
Unlike the flat average there is no closed form, but there is a simple, fast fixed-point iteration: repeatedly whiten by the current estimate, average the samples in the (flat) tangent space, and map the result back onto the manifold. It converges in a handful of iterations because the SPD manifold has non-positive curvature, which guarantees a unique mean.
- Initialize the mean with the arithmetic average of the covariances.
- Whiten every sample by the current mean and take its matrix log — these are the tangent vectors at the current estimate.
- Average those tangent vectors (an ordinary Euclidean average, now that they are flat).
- Map the averaged tangent vector back to the manifold (matrix exp, then un-whiten) to update the mean.
- Repeat until the tangent-space step norm falls below a tolerance — usually only a few passes.
def karcher_mean(Cs, tol=1e-9, max_iter=50):
Cbar = mean(Cs, axis=0) # arithmetic-mean init
for _ in range(max_iter):
E = sqrtm(Cbar); Einv = inv(E) # Cbar^{1/2}, Cbar^{-1/2}
# average the tangent vectors at Cbar
S = mean([logm(Einv @ Ci @ Einv) for Ci in Cs], axis=0)
Cbar = E @ expm(S) @ E # exp-map back to the manifold
if norm(S) < tol:
break
return CbarThe tangent-space trick
MDM is robust but rigid — it only compares distances to means. To bring the full arsenal of linear classifiers (LDA, logistic regression, SVM) onto covariance features, we use the observation that a curved manifold looks flat when you zoom in. Pick a reference point — the Fréchet mean of all training data — and project every covariance onto the flat tangent space there. Projected points are ordinary Euclidean vectors again, so any classifier applies.
\mathbf{s}_i = \operatorname{vech}_{\!*}\!\Big( \log\!\big( \bar{C}^{-1/2} C_i \, \bar{C}^{-1/2} \big) \Big) \; \in \; \mathbb{R}^{\,n(n+1)/2}The tangent-space projection at the reference mean C̄: whiten, take the log, then vectorize the upper triangle (off-diagonals weighted by √2 to preserve the norm).
Flatten the curved manifold near the average into an ordinary vector space, so you can then feed a standard classifier like LDA or SVM. Whiten by the mean, take the log, and unroll the matrix into a vector.
- \bar{C}^{-1/2} C_i \, \bar{C}^{-1/2}
- Whiten each trial by the reference mean.
- \log(\cdot)
- Map from the curved manifold into the flat tangent space.
- \operatorname{vech}_{\!*}
- Vectorize the upper triangle, weighting off-diagonals by \sqrt{2} to preserve the norm.
- \mathbf{s}_i
- The resulting flat feature vector for trial i.
This tangent-space projection lets you keep the manifold's benefits while using any off-the-shelf classifier.
The projected vector has dimension n(n+1)/2 — for 22 channels that is 253 features, a comfortable size for regularized logistic regression or shrinkage LDA. This 'tangent space + linear classifier' pipeline, often called a tangent-space classifier, is the accuracy workhorse of Riemannian BCI. The linearization is only accurate near the reference, but that is fine: your data cloud sits around its own mean, and guide 4's re-centering keeps every session parked there.
MDM or tangent space — choosing
A practical rule of thumb. Reach for MDM when data is scarce, when you need many classes, when interpretability and robustness matter more than the last percent of accuracy, and for online use where its cost is trivial. Reach for the tangent-space classifier when you have enough trials to fit a regularized linear model well and want peak accuracy. Between them sits Fisher-geodesic MDM (FgMDM), which inserts a geodesic-filtering / LDA step to sharpen class separation while keeping MDM's structure.