Error while computing sources: "Input to SVD must not contain NaN of Inf"

Hello. In this case I’m reasonably confident the problem is something I’m doing rather than a bug based on the handful of other threads similar to this, so I’m filing under “Discussions”. I have mixed head models for all subjects, as well as an EEG noise covariance matrix for each subject. I am selecting the option “Compute sources [2018]” for a condition, and selecting the defaults (Method Minimum norm imaging). I get the following output and error at the command line:

BST_INVERSE (2016) > Modified Feb 2018

BST_INVERSE (2018) > Deep Brain Analysis for 5 submodels

BST_INVERSE (2018) > NOTE: Cross Covariance between sensor modalities IS NOT CALCULATED in the noise covariance matrix

BST_INVERSE > Rank of the 'EEG' channels, keeping 255 noise eigenvalues out of 257 original set
BST_INVERSE > Using the 'reg' method of covariance regularization.
BST_INVERSE > Diagonal of 10.0% of the average eigenvalue added to covariance matrix.
BST_INVERSE > Using 'free' surface orientations
BST_INVERSE > Using 'fixed' surface orientations
BST_INVERSE > Using 'fixed' surface orientations
BST_INVERSE > Using 'free' surface orientations
BST_INVERSE > Using 'free' surface orientations
Error using svd
Input to SVD must not contain NaN or Inf.

