braindecode.functional.linear_channel_map#

braindecode.functional.linear_channel_map(A, B, cov, noise=0.0, flat=None, match_gain=False, atol=1e-09)[source]#

Best linear estimate of the channels B v from the channels A v.

The electrode potentials \(v\) have prior covariance \(\Sigma\) (cov), plus an unknown offset along each column of \(F\) (flat: a flat prior, e.g. the unknown recording reference). The inputs are \(y = A v + \varepsilon\) with \(\varepsilon \sim \mathcal{N}(0, \sigma^2 I)\) (noise) and the targets are \(t = B v\). The best linear unbiased estimate \(\hat t = W y\) solves

\[\begin{split}\begin{bmatrix} A \Sigma A^\top + \sigma^2 I & A F \\ (A F)^\top & 0 \end{bmatrix} \begin{bmatrix} W^\top \\ M \end{bmatrix} = \begin{bmatrix} A \Sigma B^\top \\ (B F)^\top \end{bmatrix}, \qquad \operatorname{var}(t_k - \hat t_k) = \big[B \Sigma B^\top - W A \Sigma B^\top - (B F) M\big]_{kk},\end{split}\]

which is kriging [Matheron1963], universal kriging when \(F\) is given [Matheron1969], and the posterior mean and variance of a Gaussian process [Rasmussen2006]. Without flat it is \(W = B \Sigma A^\top (A \Sigma A^\top + \sigma^2 I)^{-1}\). The choice of \(\Sigma\) gives the known methods:

  • \(\Sigma = 0\) and \(F = I\) (every potential unknown): the exact derivations of exact_derivation(), W = B A^+, such as bipolar or Laplacian (source) derivations [Hjorth1975]; a target is exact when \(B F\) lies in the span of \(A F\).

  • the spherical-spline kernel (spherical_spline_kernel()), noise the regularisation and \(F = \mathbf 1\) (the unknown reference): spherical-spline interpolation [Perrin1989], which is spline smoothing on the sphere [Wahba1981] and the Gaussian-process estimate with that kernel [Kimeldorf1970].

  • \(\Sigma = L L^\top\) for a lead field \(L\): the minimum-norm estimate [Hamalainen1994]; with the targets taken against a point at infinity (zero potential) it is REST re-referencing [Yao2001].

  • a covariance fitted on dense recordings: the Wiener (linear MMSE) filter.

Parameters:
  • A (Tensor) – (n_inputs, n_electrodes) input channels (derivation_matrix()).

  • B (Tensor) – (n_targets, n_electrodes) target channels.

  • cov (Tensor) – (n_electrodes, n_electrodes) prior covariance \(\Sigma\).

  • noise (float) – Input noise variance \(\sigma^2\) (the regularisation).

  • flat (Tensor | None) – (n_electrodes, n_flat) directions \(F\) with a flat prior.

  • match_gain (bool) – Rescale the part of each row free of the flat constraint (so \(W A F = B F\) still holds) so that the estimate has, as closely as that constraint allows, the prior variance of its target, \([W A \Sigma A^\top W^\top]_{kk} = [B \Sigma B^\top]_{kk}\): the minimum-variance estimate shrinks the amplitude.

  • atol (float) – Largest residual of \(B F\) from the span of \(A F\) for a target to be estimable (the flat part alone, whatever \(\Sigma\)).

Return type:

tuple[Tensor, Tensor]

Returns:

  • weight (torch.Tensor) – (n_targets, n_inputs), float64; rows of targets that cannot be estimated (W A F != B F) are 0.

  • variance (torch.Tensor) – (n_targets,) posterior variance (of the estimate before match_gain); inf where not estimable.

References

[Matheron1963]

Matheron, G. (1963). Principles of geostatistics. Economic Geology, 58(8), 1246-1266. https://doi.org/10.2113/gsecongeo.58.8.1246

[Matheron1969]

Matheron, G. (1969). Le krigeage universel. Cahiers du Centre de Morphologie Mathématique, 1. École des Mines de Paris. https://www.cg.minesparis.psl.eu/bibliotheque/public/MATHERON_Ouvrage_00131.pdf

[Kimeldorf1970]

Kimeldorf, G. S., & Wahba, G. (1970). A correspondence between Bayesian estimation on stochastic processes and smoothing by splines. The Annals of Mathematical Statistics, 41(2), 495-502. https://doi.org/10.1214/aoms/1177697089

[Hjorth1975]

Hjorth, B. (1975). An on-line transformation of EEG scalp potentials into orthogonal source derivations. Electroencephalography and Clinical Neurophysiology, 39(5), 526-530. https://doi.org/10.1016/0013-4694(75)90056-5

[Wahba1981]

Wahba, G. (1981). Spline interpolation and smoothing on the sphere. SIAM Journal on Scientific and Statistical Computing, 2(1), 5-16. https://doi.org/10.1137/0902002

[Perrin1989]

Perrin, F., Pernier, J., Bertrand, O., & Echallier, J. F. (1989). Spherical splines for scalp potential and current density mapping. Electroencephalography and Clinical Neurophysiology, 72(2), 184-187. https://doi.org/10.1016/0013-4694(89)90180-6

[Hamalainen1994]

Hämäläinen, M. S., & Ilmoniemi, R. J. (1994). Interpreting magnetic fields of the brain: minimum norm estimates. Medical & Biological Engineering & Computing, 32(1), 35-42. https://doi.org/10.1007/BF02512476

[Yao2001]

Yao, D. (2001). A method to standardize a reference of scalp EEG recordings to a point at infinity. Physiological Measurement, 22(4), 693-711. https://doi.org/10.1088/0967-3334/22/4/305

[Rasmussen2006]

Rasmussen, C. E., & Williams, C. K. I. (2006). Gaussian Processes for Machine Learning. MIT Press. https://doi.org/10.7551/mitpress/3206.001.0001