-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
[MRG] More work on the beamformer code #5447
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
Conversation
|
@wmvanvliet can you confirm that we should indeed be emitting warnings when using DICS with multiple channel types, e.g. mag+grad, or worse mag+grad+eeg? |
|
for now, yes, but we should just whiten the CSD like we do with the LCMV beamformer. EIther me or @britta-wstnr will probably get to it soon. |
|
Okay cool. If not before 0.17 (not sure when that will be) then we'll want to make a note in the example |
|
I'm being over-enthousiastic in sharing this, unit tests currently fail. I'll look at it tomorrow and fix things :) |
391ff25 to
d56849e
Compare
Codecov Report
@@ Coverage Diff @@
## master #5447 +/- ##
==========================================
+ Coverage 88.43% 88.51% +0.07%
==========================================
Files 363 369 +6
Lines 68196 69136 +940
Branches 11524 11645 +121
==========================================
+ Hits 60309 61193 +884
- Misses 5045 5089 +44
- Partials 2842 2854 +12 |
|
goody, that looks like fun to debug... |
|
CircleCI is failing because sphynx-gallery refuses to build or something. |
|
@britta-wstnr are you happy with the |
0a7116a to
8d22f79
Compare
|
Ok, tests all pass and this PR is ready for comments. @britta-wstnr WDYT? |
larsoner
left a comment
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.
Other than versionadded, LGTM. I'm trusting @britta-wstnr to check the math
|
@wmvanvliet I was hoping to find some time while at Biomag - but realized that I need some more time to go over the code! So excuse my slowness here, I will give it a look when back! |
|
Enjoy Biomag! |
|
Hi @wmvanvliet - finally had time looking over the code. However, it is basically impossible to compare old and new code snippets for the things that change the output of LCMV or DICS due to the refactoring. Could you please split the PR into 2, probably best code changes first and then refactoring? |
|
@wmvanvliet diff is indeed quite big and it is harder to review if part is refactoring and part is bug fix / change of behavior. Can you allocate some time to help @britta-wstnr review this work? If you have doubts let me share a quote. "Along you go fast, together we go far" ! |
|
@britta-wstnr here are the changes to the LCMV beamformer, in a separate PR: #5511 |
833e64b to
efa3c40
Compare
|
Rebased after merging #5511 |
|
@wmvanvliet in the meantime can you see if you agree wmvanvliet#6 is correct? |
|
I will take a look! |
|
@britta-wstnr this would be great to get into 0.17. Can you take a look in the next week or so? |
|
@wmvanvliet does this close #5362? |
|
... and also @wmvanvliet we have to figure out how to deal with |
| if k in info['ch_names']]) | ||
|
|
||
| # XXX this could maybe use pca=True to avoid needing to use | ||
| # _reg_pinv(..., rank=rank) later |
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.
Just a minor comment here that eventually we could make compute_beamformer pass on the pca argument (we currently don't publicly expose it), meaning that it would return a non-rank-deficient multplier of shape (rank, 306) instead of (306, 306). It might simplify things at some point. I've also wanted this parameter before when analyzing data.
|
Okay @wmvanvliet done, feel free to look to make sure it looks like I did not break anything. I touched the beamformer examples so we could ensure that they are not broken: @wmvanvliet it looks like the DICS example changed, maybe not for the better. It looks like it's also that way on your commit when I try a8f4f1f locally. Do you think it's okay, or is there something to fix? EDIT: Updated to reflect CircleCI build for 05813cc |
|
I'll have to take a look. Don't merge this yet. Currently busy with kids but I'll try to get to it soon. |
|
@larsoner how about this? |
|
Yeah that makes sense. Travis is red, though, can you look into it? If not I can do it in a few hours |
|
@wmvanvliet so for |
doc/whats_new.rst
Outdated
| API | ||
| ~~~ | ||
|
|
||
| - The parameter ``rank`` was added to :func:`mne.beamformer.make_dics` and :func:`mne.beamformer.make_lcmv`` with a default of ``'full'`` that will change to ``None`` in 0.18 to auto-compute the rank of the covariance matrix before regularization by `Marijn van Vliet`_ |
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.
@wmvanvliet I realized that we should probably do this. We need a deprecation cycle for make_lcmv to do this. I assume we also need it for make_dics but if not let me know and I can set the defaults there back to None instead of '' (the internal signal I used for checking deprecation).
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.
The default for make_dics is already None. For the LCMV, I don't like changing the default without some good simulation study backing it up. Both the LCMV and DICS defaults are carefully selected to yield generally stable beamformers.
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.
@britta-wstnr care to weigh in on this?
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.
FYI this commit is outdated, now DICS has no deprecation but yes LCMV still has a deprecation cycle scheduled to go from 'full' to None. I agree it might make sense to wait a release cycle to do this deprecation, though, to be safe. I'll revert it.
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.
Ok, if you do that, I'm happy with everything.
|
Updated example links above to reflect their current status. @wmvanvliet if you are happy with the deprecation updates I made and the examples, then I think this is finally ready for merge! |
|
Okay reverted the deprecation. It seems like it should be okay to have it in there but I agree it's safer not to. And we want to release ASAP, so let's not do the deprecation "full"->None in 0.17. @wmvanvliet do you want to try to fix the "Singular matrix" vs "complex spectrum" error depending on build type? To me it seems not worth the effort, unless you see that it's obvious and easy, e.g. some default tolerance is bit too high and fixing it makes it work. |
|
Hang on... something changed in the output of the |
|
I did change the example to:
It looks okay to me with these differences in mind. (It actually looks better, since (2) makes it so the same vertex is now found in free orientation as in fixed.) |
|
I can confirm that this (reverting) diff: Puts the But I think the one in this PR is more correct (using |
|
ah ok. Thanks for looking into it. |
|
Thanks @wmvanvliet ! |
|
🎈 🍾 🎉 |

This PR gives the
_create_beamformeranother refactoring pass to unify the LCMV and DICS flow.Bugs fixed:
pick_ori='normal', weight_norm='unit_noise_gain'. The existing implementation has a bug where the weights were first normalized to have unit length before picking the normal direction. Instead, the weights should be normalized to unit length after picking the orientation, as is the case whenpick_ori='max-power'.inversion='single', pick_ori='max-power', weight_norm='unit_noise_gain'. The computation of the power (in order to pick the orientation with max power) was bugged.inversion='matrix', pick_ori='max-power', weight_norm='unit_noise_gain'. In this case, a computational shortcut is performed, but it was performed incorrectly. See this comment.New features:
reg_pinvfunction, which now lives inutils.pyand will even walk your dog.method='lcmv'andmethod='dics'.New features we got for free in the process:
pick_ori='max-power'now also supported whenweight_norm=Noneweight_norm='nai'now also supported whenpick_ori=Noneandpick_ori='normal'weight_norm='nai'now also supported for the DICS beamformerrankparameter for the DICS beamformer to explicitly specify rankrank='auto'setting to do rank-based inversion as in ENH: Ditching regularization - beamformer with rank-based inversion of cov matrix #5362 (DICS already did this)In all other cases, the new version gives exactly the same output as the version in the current master branch:
LCMV
DICS