MNE: Magnetoencephalography (MEG) and Electroencephalography (EEG) in Python
BSD 3-Clause "New" or "Revised" License
2.72k
stars
1.32k
forks
source link
CSP.plot_filters() is actually plotting the transpose of filters #8579
Closed
hongjiang-ye closed 3 years ago
Describe the bug
The
plot_filters()
method ofmne.decoding.CSP
is not plotting filters, but actually plotting the transpose of filters. Using version0.21.2
.Steps to reproduce
Use the code from Motor imagery decoding from EEG data using the Common Spatial Pattern (CSP) and change the last line of the second code block
csp.plot_patterns
tocsp.plot_filters
, and the result is:And in
mne.decoding.CSP
, the each row offilters_
attribute is one CSP filter, see: https://github.com/mne-tools/mne-python/blob/maint/0.21/mne/decoding/csp.py#L184. But if we set the second row offilters_
to be all zeros, the figure almost has no change:Instead, if we set the second column of
filters_
to be all zeros, then the "second filter" CSP1 becomes empty:So
plot_filters
is actually plotting the transpose of filters (the columns offilters_
), not the csp filters (the rows offilters_
).To fix it
I think just change this line of code https://github.com/mne-tools/mne-python/blob/maint/0.21/mne/decoding/csp.py#L479 to
filters = EvokedArray(self.filters_.T, info, tmin=0)
could fix this issue. I tried the following code and the figure looks more reasonable to be CSP filters:BTW, the figure from
plot_patterns
method is correct.