Skip to content
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

GFP equation #160

Open
mscheltienne opened this issue Feb 16, 2024 · 10 comments · May be fixed by #93
Open

GFP equation #160

mscheltienne opened this issue Feb 16, 2024 · 10 comments · May be fixed by #93

Comments

@mscheltienne
Copy link
Collaborator

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?

@vferat
Copy link
Owner

vferat commented Feb 16, 2024

The usual formula used in MS analysis:

global-field-power-eqn-300x75

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 ?

@mscheltienne
Copy link
Collaborator Author

No that was from a generic method, not expecting any reference (could actually be applied to any channel type..)

@mscheltienne
Copy link
Collaborator Author

All good, it was already patch. Now 'gfp' is an alias for std for EEG sensors, and RMS for MEG sensors.

@vferat
Copy link
Owner

vferat commented Feb 16, 2024

We might also need to use RMS for MEG data in our computations

@vferat vferat reopened this Feb 16, 2024
@mscheltienne
Copy link
Collaborator Author

Oh ! Good point

@vferat
Copy link
Owner

vferat commented Feb 16, 2024

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

@mscheltienne
Copy link
Collaborator Author

I added to #93 the part about RMS for 'extract-gfp-peaks', but it seems we do need 'ignore-polarity' to False for magnetometers

@mscheltienne mscheltienne linked a pull request Feb 16, 2024 that will close this issue
6 tasks
@vferat
Copy link
Owner

vferat commented Feb 16, 2024

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.

@mscheltienne
Copy link
Collaborator Author

But are we actually enforcing centered data? I don't think average reference is a requirement at the moment, should it?

@vferat
Copy link
Owner

vferat commented Feb 16, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants