sccn / xdf

BSD 2-Clause "Simplified" License
87 stars 34 forks source link

numpy.linalg.linalg.LinAlgError: Matrix is not positive definite #23

Closed schelian closed 5 years ago

schelian commented 6 years ago

HI all, new to EEG but I'm learning by looking at NeuroPype and MNE. I"m happy to learn best practices for EEGLAB, etc.!

I have an XDF file, when I open it with xdf, I get the error message below. By the way, I just installed MNE and put the xdf.py file in the directory where the script file is. If there is a better install for xdf, please let me know.

I also got a warning from SigViewer but that does load the file eventually.

Error message from XDF:

  reached end of file.
  performing clock synchronization...
Traceback (most recent call last):
  File "mne_view.py", line 35, in <module>
    streams, header = load_xdf(op.join(data_path, eeg_filename))
  File "C:\Users\suhas\Desktop\prjs\golf_processing\src\xdf.py", line 357, in load_xdf
    winsor_threshold)
  File "C:\Users\suhas\Desktop\prjs\golf_processing\src\xdf.py", line 494, in _clock_sync
    coef.append(_robust_fit(X, y))
  File "C:\Users\suhas\Desktop\prjs\golf_processing\src\xdf.py", line 572, in _robust_fit
    L = np.linalg.cholesky(np.dot(A.T, A))
  File "C:\ProgramData\Anaconda3\lib\site-packages\numpy\linalg\linalg.py", line 614, in cholesky
    r = gufunc(a, signature=signature, extobj=extobj)
  File "C:\ProgramData\Anaconda3\lib\site-packages\numpy\linalg\linalg.py", line 92, in _raise_linalgerror_nonposdef
    raise LinAlgError("Matrix is not positive definite")
numpy.linalg.linalg.LinAlgError: Matrix is not positive definite

Error message from SigViewer: image

cboulay commented 6 years ago

The problem is likely that one of the streams in your data file has no clock offsets. This is a problem that has been cropping up recently and we're trying to narrow down the cause. You can still load the file if you pass synchronize_clocks=False to the load function, but then your streams won't be synchronized. If all your streams are coming from the same PC and they all use the system clock then this MIGHT NOT be too bad (still not as good as it could be).

However, the SigViewer warning suggests that this will in fact be bad.

Can I ask what device(s) you were recording from and what were the settings for the recording?

schelian commented 6 years ago

Thank you @cboulay!, your suggestion works in Python.

Strangely, with Matlab and xdfimport1.13, an error still comes up even though I called it like so: load_xdf( fileName, 'HandleClockSynchronization', 'false' ) Error message:

Error using chol
Matrix must be positive definite.

Error in load_xdf>robust_fit (line 695)
L = sparse(chol(A'*A,'lower')); U = L';

Error in load_xdf (line 435)
                    mappings{r} = robust_fit([ones(idx(2)-idx(1)+1,1)
                    clock_times(idx(1):idx(2))']/opts.WinsorThreshold,
                    clock_values(idx(1):idx(2))'/opts.WinsorThreshold);

We have one set of data collected from a Cogniomics q20 and another from an ABM M4 w/ a LSL recorder.

cboulay commented 6 years ago

Do you have a small file with this problem that you can upload?

cboulay commented 5 years ago

This bug was fixed in liblsl in Nov 2018. To avoid getting this error in the future, you will need to use a version of LabRecorder that uses liblsl more recent than that.