OHBA-analysis / HMM-MAR

Toolbox for segmentation and characterisation of transient connectivity
GNU General Public License v3.0
212 stars 95 forks source link

Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. #53

Closed pauldhami closed 3 years ago

pauldhami commented 3 years ago

Dear Diego,

I am running the HMM on some resting state EEG data. For each subject, the data is continuous, and parcellated using the DK atlas. Each subject has about 5 mins of data.

However, I am running into this error when trying to perform leakage correction, as well as when trying to run the HMM without leakage correction.

Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 1.875350e-16.

I searched all the input matrices for Inf or NaN values, but do not find any. I also am running into this error using both MNE and LCMV beamforming methods for source localization. I also tried running the HMM on random subset of my data, but the issue remains, so it seems to be something wrong with all the data.

I read the wiki and wonder if it has to do with extreme values in my data? Is there any way to check with code?

Thank you in advance, Paul

vidaurre commented 3 years ago

Hi Paul, Two quick questions: How many channels are you feeding? And which observation model (HMM parameters order, covtype, zeromean) are you using? Cheers d

pauldhami commented 3 years ago

Hi Diego,

Thank you for your response.

The original EEG data is 58 channels, but after source reconstruction, it is 68 regions as defined by the Desikan-Killiany atlas.

I am using the TDE-HMM model, with covtype = 'full', and zeromean I left to the default.

I should note that I changed my source reconstruction from a constrained to solution (which is what the original post was based on), to now doing an unconstrained solution followed by PCA to reduce the 3 orientations to one signal. The warning I received as described in the original post no longer appears, and the HMM appears to run correctly. But I am not sure why going from constrained to unconstrained would "solve" the warning.

Thank you again. Paul

vidaurre commented 3 years ago

Hi Paul,

I'm not sure of the reason why it got solved, but your data seemed to be not full-rank. Of course, if you projected from 58 channels to 68 regions, that's a good reason because your data is not full rank (58<68) —even more if you leakage correct. My suggestion would be to use a parcellation with fewer regions, 68 is probably too much for 58 channels even if you find a hack around the non-full-rank issue.

Thanks d