Functional Connectivity algorithms

Making & changing box plugins and external apps
Post Reply
cberhanu
Posts: 6
Joined: Sun Mar 10, 2019 6:30 pm

Functional Connectivity algorithms

Post by cberhanu »

Hello,

I have recently started using OpenVibe and plan on developing one or more connectivity algorithms for the connectivity measure box, since with the current ones volume conduction effects might be very large (I'm thinking in the lines of Imaginary Part of Coherency, Granger Causality...). Besides general advice related to this specific task, two essential questions came up:

1) The box is marked as unstable. How much of it can be trusted to work? Or is there a specific inconsistency with the results, errors, or it is a specific algorithm that is not working? This is important for me to know, so that I don't have to test every single step of the calculations.

2) I noticed when creating two equal sine waves in two different channels and measuring the connectivity between them with Magnitude Squared Coherence that it outputs zero always, whereas it should be 1, since the signal is the same (which is what happens with Phase Locking Value). Am I missing something, or is this an error?

Thanks for your attention!
Cristiano

Thibaut
Posts: 264
Joined: Wed Oct 31, 2018 9:14 am

Re: Functional Connectivity algorithms

Post by Thibaut »

Hi,
1) You have the answer Here : http://openvibe.inria.fr/faq/#unstable
2) I do not know this box very well, you have the algorithm used in the folder : Openvibe_Folder\extras\plugins\processing\signal-processing\src\algorithms\connectivity

cberhanu
Posts: 6
Joined: Sun Mar 10, 2019 6:30 pm

Re: Functional Connectivity algorithms

Post by cberhanu »

Thank you for your information!

I have a note/question to make on the Magnitude Squared Coherence algorithm. I do not know if this is the right place for it, but I rather make all my contacts regarding the functional connectivity algorithms in a single place!

In the definition of the Magnitude Squared Coherence there is in the implementation:

Code: Select all

const VectorXd l_vecXdCoherenceNum = (m_vecXcdCrossSpectrum.real().cwiseProduct(m_vecXcdCrossSpectrum.conjugate())).real();
This means we take the real part of the Cross Spectrum Sxy and multiply by the real part of the conjugate of Sxy. However, I think this might not be a good approach since, considering a very simple case of:
  • x being a sine wave (Sx = Ax*e^iPx, where Ax is the amplitude and Px the phase of Spectrum for a given frequency)
  • y the same sine wave shifted by 90 degrees
Then we would expect high coherence (there is only a delay but the signals are the same), but since through the above implementation we obtain Sxy = Ax*Ay*e^i*PI/2 = i*Ax*Ay , when we take the real part the Coherence vanishes.
Instead, we should make something like:

Code: Select all

const VectorXd l_vecXdCoherenceNum = m_vecXcdCrossSpectrum.cwiseProduct((m_vecXcdCrossSpectrum.conjugate()).real();
That is, we take the real part only of the product of Sxy by its conjugate.

Sorry for the long exposure :P Some feedback on this would be great!

Thibaut
Posts: 264
Joined: Wed Oct 31, 2018 9:14 am

Re: Functional Connectivity algorithms

Post by Thibaut »

I dig a little (the one who coded it is no longer there and at the moment there is very little test in OpenViBE for algorithms) and I asked someone who knows a little more these algo , according to him, you're probably right. If you use the OpenViBE version that you compile yourself, test your change on this line. Just as if you want to implement other connectivity algorithm, I'd be happy to add them later in OpenViBE.

Thibaut
Posts: 264
Joined: Wed Oct 31, 2018 9:14 am

Re: Functional Connectivity algorithms

Post by Thibaut »

I dig a little (the one who coded it is no longer there and at the moment there is very little test in OpenViBE for algorithms) and I asked someone who knows a little more these algo, according to him, you're probably right. If you use the OpenViBE version that you compile yourself, test your change on this line. Just as if you want to implement other connectivity algorithm, I'd be happy to add them later in OpenViBE.
Thibaut

cberhanu
Posts: 6
Joined: Sun Mar 10, 2019 6:30 pm

Re: Functional Connectivity algorithms

Post by cberhanu »

Yes I tested it on a very simple example with 2 channels, each with a sine wave, and a different phase shift between them for each trial.
With the current implementation, the value for Magnitude Squared Coherence starts at 1 for a phase shift of 0º and as the shift increases to 90º the Magnitude Squared Coherence decreases (almost uniformly) to 0.
With the little change I described, the value starts at 1 for a 0º phase shift and decreases to 0.4 at a 90º phase shift.
This is still not ideal, but reasonable if we consider a time epoch of 1s, I suppose.
I am, however, really uncertain as to how should I properly test the connectivity algorithms, and would deeply appreciate any suggestions! :?

Thibaut
Posts: 264
Joined: Wed Oct 31, 2018 9:14 am

Re: Functional Connectivity algorithms

Post by Thibaut »

There are two main methods in my opinion:
1) test with typical values of which we know the result (for example for trigonometry examples test the sine / cosine every 45 ° because they are known values, test a 0 divide, a unit multiplication/divide.....)
2) Test an input series and compare the output with a different library that has already been extensively tested and / or used. For example to test classification algorithms by comparing with scikit learn in python

cberhanu
Posts: 6
Joined: Sun Mar 10, 2019 6:30 pm

Re: Functional Connectivity algorithms

Post by cberhanu »

Hello again!

On part of my work for the Master's thesis, I adapted the existing functional connectivity algorithms to provide more stable measures with regards to volume conduction, common reference, etc.
I have crudely implemented:

-> Imaginary Part of Coherency (Nolte et al, 2004) - two approaches, one using the Welch method and other with Hilbert transform
-> Weighted Phase Lag Index (Vinck et al, 2011)
-> Phase Slope Index (Nolte et al, 2008)
-> corrected imaginary Phase Locking Value (Bruña et al, 2018)

All algorithms are coherence based and required minimal alterations on current algorithms.
For validation, I compared the output with Fieldtrip's algorithms, namely by reproducing the steps of Bastos et al, 2016
I hope this work might be of some use to the OpenViBE developing team! If so, how should I proceed to share the code?

Cristiano

Thibaut
Posts: 264
Joined: Wed Oct 31, 2018 9:14 am

Re: Functional Connectivity algorithms

Post by Thibaut »

Hello,
I am interested in any contribution.
Do you have a git with the changes made?
Have you commented and documented your code (the different new files, functions, algorithms ... If in addition in the doc you put the references to the articles where the algo comes from, it's perfect.)
Then, there will undoubtedly be other things to see. masi this will provide me with a basis for incorporating it
Thibaut

cberhanu
Posts: 6
Joined: Sun Mar 10, 2019 6:30 pm

Re: Functional Connectivity algorithms

Post by cberhanu »

Hello,

That is good to hear! Yes I have created a repository with the new algorithm files (https://github.com/stickp1/fc_openvibe). The code is commented, although the great majority of code is common across different algorithms.
I don't think I have any documentation, how should I go about it? You mean something like this? http://openvibe.inria.fr/documentation/ ... asure.html
What format should I use?

Cristiano

Thibaut
Posts: 264
Joined: Wed Oct 31, 2018 9:14 am

Re: Functional Connectivity algorithms

Post by Thibaut »

Hi,
I will soon prepare the next release of OpenViBE. I would not have time to integrate your algorithms by then, but I'll take care of it right after that. For the documentation, At the moment it is a little complicated, you have the step here: http://openvibe.inria.fr/writing-box-documentation/ (you can create the documentation by hand but it's a "little" verbose).
If you use the current sources (with a lot of changes lately). You will see a Riemannian Geometry folder. In which I also put the box tests. If you have time to look to add tests to your algorithms (or modify existing ones).
Thibaut

Post Reply