Strange source activity with lcmv beamformer in volume source space (empty room covariance)

Hello MNE forum!

I am running into problems when trying to use LCMV beamformers on evoked MEG data (mags & grads) with a volume source space.

  • using an empty-room noise covariance matrix and a data covariance matrix computed from the epochs leads to confetti-like source activation values (upper right plot)

  • running the same pipeline with a noise covariance computed on the epochs’ baseline works fine (lower right)

Discussing this with @agramfort, he pointed out the 2 bumps in the covariance matrices computed on epochs (both baseline and post-stimulus time windows) – @larsoner what do you think about those?

@sophie

  1. Can you see if this problem occurs with minimum-norm localization of the same data? This will tell us if it’s a problem with beamforming specifically or the whitening that comes from the noise covariance. My guess is that it’s the noise cov but we’ll see!
  2. Did you process the task data and the empty-room data the same way, looks like using MaxFilter? I have some code for processing empty-room data the same way as run data, for example by hacking in the info['dev_head_t'] and setting destination the same way and actually using the head position from an actual run with movement compensation, etc. I haven’t implemented this in MNE because I doubt it affects other people very much but if it turns out to be a not-identical-MaxFilter-processing issue we can figure out how to incorporate it. Also FIX: Improve covariance code · Issue #4676 · mne-tools/mne-python · GitHub might be to blame.
  3. If you have a surface source space for this subject (recon w/FreeSurfer), can you try using a surface source space instead? I imagine the same issue will come up but if it’s easy to test we might as well.

We hacked something like this into the MNE Study Template because this is something we had to deal with for numerous datasets. Just saying this to let you know there is, in fact, a demand, and if you believe this could somehow be added to MNE directly, I’d greatly appreciate it (and I’d be willing to help test)

Hi @larsoner, thank you for your suggestions!

I tried different combinations and the stc looks similarly scattered with:

  • MNE/ dSPM on same volume source space
  • lcmv on surface source space

It looks normal however when using dSPM on the surface source space only, with the same noise-cov. :thinking:

I used the study-template code by @richard to manually change the dev_head_t and dig of the empty room to the one from a reference run, and otherwise the same maxfilter parameters and filters as for the subjects’ data.

The bad STCs seem to depend on the rank of the covariance matrix: when I compute the noise cov with rank=‘info’, it estimates a rank of 72, while the data has a rank of 73 (multiple runs combined).
When I instead compute the noise cov with rank = {meg=‘73’} (estimated from the data) the resulting stc looks fine (volume source space, LCMV).

For make_lcmv I use the following rank parameters: rank = {meg=‘73’} and reduce_rank=True; without explicitly setting the rank it gave me an error saying the rank of the noise and data covariance doesn’t match. Could that be the issue finally?

how does this happen? when you pass rank=‘info’ to compute_covariance and make_lcmv and the info in the same it should be 72 everywhere. It’s not the case? Any explanation based on your code?

Alex

@agramfort I think this happens because maxfilter is applied on each of 8 raw runs separately, so they end up having slightly different ranks. Then the runs are combined to epochs with one resulting rank.
The empty room gets the dev_head_t from one reference run, so it might end up having a different rank than the epochs (all ranks range between 71-74).
For compute_covariance I use the info from the empty room raw, and for the lcmv the info from the epochs.

we need to find a way to detect this issue and throw a warning / error if this happens


@larsoner thoughts?

Alex

make_lcmv did issue a warning about the mismatch in ranks between noise and data cov, when rank=‘info’, which I thought I had overcome by explicitly providing the rank from the data (no warning).

so there is already a message? if so maybe we can make it more explicit and also explain
how to fix it in the message.

So
 I’m confused now. How would one fix it?? It appears to me @Sophie did all she mentioned above intentionally, no?

There is no message about the mismatch if the rank is set explicitly.

I still don’t fully grasp why this mismatch of ranks by 1 causes such trouble
since the rank of the epochs does anyways not reflect the rank of every run.

1 Like

I’d like to second that :slight_smile: Not sure what the “correct” approach would be!

Maybe Algorithms and other implementation details — MNE 0.22.0 documentation would be a good place for 1–2 paragraphs about ranks, and how to deal with them properly?

[See also https://github.com/mne-tools/mne-python/pull/8707]

I would use the rank of the matrix that is doing the whitening. So @sophie in your case compute rank from the empty-room raw, not from the epoched / evoked task data, or process the empty-room in an identical way and you will probably be safe enough – but even then it’s probably safest to compute rank from the empty-room data.

Let’s say you have two matrices, noise = np.diag([1, 1, 1e-14, 0.9e-14]) and data=np.diag([1, 1, 1, 1e-14]). If we want to whiten data using the matrix noise, the correct behavior is to use rank=2 and your resulting data matrix will have one component thrown away because it is truly of rank 3. You lose a bit of information this way, but it’s probably the best you can do with a mismatch of spatial subspaces. And at least with MaxFiltered data, the mismatch will occur in the highest (spatial) orders, so you’ll be losing some of your lowest-SNR components anyway (hopefully no huge loss).

OTOH if you whiten with rank=3 your whitened data matrix will be totally broken, because your whitening matrix will be something like np.diag([1, 1, 1e14, 0]), and 1e14 will dominate even though this was a valid component in your data. And worse, sometimes the subspace mismatch will mean that this component wasn’t even present in your data so you can be literally amplifying noise rather than signal.

Processing your empty room the same way as generally raw helps with these situations because it helps ensure (but does not guarantee, at least in the case of movement compensation) that the high-order components that are thrown away during regularization are the same in both cases. And something like the proposals here would allow us to explicitly keep track of which spatial components are present and maybe do a better job of reconciling them:

Concretely though I would say that even though in general rank problems can be tricky, if we special-case MEG channels (and maybe even MEG+MaxFilter?) without reference channels we can probably detect this sort of problem. @sophie Can you share your noise and data covariances somewhere?

1 Like

Hi @larsoner, thank you for the elaborate response!
Does your recommendation to use the rank of the noise covariance matrix also hold when it has a higher rank than the data covariance matrix (by 1 or 2)?

I will send you a link to the data.

Yes it should still apply in that case. Think about the reverse case where you have data = np.diag([1, 1, 1e-14, 0.9e-14]) and noise = np.diag([1, 1, 1, 1e-14]). Your whitener with rank=3 based on noise will be np.diag([1, 1, 1, 0] and your whitened data will be np.diag([1, 1, 1e-14, 0], i.e., the component that was essentially zero in your original data will stay that way.

2 Likes

Hello @sophie, what’s the current status of this? Did you manage to resolve the issue? I would be very curious to learn if and how you got it resolved, so we can follow the same approach in the Study Template. Thanks!

Hi @richard, I did follow Eric’s suggestion, to use the rank of the matrix used for whitening and the stc’s look ok now. I think this point would merit to be made explicit somewhere as a recommendation.

I will clean up my code and we can discuss for the study template.

Thanks @sophie, this sounds great! Let me know if you’d like to schedule a call.

Best wishes

1 Like

I’d like to add my +1 to implement this functionality. I wouldn’t know how to do it, but it does seem helpful indeed!

1 Like