function prepare_bemmodel: resulting BEM system matrix is NaN
Vladimir Litvak
v.litvak at ION.UCL.AC.UK
Wed Feb 17 11:48:13 CET 2010
FYI
---------- Forwarded message ----------
From: Christophe Phillips <c.phillips at ulg.ac.be>
Date: Wed, Feb 17, 2010 at 10:07 AM
Subject: Re: Fwd: [FIELDTRIP] function prepare_bemmodel: resulting BEM
system matrix is NaN
To: Vladimir Litvak <v.litvak at ion.ucl.ac.uk>, gbirot at gmail.com
Dear Gwenael,
Vladimir, feel free to forward my response to the FieldTrip mailing
list though a few emails may be needed to sort out this error...
If there are NaN in the 1st BEM matrix generated, C11st, then these
will indeed propagate throughout the rest of calculation...
This C11st matrix is created by a compiled C-routine to speed up
things. The details of the numerical implementation are available
here: http://www.fil.ion.ucl.ac.uk/~chrisp/Thesis/these_ch3_numBEM.zip
Since the code seems to be working for most people but not on your
data, I suspect there is a problem in your mesh.
Are you using a mesh you generated yourself ? Or the (deformed)
template mesh from SPM ? I assume it's the former.
Sometimes, when meshes are generated, there remain "errors" in the
mesh, like one triangle becoming infinitely small because 3 vertices
collapsed to one single point. I suspect this is the case here.
Could you check which vertices lead to a NaN in C11st?
Something like [ii,jj] = find(isNaN(C11st)) should give you the index
of those vertices.
Then check their actual location in 3D (in vol.bnd(1).pnt) and the
triangles that use this/those vertices (in vol.bnd(1).tri).
If you find something dodgy, then you should correct the mesh... like
removing the collapsed vertex/triangle.
Best,
Chris
PS: You should also check that the other matrices Cij don't contain any NaN.
---------- Forwarded message ----------
From: Gwenael Birot <gbirot at gmail.com>
Date: Fri, Feb 12, 2010 at 1:54 PM
Subject: [FIELDTRIP] function prepare_bemmodel: resulting BEM system
matrix is NaN
To: FIELDTRIP at nic.surfnet.nl
Hello,
I am a new user of fieldtrip. I am trying to generate BEM system
matrix using the function 'prepare_bemmodel' and the 'bemcp' method.
The system matrix 'vol.mat' I obtained using the following code is a
'NaN' matrix.
%% -------------- Begin --------------
% ---- load brain mesh
% load_bnd is a function to load brainvisa mesh
[vol.bnd(1).pnt vol.bnd(1).tri] = load_bnd('../data/mesh/colin_
no_artef.eeg-3.bnd');
vol.bnd(1).tri = vol.bnd(1).tri + 1;
vol.bnd(1).pnt = vol.bnd(1).pnt;
% ---- load skull mesh
[vol.bnd(2).pnt vol.bnd(2).tri] =
load_bnd('../data/mesh/colin_no_artef.eeg-2.bnd');
vol.bnd(2).tri = vol.bnd(2).tri + 1;
vol.bnd(2).pnt = vol.bnd(2).pnt/1000;
% ---- load skin mesh
[vol.bnd(3).pnt vol.bnd(3).tri] =
load_bnd('../data/mesh/colin_no_artef.eeg-1.bnd');
vol.bnd(3).tri = vol.bnd(3).tri + 1;
vol.bnd(3).pnt = vol.bnd(3).pnt;
% ---- check meshes
figure; triplot(vol.bnd(1).pnt, vol.bnd(1).tri, [], 'faces_skin'); rotate3d
figure; triplot(vol.bnd(2).pnt, vol.bnd(2).tri, [], 'faces_skin'); rotate3d
figure; triplot(vol.bnd(3).pnt, vol.bnd(3).tri, [], 'faces_skin'); rotate3d
% this gives good results, so meshes are correctly loaded
% ---- prepare BEM model
vol.cond = [0.3300 0.0825 0.3300]; % conductivities
vol.skin = 3; % index of skin surface
cfg = [];
cfg.method = 'bemcp';
vol = prepare_bemmodel(cfg, vol);
%% ------------------- End ------------------------
When executing this code I've got the following result in the matlab prompt
using the mesh specified in the input volume conductor
determining source compartment (1)
determining skin compartment (3)
not using the isolated source approach
Nvert = 1222
Ntri = 2440
weight = 0.095493 , defl = 0.000000
Nverta = 1222
Ntrib = 2440
Nverta = 1222
Ntrib = 2440
Nvert = 1222
Ntri = 2440
weight = -0.095493 , defl = 0.000000
Nverta = 1222
Ntrib = 2440
Warning: Matrix is singular, close to singular or badly scaled.
Results may be inaccurate. RCOND = NaN.
In prepare_bemmodel at 187
In test_fieldtrip at 166
Nverta = 1222
Ntrib = 2440
Warning: Matrix is singular, close to singular or badly scaled.
Results may be inaccurate. RCOND = NaN.
In prepare_bemmodel at 194
In test_fieldtrip at 166
Nverta = 1222
Ntrib = 2440
Nverta = 1222
Ntrib = 2440
Nvert = 1222
Ntri = 2440
weight = 0.159155 , defl = 0.000818
Warning: Matrix is singular, close to singular or badly scaled.
Results may be inaccurate. RCOND = NaN.
In prepare_bemmodel at 220
In test_fieldtrip at 166
and as I mentionned the resulting BEM system matrix vol.mat is a 'NaN'
matrix. I guess the problem occurs in this part of the
prepare_bemmodel function (beginning at line 152):
% --------------------------------------------
% Deal first with surface 1 and 2 (inner and outer skull
% NOTE:
% C11st/C22st/C33st are simply the matrix C11/C22/C33 minus the identity
% matrix, i.e. C11st = C11-eye(N)
weight = (vol.cond(1)-vol.cond(2))/((vol.cond(1)+vol.cond(2))*2*pi);
C11st = bem_Cii_lin(vol.bnd(1).tri,vol.bnd(1).pnt,
weight,defl(1),vol.bnd(1).pnt4);
weight = (vol.cond(1)-vol.cond(2))/((vol.cond(2)+vol.cond(3))*2*pi);
C21 = bem_Cij_lin(vol.bnd(2).pnt,vol.bnd(1).pnt,vol.bnd(1).tri,
weight,defl(1));
tmp1 = C21/C11st;
weight = (vol.cond(2)-vol.cond(3))/((vol.cond(1)+vol.cond(2))*2*pi);
C12 = bem_Cij_lin(vol.bnd(1).pnt,vol.bnd(2).pnt,vol.bnd(2).tri,
weight,defl(2));
weight = (vol.cond(2)-vol.cond(3))/((vol.cond(2)+vol.cond(3))*2*pi);
C22st = bem_Cii_lin(vol.bnd(2).tri,vol.bnd(2).pnt,
weight,defl(2),vol.bnd(2).pnt4);
tmp2 = C12/C22st;
% ------------------------------------------------
where the matrix C11st contains three elements equal to NaN. Since
C11st is then inverted, the result is a 'NaN' matrix.
I'll would very much appreciate your help
Thanks
Gwenael
----------------------------------
The aim of this list is to facilitate the discussion between users of
the FieldTrip toolbox, to share experiences and to discuss new ideas
for MEG and EEG analysis.
http://listserv.surfnet.nl/archives/fieldtrip.html
http://www.ru.nl/fcdonders/fieldtrip/
----------------------------------
The aim of this list is to facilitate the discussion between users of the FieldTrip toolbox, to share experiences and to discuss new ideas for MEG and EEG analysis. See also http://listserv.surfnet.nl/archives/fieldtrip.html and http://www.ru.nl/neuroimaging/fieldtrip.
More information about the fieldtrip
mailing list