Plotting spatial patterns with CSP for each class

Hello,

I would like to plot spatial patterns of my data with using csp for each class. I know MNE supports the

csp.plot_patterns()

But it does not give for class based. How can I obtain the class based patterns like the following? Thank you.

image

Hi @ali44,

When you use the CSP() class (as in python class; let’s avoid confusion), the experimental class labels are ordered alphabetically. Moreover, using the ‘"component order’" parameter you can control which component corresponds to which class. E.g. for the case of n=4 components and c=2 classes (“Left Hand” or “Right Hand”), setting CSP(component_order='mutual_info') (the default) would mean that the first 2 components correspond to the “Left Hand” class and the next 2 to the “Right Hand” class.

Now, I am not quite sure how this would generalize in a multi-class problem as I have never used it this way, but I would hypothesize it’s the same: n=6 and c=3 would you give you back pairs (1-2), (3-4), (5-6) for each corresponding class.

But in order to be sure, I would suggest taking a look at the source code.

Hope this helps you get started.

1 Like

Thanks for your reply @sotpapad ,
I think the component_order=‘mutual_info’ is based on eigenvalues.

Hi @ali44,

You are right. This is what I had in mind, but did not remember that the absolute of the eigenvalues is used in the two-class case. In this case what I previously wrote is not guaranteed, as it was based on the assumption of ordered, signed eigenvalues. This would imply that you need to use the ‘alternate’ option in the two-class case. That would order eigenvalues in (+,-) pairs of decreasing “importance” and you would be sure that + corresponds to “Left” and - to “Right” because trials are ordered alphabetically.

I think, though, that selecting ‘mutual_info’ in the multi-class case would give you what you want, because then the eigenvalues are not ordered by absolute deviation from the mean.

1 Like

Thanks @sotpapad . I understand now.
Do you also know how to obtain the topographical values mathematically. I want to obtain numerical values of each electrodes from the topographical map of CSP patterns? For example, I want to obtain why CP3 and P1 electrodes are red, and others not using MNE? I know it calculates eigens of covariance matrices, but how can I see them numerically using MNE? Thank you
image

You can’t have access to the eigenvalues. But, depending on what it is that you want to do, the .filters_ and .patterns_ attributes are accessible. The plot_filters() and plot_patterns() functions just use these values to plot the topographic maps (and also provide a corresponding colorbar for the values).

1 Like