GFP equation
Opened this issue · 10 comments
Looking quickly through GFP stuff, this is the equation I find in MNE:
np.sqrt((data**2).mean(axis=1))
And this is in pycrostates:
@vferat Any opinion here?
The usual formula used in MS analysis:
which is equals tonp.std
From Numpy documentation:
The standard deviation is the square root of the average of the squared deviations from the mean, i.e., std = sqrt(mean(x))
, where x = abs(a - a.mean())**2
.
It seems that MNE formula is missing the a.mean()
component ( which is 0
in case of average reference). Do you know it average reference is applied before ?
No that was from a generic method, not expecting any reference (could actually be applied to any channel type..)
All good, it was already patch. Now 'gfp' is an alias for std for EEG sensors, and RMS for MEG sensors.
We might also need to use RMS for MEG data in our computations
Oh ! Good point
As suggested in taits 2022 we could use RMS for GFP calculation as well as cosine instead of correlations
The main issue ( and it is the same for #93 ) is the use of smoothing algorithm that we might need to check/adapt for this need metrics
I added to #93 the part about RMS for 'extract-gfp-peaks', but it seems we do need 'ignore-polarity' to False for magnetometers
As RMS
and std
are equivalent in case of centered data, we can change GFP computation to always use RMS, and ensure that in case of EEG data, the average reference is set.
We can do the same and change _corr_vectors
and _distance_matrix
from pycrostates.utils
to use _cosine_similarity
def _cosine_similarity(vector1, vector2):
dot_product = np.dot(vector1, vector2) / (np.linalg.norm(vector1) * np.linalg.norm(vector2))
return dot_product
I'm creating a new branch to keep things clearer.
But are we actually enforcing centered data? I don't think average reference is a requirement at the moment, should it?
Yes I agree, the current implementation enforce centered data, and so everything words well for EEG.
However, when tait 2022 extend the definition of EEG microstates to MEG microstates, they propose to use RMS as a measure of global field power and cosine similarity as a measure on similarity. This measures extend the current methodology to reference free recordings such a MEG.
In case of centered data, std = rms and cosine similarity == correlation , so the pipelines hold in