Repository navigation
MRG, ENH: Adding a function to import EEGLAB ICA. - #6938
Conversation
Codecov Report
@@ Coverage Diff @@
## master #6938 +/- ##
==========================================
+ Coverage 89.75% 89.77% +0.01%
==========================================
Files 445 445
Lines 79726 80070 +344
Branches 12754 12791 +37
==========================================
+ Hits 71562 71883 +321
- Misses 5370 5379 +9
- Partials 2794 2808 +14 |
|
Note: I made corrections directly through GitHub interfaces so it made a bunch of small commits, but I take for granted that the person that will merge this PR will "squash and merge". |
|
@larsoner Do you know what could cause the Azure Pipelines to throw this kind of errors? Do I need to add some doc somewhere besides the docstrings in the newly added function? |
|
@christian-oreilly you need to add that function to |
|
Diff looks remarkably clean, I expected it to be more painful. But I'm guessing the painful part was getting the math right :) @christian-oreilly can you update |
|
I didn't check the math so I trust that it works based on the test file. If we notice a bug later, we can always correct it then. So 👍 for merge. |
|
Thanks @larsoner. I tried to keep it clean. Yes, the math and understanding what is call what in EEGLAB versus MNE and how to do acceptable correspondances took most of the time. I tested it with three datasets with ICA performed under different context. It might still break down when users will try it on ICA parametrized in ways I did not tested. Since the .set files are juste normal matlab files, users or different EEGLAB extension can modified them in ways I did not forseen. Also, I am also not terribly satisfied from rounding errors but the operations seems right as far as I can tell so I would attribute it matrix inversions or rounding when data are dumped to disk in .set and read back Aside from the official tests, I did not see issues so far on the 100 hd-EEG recordings I used it in for database that I am currently analysing. |
|
just thinking out loud but could you compute an SVD of the mixing matrix to
obtain by the MNE pca_components and the mixing with the same shapes. It
would simplify API documentation.
… |
|
rendering of docstring look wrong https://16261-1301584-gh.circle-artifacts.com/0/dev/generated/mne.preprocessing.ICA.html#mne.preprocessing.ICA not sure if it's your fault @christian-oreilly @larsoner any idea? btw I find the layout of the parameters from sklearn much more readable eg: basically I would not expect the param description to be on the same line at the name + type that should stand out. cc @drammock |
@agramfort Yes, it is probably my fault. CI checks worked before the last commit I made where I changed the docstrings.
I sure would. I had a look at it a few days ago, without much luck. I will look into it again when I get some time. Right now, I shifted to other duties. |
|
@christian-oreilly do you have time to make it green again? i can live with the current design |
I would prefer if we could harmonize the two via |
|
@larsoner No, I did not have much time to take a look at it again. Last time I did, I had the feeling that it might not be possible to do it cleanly. From memory, the issue was boiling down to the fact that we would want to decompose M=X@Y into U@S@V', with X, U and V' being rectangular and S and Y being square. So my problem was about how you get rid of the V' so that you can get the correspondences U=X and S=Y. I tried to transform data such that V' would become the identity matrix but without success. Feel free to have a look at it. Maybe a fresh set of eyes on this problem would be beneficial. @agramfort I just looked at the CI issues more closely. It does not look like it was related to my last commit in the end. It was a socket error when running test_fetch_parcellations. No changes I made should have any effect on that test. Maybe just a transient network failure. I re-triggered the tests to check if they pass now. |
|
@larsoner Is this PR still on your radar? You were supposed to have a look at it around end of October. |
|
Forgot about this, will try to look this week |
|
@christian-oreilly okay for me to rebase and force push? I think I got this working but it would be good if you could double-check. |
c534cc0 to
df106aa
Compare
Typo correction. Co-Authored-By: Alexandre Gramfort <[email protected]>
Co-Authored-By: Alexandre Gramfort <[email protected]>
Co-Authored-By: jona-sassenhagen <[email protected]>
df106aa to
23c6aa9
Compare
I added a Otherwise this should be good for review/merge now. Tests pass locally for me and the code has been squashed to by-author commits, so a rebase+merge rather than squash+merge should be done here if possible. |
|
@larsoner The test I added compare the signals transformed from applying the EEGLAB ICA to those obtained by applying the same ICA imported and applied to the signals in MNE. So I think it is a rather complete test that does verify that the waveform match between EEGLAB and MNE. I am in the middle of refactoring lots of code right now so I need to finish this refactoring before I can rerun my pipeline and see if everything works on my other uses cases. If you don't mind waiting something like a week before merging this PR, I can finish this refactoring, rerun the refactored pipeline with MNE patch with this PR and confirm that everything works fine on my end. |
|
Sure, should be fine to wait |
|
@christian-oreilly does it work now? |
d297746 to
bed67df
Compare
|
(forgot the |
|
@christian-oreilly can you try one more time? If all is well then we can merge |
|
Yes, sorry for the delay. What I tested worked well. I think it can be merged. Thanks. |
|
@agramfort feel free to merge. Would be good to get a set of eyes on the additional checks that I put in place |
|
thx @christian-oreilly and @larsoner ! |
|
Is there a documentation for mne.preprocessing.read_ica_eeglab() to understand the input to insert? |
|
For ICA we do not account for the operation during source analysis IIRC |
|
@dede3de You may want to have a look at |
* Adding a function to import EEGLAB ICA. * Update mne/preprocessing/ica.py Typo correction. Co-Authored-By: Alexandre Gramfort <[email protected]> * Correct read_eeglab_ica to read_ica_eeglab. * Update mne/preprocessing/ica.py Co-Authored-By: Alexandre Gramfort <[email protected]> * Corrections to the PR. * Update mne/preprocessing/ica.py Co-Authored-By: jona-sassenhagen <[email protected]> * Adjusting docstrings for mixing/unmixing matrices. * ENH: Unify * FIX: Pick Co-authored-by: Alexandre Gramfort <[email protected]> Co-authored-by: Jona Sassenhagen <[email protected]> Co-authored-by: Eric Larson <[email protected]>
* Adding a function to import EEGLAB ICA. * Update mne/preprocessing/ica.py Typo correction. Co-Authored-By: Alexandre Gramfort <[email protected]> * Correct read_eeglab_ica to read_ica_eeglab. * Update mne/preprocessing/ica.py Co-Authored-By: Alexandre Gramfort <[email protected]> * Corrections to the PR. * Update mne/preprocessing/ica.py Co-Authored-By: jona-sassenhagen <[email protected]> * Adjusting docstrings for mixing/unmixing matrices. * ENH: Unify * FIX: Pick Co-authored-by: Alexandre Gramfort <[email protected]> Co-authored-by: Jona Sassenhagen <[email protected]> Co-authored-by: Eric Larson <[email protected]>
| ica.pre_whitener_ = np.ones((len(eeg.icachansind), 1)) | ||
| ica.pca_mean_ = np.zeros(len(eeg.icachansind)) | ||
|
|
||
| ica.unmixing_matrix_ = eeg.icaweights |
There was a problem hiding this comment.
I'm afraid this specific change introduced a bug. I don't think the code for n_components < n_ch works as expected. I'll have to check, but it is possible that test_read_ica_eeglab just validates the "else" part of this if, which corresponds more or less to the behavior of this function before the introduction of this if-else statement. I'll create an issue to describe this bug and submit a corresponding PR.
Reference issue
Fixes #6917.
What does this implement/fix?
Adding a function to import ica from EEGLAB .set files.
Todo: