mne_rt.tools.GEDAIDenoiser#
- class mne_rt.tools.GEDAIDenoiser(n_channels: int, shrinkage: float = 0.01)[source]#
Bases:
objectArtifact removal via Generalised Eigendecomposition-based Artifact Identification (GEDAI).
Solves the generalised eigenvalue problem (GEP)
C @ w = lambda * R @ wwhereCis the signal covariance andRis a reference covariance. Two modes are supported:Leadfield mode (recommended, true GEDAI):
R = L @ L.T, whereLis the EEG forward/leadfield gain matrix. Becauselambda = (w.T @ C @ w) / (w.T @ R @ w), components with largelambdacarry sensor power that the brain’s theoretical source model cannot explain and are treated as artifacts; components with smalllambdaare leadfield-aligned and are kept as brain signal. Usefit_from_leadfield()to fit in this mode.Band-filter mode (Cohen-style GED):
C = R_bandandR = R_broad(broadband EEG covariance, Tikhonov-regularised). Components with largelambdamaximise the target-band-to-broadband ratio, while components with smalllambdacapture broadband noise. Usefit()orfit_from_raw()for this mode.
In both modes the unmixing matrix
W(spatial filters) and activation patternsA = pinv(W.T)are stored after fitting. Denoising zeroes the selected artifact columns ofAand reconstructs clean sensor data asx_hat = A_clean @ W.T @ x.- Parameters:
References
Ros, T., Férat, V., Huang, Y., et al. (2025). Return of the GEDAI: Unsupervised EEG Denoising based on Leadfield Filtering. bioRxiv. https://doi.org/10.1101/2025.10.04.680449
Cohen, M. X. (2022). A tutorial on generalized eigendecomposition for denoising, contrast enhancement, and dimension reduction in multichannel electrophysiology. NeuroImage, 247, 118809.
Methods
__init__(n_channels[, shrinkage])denoise(data, artifact_idx)Suppress artifact components and reconstruct sensor data.
find_artifact_components(template_map[, ...])Identify artifact components by correlation with a spatial template.
find_noise_components([n_noise])Return indices of artifact/noise components according to the fitted mode.
fit(data_broadband, data_band)Estimate spatial filters from baseline data (band-filter mode).
fit_from_leadfield(data, leadfield)Fit using the forward/leadfield matrix as the reference covariance.
fit_from_raw(data, sfreq, band)Convenience wrapper: bandpass-filter
datainternally then callfit.inverse_transform(components)Reconstruct sensor-space data from components.
transform(data)Project data into component space.
update_and_denoise(data, template_map[, ...])Identify blink/artifact components then denoise in one call.
Attributes
Activation patterns A = pinv(W.T), shape (n_channels, n_channels).
Sorted eigenvalues (descending) from the GED.
Spatial filters W, shape (n_channels, n_channels).
- fit(data_broadband: ndarray, data_band: ndarray) GEDAIDenoiser[source]#
Estimate spatial filters from baseline data (band-filter mode).
- fit_from_leadfield(data: ndarray, leadfield: ndarray) GEDAIDenoiser[source]#
Fit using the forward/leadfield matrix as the reference covariance.
This is the true GEDAI mode described in Ros et al. (2025). The reference covariance is constructed as
R = L @ L.TwhereLis the leadfield gain matrix. Because the GEP solvesC @ w = lambda * R @ w, components whose eigenvalues are large have excess sensor variance relative to the theoretical brain source model and are treated as artifacts; components with small eigenvalues are leadfield-aligned and are kept as brain signal.
- fit_from_raw(data: ndarray, sfreq: float, band: tuple[float, float]) GEDAIDenoiser[source]#
Convenience wrapper: bandpass-filter
datainternally then callfit.
- inverse_transform(components: ndarray) ndarray[source]#
Reconstruct sensor-space data from components.
- find_artifact_components(template_map: ndarray, threshold: float = 0.7) tuple[list[int], ndarray][source]#
Identify artifact components by correlation with a spatial template.
- find_noise_components(n_noise: int = 1) list[int][source]#
Return indices of artifact/noise components according to the fitted mode.
In leadfield mode (
fit_from_leadfield()), eigenvalues measure the ratio of observed sensor variance to theoretical brain variance (C @ w = lambda * R_lead @ w), so components with the largest eigenvalues are artifact candidates, and the topn_noisecomponents[0, ..., n_noise - 1]are returned.In band-filter mode (
fit()/fit_from_raw()), components with the smallest eigenvalues capture the least band-specific activity and are returned as broadband noise candidates[n_channels - n_noise, ..., n_channels - 1].
- denoise(data: ndarray, artifact_idx: list[int]) ndarray[source]#
Suppress artifact components and reconstruct sensor data.