[FieldTrip] Trial by Trial Source Reconstruction for Decoding

Schoffelen, J.M. (Jan Mathijs) janmathijs.schoffelen at donders.ru.nl
Wed Apr 26 08:10:01 CEST 2023


Hi Benjy,

I would recommend against using the ‘rawtrial’ option. This in retrospect is a poorly implemented functionality in FieldTrip and does not work well (if at all) in concrete situations.

I would recommend to use ft_virtualchannel to obtain your single trial time courses. I think that this has been discussed at other threads in this discussion forum, so it should be possible to find some information about this.

Also, if your intention is to be able to classify zero from notzero trials, you will probably fool yourself if you NOT compute the covariance across all trials combined, and do a single call to ft_sourceanalysis to obtain a set of common spatial filters. Currently, your pasted code computes the covariance and spatial filters per condition, which will already serve as a booster to make the 2 conditions more dissimilar.

Good luck,
Jan-Mathijs


On 25 Apr 2023, at 14:32, Barnett, Benjy via fieldtrip <fieldtrip at science.ru.nl<mailto:fieldtrip at science.ru.nl>> wrote:

Sorry for multiple posting, please ignore - I have just noticed the cfg.rawtrials option in ft_sourceanalysis, which makes this much simpler.

Thank you

On Apr 25, 2023, at 1:12 PM, Barnett, Benjy via fieldtrip <fieldtrip at science.ru.nl<mailto:fieldtrip at science.ru.nl>> wrote:


⚠ Caution: External sender

Hi all,

I’m trying to implement some MVPA decoding analyses in source space using MEG data collected on a CTF system. I have gone through different tutorials to perform the source reconstruction (namely https://urldefense.com/v3/__https://www.fieldtriptoolbox.org/workshop/aarhus/beamformingerf/__;!!HJOPV4FYYWzcc1jazlU!4cSRAdA5lfctmjIb3wJ6BEPS-Ph4hKydOKFStlmspDg5prKPEMNUxCDuA1754_sycJjwL16-vsvkuKoOpvzD73CtWcD5qIY0QiCPKA$ <https://urldefense.com/v3/__https://www.fieldtriptoolbox.org/workshop/aarhus/beamformingerf/__;!!HJOPV4FYYWzcc1jazlU!6dJY9xn9eTEqqGoXULa_OMBzAvS3Cl7jDWxpxhESR-a61x1hEJWt38h4sKsVfLMoG9DIkPTj6qamNi18fKgf9dtYDIaRLfHvTw$>; https://urldefense.com/v3/__https://www.fieldtriptoolbox.org/workshop/paris2019/handson_sourceanalysis/__;!!HJOPV4FYYWzcc1jazlU!4cSRAdA5lfctmjIb3wJ6BEPS-Ph4hKydOKFStlmspDg5prKPEMNUxCDuA1754_sycJjwL16-vsvkuKoOpvzD73CtWcD5qIZWVDQ7mA$ <https://urldefense.com/v3/__https://www.fieldtriptoolbox.org/workshop/paris2019/handson_sourceanalysis/__;!!HJOPV4FYYWzcc1jazlU!6dJY9xn9eTEqqGoXULa_OMBzAvS3Cl7jDWxpxhESR-a61x1hEJWt38h4sKsVfLMoG9DIkPTj6qamNi18fKgf9dtYDIZKqhJFug$>).

To train my decoder, I will obviously need trial by trial activity estimates for each of the virtual channels. The issue is that these tutorials, and most other information I can find, only go into how to extract condition-level source estimates. I have an idea of how to do this for individual trials, but it’s such a shift from the tutorials I wondered if I could check whether my plan will work conceptually and technically.

My current code (to obtain condition level estimates) is as follows:

    % Compute Covariance Matrix
    cfg = [];
    cfg.covariance = 'yes';
    avg = ft_timelockanalysis(cfg,meg_data); %meg_data = datazero + datanotzero;

    cfg.keeptrials = 'yes';
    avgzero = ft_timelockanalysis(cfg,datazero); %condition 1 = ‘zero'
    avgnotzero = ft_timelockanalysis(cfg,datanotzero); %condition 2 = ’not zero'

    %Calculate spatial filter for each voxel over all data
    cfg = [];
    cfg.method = 'lcmv';
    cfg.sourcemodel = sourcemodel_new;
    cfg.headmodel = headmodel_new;
    cfg.lcmv.keepfilter = 'yes';
    cfg.lcmv.lambda = '5%';
    cfg.lcmv.weightnorm = 'unitnoisegain';
    cfg.lcmv.fixedori = 'yes';
    cfg.channel = {'MEG'};
    cfg.senstype = 'MEG';
    sourceavg = ft_sourceanalysis(cfg, avg); %compute filters over all trials

    %Now apply this filter to zero and not-zero data separately
    cfg = [];
    cfg.method = 'lcmv';
    cfg.sourcemodel = sourcemodel_new;
    cfg.sourcemodel.filter = sourceavg.avg.filter;
    cfg.headmodel = headmodel_new;
    sourcezero = ft_sourceanalysis(cfg, avgzero);
    sourcenotzero = ft_sourceanalysis(cfg, avgnotzero);

Would I be correct to simply alter this pipeline so that I perform the call to ft_timelockanalysis and estimate the covariance matrix for each trial individually, rather than each condition? Then I was planning to simply run the ft_sourceanalysis function on each of these trials individually, keeping track of which trial belongs to which condition for later use in decoding. I can then go into the source output from the sourceanalysis and extract the .mom field to get the virtual channel data per trial, which I plan to then enter into the decoder.

Does this make sense conceptually? It seems a logical step from the beamforming of condition level signals, but I’ve come to learn it’s rarely that simple!

I hope that all makes sense,

Benjy
_______________________________________________
fieldtrip mailing list
https://mailman.science.ru.nl/mailman/listinfo/fieldtrip
https://urldefense.com/v3/__https://doi.org/10.1371/journal.pcbi.1002202__;!!HJOPV4FYYWzcc1jazlU!4cSRAdA5lfctmjIb3wJ6BEPS-Ph4hKydOKFStlmspDg5prKPEMNUxCDuA1754_sycJjwL16-vsvkuKoOpvzD73CtWcD5qIaIbWPhPg$ <https://urldefense.com/v3/__https://doi.org/10.1371/journal.pcbi.1002202__;!!HJOPV4FYYWzcc1jazlU!4HiCPnTY4ZHLBQO-35S-qTzf4nEOOD1IKhyJGLDYrHsrcjodns47ZrpV1HfVBgHidCK45KCLe79g6tzsGhQWqnFMt5BvVIyIiw$>

_______________________________________________
fieldtrip mailing list
https://mailman.science.ru.nl/mailman/listinfo/fieldtrip
https://urldefense.com/v3/__https://doi.org/10.1371/journal.pcbi.1002202__;!!HJOPV4FYYWzcc1jazlU!9VKw5aAkcqyFPaSPE2qsPhnkgzk6tmjf-ll1wgLUr-bAskClg_DnP0eVgOlsbQ8Ez8ewmq9_2rsSSisJDFRupORjwY_Y-1owr6Dtww$

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.science.ru.nl/pipermail/fieldtrip/attachments/20230426/8e54a04e/attachment.htm>


More information about the fieldtrip mailing list