-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CSP component order selection #8151
Conversation
I'll take a detailed look soon, but here are already three questions:
|
|
I would maybe use Also if |
There are too many choices for my taste. Previously, we didn't have a parameter to select the sorting order - the function used MI-based sorting for both two- and multi-class cases, even though the implementation differed. The problem with that was that the "classic" approach of sorting patterns by alternating sorted eigenvalues was not available. IMO, it would be sufficient to have two possible values for the parameter, |
I am not sure about the name alternating
I started reading too. Looking at
https://www.sciencedirect.com/topics/engineering/common-spatial-pattern
See sentence:
"Since λ1j+λ2j=1, a high value for λ1j means that the filter output based
on filter *wj* yields a high variance for input signals in class 1 and a
low variance for signals in class 2 (and vice versa); spatial filtering
with such filters can thus significantly enhance discrimination ability. "
this suggests that you should sort by the distance to 0.5. I checked the
maths and I agree.
I don't know where the alternating option comes from. So this suggest we
need 2 options : 'variance' (dist to 0.5), 'mutual_information' and
eventually a third option which is 'alternating'. I would like to see a ref
in the docstring for the 3 strategies so it does not seem we came up with
that in MNE...
thx
… |
@agramfort see my comment here. Currently we have no options, but we're already doing two different things for the two- and multi-class case. Why do you want to introduce a new argument for something we already did without? Also, am I correct in assuming that the distance to 0.5 is not equal (not even conceptually) to sorting by mutual information? Even if these are not equal, I'd still summarize them as one method (the advanced), whereas the alternating one (the naive) should be there for practical reasons (it has been published, and many people in the BCI community have been using that - not sure if this is still the case though). |
Currently we have no options, but we're already doing two different things
for the two- and multi-class case. Why do you want to introduce a new
argument for something we already did without?
the question is do we want mutual info in the 2d case? if so we need a
parameter.
Also, am I correct in assuming that the distance to 0.5 is not equal (not
even conceptually) to sorting by mutual information?
correct.
Even if these are not equal, I'd still summarize them as one method (the
advanced), whereas the alternating one (the naive) should be there for
practical reasons (it has been published, and many people in the BCI
community have been using that - not sure if this is still the case though).
so we still want to support the alternating option? It's your call if you
think it's useful
|
I don't think so, this PR just adds the classic alternating sorting. I think it's still useful because the question how we sort using the new method(s) comes up frequently. However, we could also go with @larsoner's suggestion and just implement the new approach. This would mean no new parameter, no change to the code, just add links to the literature to explain the current sorting. I'm fine with either approach, but I am 👎 on introducing a new parameter with three or four possible values. |
@cbrnr so what you suggest in the 2d case? what is called old or new here? |
@agramfort I think your comment about the distance to 0.5 equalling variance is not quite correct. After all, CSP is designed to maximize the variance difference between/within conditions, so all criteria will somehow work on the variance (at least indirectly). Therefore, I suggest that we keep things simple (at the risk of being inaccurate) and use the following values for the
|
In addition, I would rename |
I find the term mutual_info for the distance to 0.5 a bit misleading but I
will not fight :)
… |
That's the inaccuracy I was talking about 😄 - I think it's more useful to keep it simple, and people can always read the docstring to find the exact methods with references. Also, we still haven't ruled out that the distance to 0.5 is somehow related to the mutual information as a special case. @alexandrebarachant maybe? |
fair enough...
|
Does everybody agree now it should be done like that? |
@mbillingr and @agramfort? Plus I suggest using |
So we'll have |
fine with me
… |
I implemented the changes, let's see if tests still come back green. |
@larsoner I've implemented all suggestions, please check if the examples are OK and if the footbibliography works. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@larsoner merge if happy
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Scores changed slightly in this one but it seems okay:
The title "Decoding in time-frequency space data using the Common Spatial Pattern (CSP)" could be shortened to "Decoding in time-frequency space using Common Spatial Patterns (CSP)". |
Feel free to push this change if you want |
By "scores changed slightly" I'm assuming you mean coverage - where is our coverage CI? |
Got it. The scores changed quite a lot - @mbillingr do you have an idea what could have caused this change? I thought that this PR didn't change the previous (default) behavior? |
Run-to-run variability due to cross-validation shuffling? |
Could be -- @cbrnr or @mbillingr please check and if so set the random state so it's reproducible |
* upstream/master: (489 commits) MRG, DOC: Fix ICA docstring, add whitening (mne-tools#8227) MRG: Extract measurement date and age for NIRX files (mne-tools#7891) Nihon Kohden EEG file reader WIP (mne-tools#6017) BUG: Fix scaling for src_mri_t in coreg (mne-tools#8223) MRG: Set pyvista as default 3d backend (mne-tools#8220) MRG: Recreate our helmet graphic (mne-tools#8116) [MRG] Adding get_montage for montage to BaseRaw objects (mne-tools#7667) ENH: Allow setting tqdm backend (mne-tools#8177) [MRG, IO] Persyst reader into Raw object (mne-tools#8176) MRG, BUG: Fix errors in IO/loading/projectors (mne-tools#8210) MAINT: vectorize _read_annotations_edf (mne-tools#8214) FIX : events_from_annotation when annotations.orig_time is None and f… (mne-tools#8209) FIX: do not project to sphere; DOC - explain how to get EEGLAB-like topoplots (mne-tools#7455) [MRG, DOC] Added linear algebra of transform to doc (mne-tools#7087) FIX: Travis failure on python3.8.1 (mne-tools#8207) BF: String formatting in exception message (mne-tools#8206) BUG: Fix STC limit bug (mne-tools#8202) MRG, DOC: fix ica tutorial (mne-tools#8175) CSP component order selection (mne-tools#8151) MRG, ENH: Add on_missing to plot_events (mne-tools#8198) ...
* move data type check into function that checks input data * allow selection of csp decomposition algorithm * replace selection of decomposition by selection of ordering * remove redundant comments * flake8 * remove unused function * pydocstyle * Simplify component_order argument * Update test * Update docstring * Fix component_order attribute error * Add whats_new entry * fix default in component_order docstring * test for exception in case of wrong component_order * Minor improvements to examples * Test invalid component_order/number of classes combination * Use utils functions to validate types and check options * Use footbibliography * Merge tests * Better example title * Remove empty field in bib entry * Add DOI * FIX: Seed * FIX: Test * FIX: Dup * DOC: DOI * FIX: Test Co-authored-by: Clemens Brunner <[email protected]> Co-authored-by: Eric Larson <[email protected]>
Reference issue
Resolves #8074.
What does this implement/fix?
CSP
to select how to order components._check_Xy
..fit()
into smaller functions for improved readability.Additional information
I left the refactoring in for now because I already made it.
You may to prefer not to have these changes in order to keep the code closer to the original from pyRiemann.
Let me know :)