JoramSoch / MACS

MACS – a new SPM toolbox for model assessment, comparison and selection
GNU General Public License v3.0
22 stars 6 forks source link

cvLME: "Error using chol : Matrix must be positive definite." #8

Open Remi-Gau opened 2 years ago

Remi-Gau commented 2 years ago

I got this error when running cvLME on one participant (might occur in others too but I have not checked yet) when trying to add MACS to our BIDS pipelines:

See this PR: https://github.com/cpp-lln-lab/CPP_SPM/pull/472

------------------------------------------------------------------------
13-Jan-2022 10:28:28 - Running job #3
------------------------------------------------------------------------
13-Jan-2022 10:28:28 - Running 'MA: define model space'
13-Jan-2022 10:28:28 - Done    'MA: define model space'
13-Jan-2022 10:28:28 - Running 'MA: calculate cvLME (automatic)'

-> Subject 1 (1 out of 1):
   - Model hrf (1 out of 6) ... 13-Jan-2022 10:30:12 - Failed  'MA: calculate cvLME (automatic)'
Error using chol
Matrix must be positive definite.
In file "/home/remi/matlab/SPM/spm12/toolbox/MACS/MD_mvn_logdet.m" (???), function "MD_mvn_logdet" at line 59.
In file "/home/remi/matlab/SPM/spm12/toolbox/MACS/ME_GLM_NG_LME.m" (???), function "ME_GLM_NG_LME" at line 49.
In file "/home/remi/matlab/SPM/spm12/toolbox/MACS/MA_cvLME_multi.m" (???), function "MA_cvLME_multi" at line 333.
In file "/home/remi/matlab/SPM/spm12/toolbox/MACS/batch_MA_cvLME_auto.m" (???), function "run_module" at line 75.

The following modules did not run:
Failed: MA: calculate cvLME (automatic)

Error using MATLABbatch system
Job execution failed. The full log of this run can be found in MATLAB command window, starting with the
lines (look for the line showing the exact #job as displayed in this error message)
------------------
Running job #3
------------------

Here is the design matrix for that subject / model.

sub-ctrl02_task-olfidolfloc_space-MNI152NLin2009cAsym_desc-beforeEstimation_designmatrix_001

Had to specify some dummy regressors, due to some conditions not being present in all runs. That did not affect other subjects / models so far though.

Let me know if I can help in some ways to help trouble shoot this one.

JoramSoch commented 2 years ago

Dear @Remi-Gau,

thanks for the issue.

Yes, it probably has to do with the empty regressors. However, the problem should only occur, if there's a regressor that only has entries in exactly 1 session and no entries in the S-1 other sessions (s.t. there is a CV fold with an entirely empty training regressor - this is the source of the problem). And, even in this case, there's a solution in place (represented by this code line in the cvLME routine). Moreover, from your design matrix I can see that each regressor has entries in at least two sessions (right?), so I don't really know what's wrong here.

If you could send the SPM.mat file to joram.soch@bccn-berlin.de, I can maybe take a closer look at this next week. In case that the SPM.mat file is too big, try this:

load SPM.mat
SPM.xVol = rmfield(SPM.xVol,'XYZ');
save('SPM_new.mat','SPM');

Cheers Joram

JoramSoch commented 2 years ago

For those who are interested in the technical details, please have a look at these lousy hand-written notes which I didn't have the time to transfer to machine-readable text so far.

JoramSoch commented 2 years ago

Regarding the question (i) whether session need to have the same number of regressors (answer: yes) and (ii) whether they need to be in the same order (answer: yes), please see this one-page excerpt from the toolbox manual.