braindecode.models.modules.GeneralizedGaussianFilter#
- class braindecode.models.modules.GeneralizedGaussianFilter(in_channels, out_channels, sequence_length, sample_rate, inverse_fourier=True, affine_group_delay=False, group_delay=(20.0,), f_mean=(23.0,), bandwidth=(44.0,), shape=(2.0,), clamp_f_mean=(1.0, 45.0))[source]#
Generalized Gaussian Filter from Ludwig et al (2024) [eegminer].
Implements trainable temporal filters based on generalized Gaussian functions in the frequency domain.
This module creates filters in the frequency domain using the generalized Gaussian function, allowing for trainable center frequency (f_mean), bandwidth (bandwidth), and shape (shape) parameters.
The filters are applied to the input signal in the frequency domain, and can be optionally transformed back to the time domain using the inverse Fourier transform.
The generalized Gaussian function in the frequency domain is defined as:
\[F(x) = \exp\left( - \left( \frac{abs(x - \mu)}{\alpha} \right)^{\beta} \right)\]- where:
μ (mu) is the center frequency (f_mean).
α (alpha) is the scale parameter, reparameterized in terms of the full width at half maximum (FWHM) h as:
\[\alpha = \frac{h}{2 \left( \ln(2) \right)^{1/\beta}}\]β (beta) is the shape parameter (shape), controlling the shape of the filter.
The filters are constructed in the frequency domain to allow full control over the magnitude and phase responses.
A linear phase response is used, with an optional trainable group delay (group_delay).
- Parameters:
in_channels (int) – Number of input channels.
out_channels (int) – Number of output channels. Must be a multiple of in_channels.
sequence_length (int) – Length of the input sequences (time steps).
sample_rate (float) – Sampling rate of the input signals in Hz.
inverse_fourier (bool, optional) – If True, applies the inverse Fourier transform to return to the time domain after filtering. Default is True.
affine_group_delay (bool, optional) – If True, makes the group delay parameter trainable. Default is False.
group_delay (tuple of float, optional) – Initial group delay(s) in milliseconds for the filters. Default is (20.0,).
f_mean (tuple of float, optional) – Initial center frequency (frequencies) of the filters in Hz. Default is (23.0,).
bandwidth (tuple of float, optional) – Initial bandwidth(s) (full width at half maximum) of the filters in Hz. Default is (44.0,).
shape (tuple of float, optional) – Initial shape parameter(s) of the generalized Gaussian filters. Must be >= 2.0. Default is (2.0,).
clamp_f_mean (tuple of float, optional) – Minimum and maximum allowable values for the center frequency f_mean in Hz. Specified as (min_f_mean, max_f_mean). Default is (1.0, 45.0).
Notes
The model and the module have a patent [eegminercode], and the code is CC BY-NC 4.0.
Added in version 0.9.
References
[eegminer]Ludwig, S., Bakas, S., Adamos, D. A., Laskaris, N., Panagakis, Y., & Zafeiriou, S. (2024). EEGMiner: discovering interpretable features of brain activity with learnable filters. Journal of Neural Engineering, 21(3), 036010.
[eegminercode]Ludwig, S., Bakas, S., Adamos, D. A., Laskaris, N., Panagakis, Y., & Zafeiriou, S. (2024). EEGMiner: discovering interpretable features of brain activity with learnable filters. SMLudwig/EEGminer. Cogitat, Ltd. “Learnable filters for EEG classification.” Patent GB2609265. https://www.ipo.gov.uk/p-ipsum/Case/ApplicationNumber/GB2113420.0
Methods
- construct_filters()[source]#
Constructs the filters in the frequency domain based on current parameters.
- Returns:
The constructed filters with shape (out_channels, freq_bins, 2).
- Return type:
- static exponential_power(x, mean, fwhm, shape)[source]#
Computes the generalized Gaussian function:
\[F(x) = \exp\left( - \left( \frac{|x - \mu|}{\alpha} \right)^{\beta} \right)\]where:
\(\mu\) is the mean (mean).
\(\alpha\) is the scale parameter, reparameterized using the FWHM \(h\) as:
\[\alpha = \frac{h}{2 \left( \ln(2) \right)^{1/\beta}}\]\(\beta\) is the shape parameter (shape).
- Parameters:
x (torch.Tensor) – The input tensor representing frequencies, normalized between 0 and 1.
mean (torch.Tensor) – The center frequency (f_mean), normalized between 0 and 1.
fwhm (torch.Tensor) – The full width at half maximum (bandwidth), normalized between 0 and 1.
shape (torch.Tensor) – The shape parameter (shape) of the generalized Gaussian.
- Returns:
The computed generalized Gaussian function values at frequencies x.
- Return type:
- forward(x)[source]#
Applies the generalized Gaussian filters to the input signal.
- Parameters:
x (torch.Tensor) – Input tensor of shape (…, in_channels, sequence_length).
- Returns:
The filtered signal. If inverse_fourier is True, returns the signal in the time domain with shape (…, out_channels, sequence_length). Otherwise, returns the signal in the frequency domain with shape (…, out_channels, freq_bins, 2).
- Return type: