[FieldTrip] Potential bug using ft_dipolefitting with fieldtrip-20200623

Schoffelen, J.M. (Jan Mathijs) jan.schoffelen at donders.ru.nl
Thu Jul 2 14:51:54 CEST 2020


Dear Martin,

Thanks for uploading the data.
Here’s the deal: the current code doesn’t work (it could be that it worked properly before: it could be that it ran through, but probably did not behave as expected), since there is a inconsistency in the way the input cfg is defined.
Particularly, you ask for a 2 dipole model, using a symmetry constraint (which in itself is fine), + a gridsearch (which is also fine), but also with precomputed leadfields in the grid for the gridsearch. It’s the precomputed leadfields that cause the problem here, since these have not been built with the symmetry constraint, which means that for each element, the leadfield represents the dipolar leadfield from a single location, and not from a symmetric dipole pair. This causes a mismatch in the expected numbers when doing the reshaping, which causes the error you report. I suspect that either of the following would work for you:

specify cfg.grid = removefields(leadfield_eeg, {‘leadfield’ ‘label’}); , and let the leadfields for the grid to be computed on the fly (because this seems to take the symmetry constraint into account),

or

recompute your leadfield_eeg (i.e. call ft_prepare_sourcemodel followed by ft_prepare_leadfield), but ensure that in ft_prepare_sourcemodel you specify the same symmetry constraint that you want to use for the dipolefitting.


I hope that this helps.

Best wishes,
JM

PS: there’s a typo in the onscreen feedback of the starting positions for the nonlinear search after the grid search. This is inconsequential for the functional behavior. I will fix this, and this fixed code will become available in the newest release.




On 2 Jul 2020, at 10:08, Martin Schaefer <martin.schaefer at ki.se<mailto:martin.schaefer at ki.se>> wrote:

Martin Schaefer has shared a OneDrive for Business file with you. To view it, click the link below.


<https://kise-my.sharepoint.com/personal/martin_schaefer_ki_se/Documents/Bifogade%20filer/debugging_files.rar>
[https://r1.res.office365.com/owa/prem/images/dc-generic_20.png]<https://kise-my.sharepoint.com/personal/martin_schaefer_ki_se/Documents/Bifogade%20filer/debugging_files.rar>

debugging_files.rar<https://kise-my.sharepoint.com/personal/martin_schaefer_ki_se/Documents/Bifogade%20filer/debugging_files.rar>




Dear Jan-Mathijs,

Thanks for getting back to me!
I did the debugging steps you recommended and attached a screenshot of the sourcemodel, the index gets created correctly as well.

I attached the data you asked for as a zip file, because they are ~110 mb I have to share them via OneDrive.

I also realised that I had writen down the wrong cfg configurations; these are the ones that lead to the error:
cfg = [];
cfg.gridsearch         = 'yes';
cfg.numdipoles      = 2;
cfg.symmetry         = 'x';
cfg.grid                    = leadfield_eeg;
cfg.headmodel       = headmodel_eeg;
cfg.dipfit.metric     = 'rv';
cfg.model                = 'regional';
cfg.senstype           = 'eeg';
cfg.channel             = 'all';
cfg.nonlinear          = 'yes';
cfg.latency              = late_latency;

dipole_eeg_late = ft_dipolefitting(cfg, timelockeds{4});

Best regards,
Martin
------------
Martin Schaefer | PhD Student
https://www.perceptionlab.se/
Department of Clinical Neuroscience (CNS), K8
Karolinska Institutet | 17 177 Stockholm | Nobels väg 9
martin.schaefer at ki.se<mailto:artin.arshamian at ki.se>
______________________________________
Karolinska Institutet – a Medical University

________________________________
From: fieldtrip <fieldtrip-bounces at science.ru.nl<mailto:fieldtrip-bounces at science.ru.nl>> on behalf of Schoffelen, J.M. (Jan Mathijs) <jan.schoffelen at donders.ru.nl<mailto:jan.schoffelen at donders.ru.nl>>
Sent: Wednesday, July 1, 2020 4:45 PM
To: FieldTrip discussion list <fieldtrip at science.ru.nl<mailto:fieldtrip at science.ru.nl>>
Subject: Re: [FieldTrip] Potential bug using ft_dipolefitting with fieldtrip-20200623

Dear Martin,

Thanks for your message. Sorry to hear that you experience some issues. ft_dipolefitting has received a facelift recently, so it could be that the issue you report is a genuine problem. On the other hand, it could also be that something unexpected happens due to an unexpected feature in your data, which causes an error in the changed code. Our battery of test functions apparently ran through just fine, causing the changed function to percolate into the relase version of the codebase. Yet, our tests are not exhaustive, and it could be that there are user scenarios that we haven’t thought of.

In order to be able to make the distinction between a genuine bug, and an interaction between features-of-the-specific-usecase and the updated code, could you investigate a bit more what’s going on, using the matlab debugger? If you put a breakpoint in the code on line 442 (or so), or type ‘dbstop if error’ on the matlab command line, and then execute ft_dipolefitting again, you should be able to investigate the content of the variables. Specifically, it would be interesting to know what the content is of the ‘sourcemodel' variable, as well as whether the variable ‘indx’ is properly created on line 442.

Alternatively, you could send us some data (essentially the timelockds{4} + leadfield_eeg + headmodel_eeg which would allow us to reproduce the issue and, if needed, make a fix.

Best wishes,
Jan-Mathijs


On 1 Jul 2020, at 13:35, Martin Schaefer <martin.schaefer at ki.se<mailto:martin.schaefer at ki.se>> wrote:

Dear all,

I ran into the following error message when calling the ft_dipolefitting function on my data:

Error using reshape
Number of elements must not change. Use [] as one of the size inputs to automatically calculate the appropriate size for that dimension.

Error in ft_dipolefitting (line 444)
      dip.pos = reshape(dip.pos,3,cfg.numdipoles)';     % convert to a Nx3 array

Error in dipole_fitting (line 152)
dipole_eeg_late = ft_dipolefitting(cfg, timelockeds{4});

My cfg commands:
cfg = [];
cfg.gridsearch         = 'yes';
cfg.numdipoles      = 1;
cfg.symmetry         = [];
cfg.grid                    = leadfield_eeg;
cfg.headmodel      = headmodel_eeg;
cfg.dipfit.metric    = 'rv';
cfg.model               = 'regional';
cfg.senstype          = 'eeg';
cfg.channel           = 'all';
cfg.nonlinear        = 'yes';
cfg.latency             = early_latency;
cfg.backproject     = 'yes';

dipole_eeg_early = ft_dipolefitting(cfg, timelockeds{4});


However, the code runs fine on an older version of fieldtrip (the one used during the last online fieldtrip workshop, I think it is from 16-04-2020).

So I'm not sure whether there is a bug in one of the versions or something else is wrong.
Does anyone else have issues with this?

Best regards,
Martin

------------
Martin Schaefer | PhD Student
https://www.perceptionlab.se/<https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.perceptionlab.se%2F&data=02%7C01%7Cmartin.schaefer%40ki.se%7C268947d09a27414b01c008d81dcd9bba%7Cbff7eef1cf4b4f32be3da1dda043c05d%7C0%7C0%7C637292116200198856&sdata=w9gFEvzSeKwxySOWwnCbR9%2F%2BzWXWeBTjVi1KFq9oJUY%3D&reserved=0>
Department of Clinical Neuroscience (CNS), K8
Karolinska Institutet | 17 177 Stockholm | Nobels väg 9
martin.schaefer at ki.se<mailto:artin.arshamian at ki.se>
______________________________________
Karolinska Institutet – a Medical University



När du skickar e-post till Karolinska Institutet (KI) innebär detta att KI kommer att behandla dina personuppgifter. Här finns information om hur KI behandlar personuppgifter<https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fki.se%2Fmedarbetare%2Fintegritetsskyddspolicy&data=02%7C01%7Cmartin.schaefer%40ki.se%7C268947d09a27414b01c008d81dcd9bba%7Cbff7eef1cf4b4f32be3da1dda043c05d%7C0%7C0%7C637292116200198856&sdata=76Of3%2BtLi%2Bzl1prxLy9H0TyY73mCg9kZ6Q%2BfDiTK5Kg%3D&reserved=0>.

Sending email to Karolinska Institutet (KI) will result in KI processing your personal data. You can read more about KI’s processing of personal data here<https://ki.se/en/staff/data-protection-policy>.
_______________________________________________
fieldtrip mailing list
https://mailman.science.ru.nl/mailman/listinfo/fieldtrip<https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fmailman.science.ru.nl%2Fmailman%2Flistinfo%2Ffieldtrip&data=02%7C01%7Cmartin.schaefer%40ki.se%7C268947d09a27414b01c008d81dcd9bba%7Cbff7eef1cf4b4f32be3da1dda043c05d%7C0%7C0%7C637292116200208851&sdata=9kimEP3jV2bmlS5CpYcqxlK8%2BzedF4XM4pAyH8%2FL8Zs%3D&reserved=0>
https://doi.org/10.1371/journal.pcbi.1002202<https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fdoi.org%2F10.1371%2Fjournal.pcbi.1002202&data=02%7C01%7Cmartin.schaefer%40ki.se%7C268947d09a27414b01c008d81dcd9bba%7Cbff7eef1cf4b4f32be3da1dda043c05d%7C0%7C0%7C637292116200208851&sdata=F5vmA1DY7S9UMGt1Y94bw%2Bxt9NOn3oGatMKPIZ3zEMU%3D&reserved=0>

<sourcemodel.png>_______________________________________________
fieldtrip mailing list
https://mailman.science.ru.nl/mailman/listinfo/fieldtrip
https://doi.org/10.1371/journal.pcbi.1002202

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.science.ru.nl/pipermail/fieldtrip/attachments/20200702/95676ef8/attachment.htm>


More information about the fieldtrip mailing list