Error in bst_inverse_linear_2018 (line 764)
[UL,SL2] = svd((L*L'));

Error in process_inverse_2018>Compute (line 638)
                    [Results, OPTIONS] = bst_inverse_linear_2018(HeadModel, OPTIONS);

Error in process_inverse_2018 (line 24)

Error in panel_protocols>TreeInverse (line 1221)
            [OutputFiles, errMessage] = process_inverse_2018('Compute', iStudies, iDatas);

Error in panel_protocols (line 44)

Error in tree_callbacks>@(h,ev)panel_protocols('TreeInverse',bstNodes,'2018') (line 2302)
        gui_component('MenuItem', jPopup, [], 'Compute sources [2018]', IconLoader.ICON_RESULTS, [], @(h,ev)panel_protocols('TreeInverse', bstNodes, '2018'));


Let me know if you need more information/data to help me figure this out. Thanks,


Hi Karl,
Maybe there is something wrong with your noise covariance matrix. Display it and make sure it was properly computed (non-zero values for all the EEG channels).

Thanks Francois. Here are the answers to your two suggestions. Does this matrix look ok?

>> load data/Subject01/@default_study/noisecov_full.mat
>> figure;imagesc(NoiseCov);colorbar
>> numel(find(NoiseCov==0))

ans =



The noise covariance looks like what we expect.
Then there is maybe an issue with the forward model. Have you used OpenMEEG?
There are bugs that are currently being identified and fixed with OpenMEEG, which could cause some parts of the gain matrix to be left empty.
Right-click on the head model > File > Export to Matlab > “HeadmodelMat”, and check if HeadmodelMat.Gain contains lots of zeros or NaN value.
If so, this is also a bug you could report to the OpenMEEG team.

Can you try with the 3-shell sphere model instead, to check if it works correctly?


Yes I used OpenMEEG, and yes there are many zeros in the gain matrix, thought that was suspicious:

Data exported as "HeadmodelMat"
>> size(HeadmodelMat.Gain)

ans =

         257       44565

>> numel(find(HeadmodelMat.Gain==0))

ans =


>> figure;imagesc(HeadmodelMat.Gain);colorbar

I will report the issue to the OpenMEEG team, and try the 3-shell sphere model.


yep this doesn’t look good. How do I reproduce?

Or could you get to the point where I can take the .mat files and try the openmeeg command?

@Francois Can you advise which files I should share to reproduce this gain matrix?

Also, I am able to create a head model with the 3-shell sphere method. But when I click on compute sources for one of my stimulus conditions and look at the results, there doesn’t seem to be anything there. If I right-click and look at Cortical activations, there is nothing there and if I click on Project sources it says “Source and destination surfaces are the same for all the selected files. Nothing to project…” Not sure if I’m doing something wrong.

Actually the intermediate matrices should be in .brainstorm/tmp/ as in the previous case. What I’m not sure is when the cleaning is carried out. But if you execute the code step by step it should be possible to stop it right before.

I see what you mean. I’ll create the OpenMEEG head model again and see if the intermediate files remain in the tmp directory. @Francois can you advise where I could a breakpoint etc. right before the tmp files are removed?

Actually Brainstorm left all the OpenMEEG stuff in the tmp folder after it finished making the head model, so I have it all. Here it is:


even the previous example gives the same result. I’ll open an issue.

I’ve open an issue in openmeeg. Something I did not try was to replicate with previous versions of openmeeg I’m away of the keyboard. Could you check if the issue described in openmeeg replicates with previous versions?

Ok I can confirm that the same result is obtained from version 2.2.0. I used that one since that version was mentioned previously, let me know if you think using some other version might yield something different. I used the three mat files that @sik referenced on the issue report on the OpenMEEG Github. Here is what I did:

d127h208:lib karl$ ../bin/om_gain -EEG ~/segFaultTests/openmeeg_hminv.mat ~/segFaultTests/openmeeg_dsm.mat ~/segFaultTests/openmeeg_h2em.mat ~/segFaultTests/gain_eeg.mat
../bin/om_gain version 2.2.0 (exported) compiled at Feb 22 2013 18:41:19

| ------ ../bin/om_gain
| -EEG
| /Users/karl/segFaultTests/openmeeg_hminv.mat
| /Users/karl/segFaultTests/openmeeg_dsm.mat
| /Users/karl/segFaultTests/openmeeg_h2em.mat
| /Users/karl/segFaultTests/gain_eeg.mat
| -----------------------
Using variable with name : matrix
| Elapsed Time: 29.1593 s.
d127h208:lib karl$ ../bin/om_matrix_info -i ~/segFaultTests/gain_eeg.mat 
../bin/om_matrix_info version 2.2.0 (exported) compiled at Feb 22 2013 18:41:12

Loading : /Users/karl/segFaultTests/gain_eeg.mat
Format : BINARY
Dimensions : 257 x 45000
Min Value : -330.452 (124,1212)
Max Value : 170.216 (124,1192)
First Values
13.0735 -9.86959 0.198685 13.0337 -9.88526 -0.520019 12.9657 -9.84932 -1.20087 12.7462 
16.1424 -9.24023 10.517 16.2927 -9.54824 9.77919 16.4522 -9.83405 9.06673 16.7769 
15.7827 -7.38458 15.9536 15.9731 -7.73443 15.3997 16.2067 -8.08761 14.8833 16.7852 
14.5447 -5.27728 18.6208 14.7053 -5.55507 18.2369 14.9275 -5.84641 17.9067 15.547 
12.9091 -3.77995 20.3059 13.0044 -3.98566 20.0702 13.1719 -4.20764 19.9021 13.7204 
10.8581 -2.22544 21.5094 10.8544 -2.33409 21.4133 10.927 -2.45614 21.3972 11.302 
8.00609 -1.14805 22.613 7.84871 -1.18406 22.667 7.76609 -1.22948 22.811 7.82512 
5.14811 0.149441 23.1186 4.82897 0.210086 23.2716 4.57636 0.268769 23.5167 4.26515 
2.34021 1.5524 23.1087 1.86344 1.71623 23.3077 1.44162 1.886 23.5922 0.749412 
15.7289 -7.68692 6.34218 15.8258 -7.83236 5.60371 15.912 -7.95043 4.89727 16.0397

And then in MATLAB:

>> load segFaultTests/gain_eeg.mat
>> numel(find(linop==0))

ans =


Not attaching the picture again because it seems to be identical.

@Francois, I am able to create a head model with the 3-shell sphere option from my mixed cortex + subcortical surface. Then I click “Compute sources [2018]” for one of my stimulus conditions and on “MN: EEG(Mixed) 2018” I right click and click on “Cortical activations” but nothing is there, in any of the displays. I see no activations anywhere. Does this indicate what a problem might be?

@Francois the problem is matio i/o. I wanted to do a PR changing all matrix extensions from mat to bin which should solve the problem but I found out that this is already in the code base.

So calling bst_openmeeg_bin should be enough.


@sik bst_openmeeg_bin.m has not been updated for a long time, I don’t think this is a good idea to recommend using it as is. It would automatically replace openmeeg 2.4 with 2.2…
I think you’d rather submit a new bst_openmeeg_bin.m by copying bst_openmeeg.m and replacing all the .mat with .bin (what you suggested initially). Or adding the file extension as an input parameter to bst_openmeeg.

@lerud Sorry for the response delay. Have you solved your issues?
If you don’t see anything in the sources results: have you tried setting the amplitude threshold to zero and/or adjusting the colormap.

Thanks @Francois. Actually I was only looking at time zero because I didn’t notice that you can specify a time in the main window to advance through the activations. I now see activations, although they’re not at all what I expect. For example I am expecting largely subcortical sources but am seeing the opposite: Distributed activation all throughout the cortical surface. But I will continue to try to figure that out.

Meanwhile, I have been using the 3-shell sphere head model, but I see that the necessary fixes to OpenMEEG and Brainstorm look to have been merged. @sik and @Francois, can I now use the OpenMEEG head model instead, on both macOS and Linux? Will they update automatically or do I have to do something manually to use the latest versions?


I'd recommend you start by reading all the introduction tutorials using the example dataset before trying to use Brainstorm on your own data.

In the meantime we'll finish fixing the distribution. Most likely, you'll have to update Brainstorm manually (menu Update > Update Brainstorm), which will then update OpenMEEG automatically.

@lerud you should now be able to update brainstorm and get an updated version (2.4.1) of OpenMEEG that should work out of the box.