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
Regression spectra (negative values) #228
Comments
Normally, we wouldn't use the normalised alphas to calculate the mode-specific spectra. However, I think we standardise the alphas before regressing, so it might not make a difference. Maybe just to double check can you run the function using the raw alphas you get from |
Yes in the regression spectra code the alphas are normalised. And yes I can run the function using raw alphas. |
I ran the scipy.signal spectrogram function on the same dataset. I don't get back any negative values in the spectrogram when I use that function. |
Just to be clear there are negative values in the actual PSD/auto spectral density which is a problem. The real part of cross spectral density can have negative values which is fine. |
This might be unrelated but I think the normalisation in normalised alphas is different from the normalisation before regression. The formor ensures they are normalised by the trace of the covariances, but the latter z-transforms the alphas. |
Sorry for the delay. The model to calculate the mode PSDs is a GLM (General Linear Model): P_t = alpha_jt P_j + P_0 + eps where P_t is the spectrogram calculated using Welch's method. alpha_jt are the (non-normalised, i.e. raw) mixing coefficients inferred by DyNeMo (these are obtained using the P_t is always positive. This means P_0, which is the time-average of P_t, is also always positive. However, P_j can be negative for certain frequencies which represents for a particular mode then that mode "activates" (increases in mixing coefficient) it results in less power in that particular frequency. In practice however the mode PSDs, P_j, generally are positive for most frequencies and and negative values are very small. I would advise just plotting P_j (mode PSDs, referred to as the Note, if you're passing |
P_t = Spectrogram for a window designated by t? Then when I use return_coefs_int = False will P_j s be omitted? Or just the intercept will be not be returned. If that is the case then for clarity does the "int" part of return_coefs_int refer to intercept? So this means that if for example when we use coherence returned from the function regression spectra then it possible that the values are negative and/or greater than 1? |
Since you mention that P_j can be negative therefore cpsd values can be negative. coh[i, j, k] = abs(cpsd[i, j, k]) / np.sqrt( That is why I get warnings and errors for np.sqrt. RemedyBut this has to be fixed. Can't we simply take the absolute value in order to normalize? Sign has no meaning here for normalization. Maybe directly of the complex number. Absolute value is being used in the numerator anyway. Although it is being used to calculate the magnitude of complex values. Some questionsThis also brings into question the concept of using regression spectra to calculate coherence or PSD. What are we assuming here? That it doesn't matter what the sign of regression coefficient is for a specific frequency bin it just depends upon the magnitude? Example2 Mode DyNemo model: Then how do we spectrally segregate the modes? Or what is unique about them? Any other interpretation would also be helpful. |
Sample outputNAN VALUES :1: RuntimeWarning: invalid value encountered in sqrt abs(cpsd[i, j, k]) / np.sqrt(cpsd[i, j, j].real * cpsd[i, k, k].real) |
Did you bandpass filter the data you pass to |
1-125 Hz |
I meet the same problem. I get negative value in psd compute when usd spectral.regression_spectra after training DyNeMo. However, when I train HMM using the same data, I didn't get any negative value. |
Apologies for the delay on this. Will get back to very soon. |
Hi team,
I was calculating the regression spectra using the function:
spectral.regression_spectra()
I am using normalized alpha.
Code
Problem
There are negative values in the cpsd.real being passed to the function def coherence_spectra(cpsd, keepdims=False).
https://osl-dynamics.readthedocs.io/en/latest/_modules/osl_dynamics/analysis/spectral.html#coherence_spectra
I don't understand why would we have negative values in the spectrogram that is being calculated using Welch's method.
What is going on here?
The text was updated successfully, but these errors were encountered: