Envelope Correlation N x N (2020) - Dimensions of arrays being concatenated are not consistent

Dear BST Community,

I am having trouble using the Envelope Correlation N x N (2020) feature.

I am testing it on one participant, with 47 epochs (source localized), each epoch of 10 seconds long (512 Hz samples). Running Amplitude Envelope Correlation (N x N) works and provides no error, but to speed up the process, I would like to run the exact same analysis but with the parallel processing provided in the Envelope Correlation N x N (2020).

My understanding is that the "Estimation window length" should equal to the "Time Window" if I want to produce the same results as the Amplitude Envelope Correlation (N x N).

But when trying to do so, I am running into the following error:


** Error: [process_henv1n] Connectivity > Envelope Correlation NxN (2020)
** Line 23: cat
** Dimensions of arrays being concatenated are not consistent.
**
** Call stack:
** >process_henv1n.m at 23
** >bst_process.m>Run at 230
** >bst_process.m at 37
** >panel_process1.m>RunProcess at 124
** >panel_process1.m at 26
** >gui_brainstorm.m>CreateWindow/ProcessRun_Callback at 768
** >bst_call.m at 28
** >gui_brainstorm.m>@(h,ev)bst_call(@ProcessRun_Callback) at 292
**
**


Below is my GUI setup:

Any help with this would be greatly appreciated.

My understanding is that the "Estimation window length" should equal to the "Time Window" if I want to produce the same results as the Amplitude Envelope Correlation (N x N).

This probably results in gigantic files created in memory, and maybe output files with an unnecessarily high frequency resolutions. Have you tried with shorter epochs?

I am running into the following error

I could not reproduce the error you reported with the options shown in your screen capture.
Could you please share an example dataset so that we can first reproduce this error?

  • Right-click on the subject > File > Duplicate subject
  • In the duplicated subject, keep only the files that are needed to reproduce the error:
    • In the anatomy: the MRI, the cortex surface you used for the source estimation
    • In the functional data: the channel file, two data files + the inversion kernel (or + the associated source maps if they are not links)
  • Make sure you can replicate the error with this minimalist setup
  • Right-click on the subject > File > Export
  • Upload the .zip file somewhere and post the download link here

@hossein27en @Raymundo.Cassani
Do you see any combination of inputs that can cause problem?

Hi Francois,

Thank you for the response.

I have tried shortening the epochs down to 2 seconds, and still run into the error.

I also shortened "Estimation Window Length" from 10000 down to 1000, in steps of 1000. Only when I reached 1000, did it work. However, since I'm trying to produce the exact same results as Amplitude Envelope Correlation (N x N), as in only interested in static AEC with Hilbert Transform, I followed this post by Hossein, which if I'm understanding the last part of it, "Estimation Window Length" should equal the entire "Time Window" for what I am trying to do. Or is "Estimation Window Length" not considered at all when choosing "Static" (this was my first thought)?

Please find the link below with the example dataset. The error was replicated with this as well (just the 2 data files).

https://drive.google.com/drive/folders/12NIpAH9q3pyg6yJIkrLonXgWOTPudqol?usp=sharing

Thank you.

@hossein27en Could you please have look at this? - Thanks

Hi Francois,

I am revisiting this analysis, and was hoping to speed up the analysis using the parallel feature for AEC calculation.

However, I am running into the same error as posted above.

Any help would be greatly appreciated.
Paul

I debugged the code and understood what the problem was: the Envelope correlation code is not capable of correctly handling unconstrained source maps.
I opened a PR to propose a fix for these changes:

We'll let you know when the PR is merged and you can download a fixed version of Brainstorm.

Great, thank you Francois!

@pdhami
The PR is now merged into the Brainstorm distribution.
Please update Brainstorm and try again.

Hi Francois,

Thank you, it works now!

I am still having trouble however reproducing the same results as found using the Amplitude Envelope Correlation (N x N).

The top figure (theta band) is that calculated with Envelope Correlation N x N (2020), with the 'Estimation window length' set to the length of the full epoch (9998 ms; this is resting state continuous EEG where I split the data into ~10 sec epochs). The bottom is with the static Amplitude Envelope Correlation N x N process.

EDIT: orthogonalization was applied to both.

Any suggestions as to what I may be doing wrong?

Best,
Paul

These are results obtained with the files you shared earlier?

