eelbrain.pipeline.Covariance

class eelbrain.pipeline.Covariance(method='empirical', max_condition=1000000.0)[source]

Base class for covariance estimation.

Parameters:
  • method (str) – Covariance estimation method.

  • max_condition (float) – Limit how unevenly the covariance weights different directions in the data, by adding just enough regularization to keep its condition number at or below this value (see Notes); 0 to use the covariance as estimated, without regularization.

Notes

Source localization uses the noise covariance to whiten the data. Whitening decomposes sensor space into the eigen-directions of the covariance and scales each direction by \(1/\sqrt\lambda\), the inverse square root of its noise variance (its eigenvalue). The inverse solution fits the whitened data, which means that the residual in each direction is weighted by \(1/\lambda\): the lower the estimated noise in a direction, the more exactly the solution is required to reproduce the measured signal in that direction. The condition number of the covariance, the ratio between its largest and its smallest retained eigenvalue, is thus the ratio between the weight given to the quietest and to the noisiest direction.

These weights are appropriate only if the small eigenvalues are reliable estimates of genuinely low noise, and for very small eigenvalues they are not. Maxwell filtering reconstructs the data from an ill-conditioned basis, which leaves directions whose variance is tiny but still above the tolerance that MNE-Python uses to estimate the rank of the covariance, so they are retained in the whitener. Their eigenvalues reflect the numerical properties of the filter rather than measured noise, and the smallest eigenvalues of a covariance estimated from a short recording are in any case the least accurate. When the condition number reaches 1e10, as it routinely does after Maxwell filtering, the residual in such a direction is weighted 1e10 times more than the residual in the noisiest direction, and any signal that leaks into it, for example through small differences in head position between the noise recording and the data, is fitted at the expense of the actual measurements.

max_condition bounds this ratio. It adds the same constant to every retained eigenvalue (the reg parameter of mne.cov.regularize(), which adds reg times the mean retained eigenvalue to the diagonal), with reg chosen as the smallest value that brings the condition number down to max_condition. A covariance that already meets the target is left unchanged, and covariances that exceed it all end up with the same condition number, which keeps whitening comparable across subjects. Magnetometers, gradiometers and EEG channels form separate blocks, except that magnetometers and gradiometers form a single block after Maxwell filtering, which makes them linearly dependent.

The default of 1e6 is meant to intervene only in the pathological range. Since whitening scales each direction by \(1/\sqrt\lambda\), at a condition number of 1e6 the quietest direction is amplified 1000 times more than the noisiest; at 1e10, where MNE-Python starts warning that the whitener is likely to be unstable, the factor is 100,000. At the other end, the default of mne.cov.regularize() (reg=0.1) bounds the condition number by roughly ten times the rank, i.e. a few hundred for a Maxwell-filtered recording, but it regularizes every covariance regardless of whether it needs it. The default sits between these two values: covariances that MNE-Python would regularize by default but that whiten reliably are left untouched, and only covariances that are far worse conditioned than MNE-Python’s default ever produces are regularized.

Methods

make(data, log_path)

Estimate the covariance from data, bounding its condition number.