Can you please post screen captures of the options that you are using in the two cases (including all the secondary option windows that can be set from the pipeline editor)?

Hi Francois,

For the Envelope Correlation (2020) process:

image

Please note this is a different file as the one I had previously shared is no longer in my database.

For the Amplitude Envelope Correlation:

For sake of time, I thought I would do the analysis on just a few scouts and compare them again. This time, they are equivalent:

I may have done something wrong with the definition of the time window that led to the differences originally reported.

On a related note, is there any reason why would want to define the "time window" and "overlap %" when using the static option? From my understanding the 2 parameters are for dynamic?

Thanks,
Paul

I double checked everything regarding the time window options, and now am getting the original differences I reported in the same dataset.

The dataset that showed the difference vs the one above (where they are the same) are different. Not sure if this could be an issue with the data? I will dig further.

Hi Francois,

I've compared the two methods again, and they are indeed not converging on this particular data. What is interesting is that when comparing the correlations values for each connection, either they do match, or they do match in magnitude, but are opposite in direction.

A few examples:

As the tutorial says:
" Time resolution: If Dynamic, connectivity is saved for each time window. If Static, the connectivity measures are averaged across all windows. Select Dynamic."
https://neuroimage.usc.edu/brainstorm/Tutorials/Connectivity#Envelope_correlation

I've compared the two methods again, and they are indeed not converging on this particular data.

Can you share an example dataset?
The simplest could be that you extract the scouts time series (with the dedicated process) first. Make sure that you can reproduce the same differences with the scouts time series in input (select the scouts "matrix" files in the Process1, instead of the source maps). Then share only this matrix_...mat file so we can reproduce your observations on our end.

Thanks

Hi Francois,

I followed your instructions and am still getting differences.

Top is with the Amplitude Envelope Correlation process, and bottom is Envelope Correlation (2020) process.

Please find the matrix file using the following link:

Thank you,
Paul

Thank you for the example file.
I could reproduce exactly the behavior you reported.

I noticed that the values are mostly the same, except for some differences:

  • The old function (AEC) return positive/negative values, while the new function (HENV) returns strictly positive values
  • A small number of values are very different (not only a sign difference), like the one selected in the screen captures below (same as yours, but with the colormap configured with the option "Absolute values")

Old function (AEC):
image

New function (HENV):
image

@hossein27en
You can download the example posted above as a readily available Brainstorm protocol from the link below. You can import it with the menu File > Load protocol > Load from zip file.
https://www.dropbox.com/s/00fqc10srbbxq5n/TutorialConnectivity_Comparison_AEC.zip?dl=0

@pdhami Note that we've just updated the HENV processes. This corrects many bug fixes, but does not change the differences you observed.
Please update Brainstorm to get these fixes before doing any further tests.

https://github.com/brainstorm-tools/brainstorm3/commit/0d634662e3e135beabe77c5f53263db49078e3a7

Hi Francois,

Thank you for the update.

I was able to finish my AEC calculations using the old process.

I'm assuming (due to providing both positive and negative correlations) that these results are 'correct' and okay to move forward with, and that the issue is strictly with the newer HENV process?

Best,
Paul

We tested further the comparison between the older AEC and the new HENV processes.
You can reproduce exactly the results obtained the new HENV results with the older processes AEC by editing bst_connectivity.m.
Eeplace line 504:

R(:,:,iBand) = (R(:,:,iBand)+R(:,:,iBand)')/2;

with

R(:,:,iBand) = (abs(R(:,:,iBand))+abs(R(:,:,iBand))')/2;

And replace line 515:

R(iSeed,:,iBand) = (r1+r2)/2;

with:

R(iSeed,:,iBand) = (abs(r1)+abs(r2))/2;

Explaination from Hossein:

Amplitude envelope correlation is not a symmetric measure by its nature. Still, most people have used it as symmetric, and there is no clear explanation about the meaning of the connectivity from A->B Vs. B->A.
As a result, my code and the AEC make the matrix symmetric by adding its transpose and dividing over 2. However, I apply abs() before summation, but the AEC does not (so if there is a negative value, it might cancel the positive one). I do think the abs value is necessary. In MNE-python, they have abs as the default.

1 Like

The AEC processes have been deprecated:
https://github.com/brainstorm-tools/brainstorm3/commit/33a5ffa28d7f9d17495c75fe1e1d8d132d50693b