[Mne_analysis] [External] Mne_analysis Digest, Vol 138, Issue 5

Mainak Jas mainakjas at gmail.com
Mon Jul 8 01:10:53 EDT 2019
Search archives:

        External Email - Use Caution        

Hi Jason,

Have you looked at this example:
https://martinos.org/mne/dev/auto_tutorials/time-freq/plot_sensors_time_frequency.html#time-frequency-analysis-power-and-inter-trial-coherence

Does it help?

Best,
Mainak

On Sat, Jul 6, 2019 at 11:47 AM Geller, Jason <jason-geller at uiowa.edu>
wrote:

>         External Email - Use Caution
>
> Hello,
>
> I am trying to calculate inter-trial coherence (itc) for a project. Does
> anyone know of an easy way to calculate the average itc over several
> channels? It is not clear to me how do this over a 3D array in Python. Any
> help would be greatly appreciated.
>
> Thanks,
>
> Jason
>
> Get Outlook for iOS <https://aka.ms/o0ukef>
> ------------------------------
> *From:* mne_analysis-bounces at nmr.mgh.harvard.edu <
> mne_analysis-bounces at nmr.mgh.harvard.edu> on behalf of
> mne_analysis-request at nmr.mgh.harvard.edu <
> mne_analysis-request at nmr.mgh.harvard.edu>
> *Sent:* Wednesday, July 3, 2019 4:40:57 PM
> *To:* mne_analysis at nmr.mgh.harvard.edu
> *Subject:* [External] Mne_analysis Digest, Vol 138, Issue 5
>
> Send Mne_analysis mailing list submissions to
>         mne_analysis at nmr.mgh.harvard.edu
>
> To subscribe or unsubscribe via the World Wide Web, visit
>         https://mail.nmr.mgh.harvard.edu/mailman/listinfo/mne_analysis
> or, via email, send a message with subject or body 'help' to
>         mne_analysis-request at nmr.mgh.harvard.edu
>
> You can reach the person managing the list at
>         mne_analysis-owner at nmr.mgh.harvard.edu
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Mne_analysis digest..."
>
>
> Today's Topics:
>
>    1. Re: Applying ICA with No Components Selected out but Signal
>       Changes Using Default Parameters (Alexandre Gramfort)
>    2. Re: Applying ICA with No Components Selected out but Signal
>       Changes Using Default Parameters (Mainak Jas)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Wed, 3 Jul 2019 22:22:50 +0200
> From: Alexandre Gramfort <alexandre.gramfort at inria.fr>
> Subject: Re: [Mne_analysis] Applying ICA with No Components Selected
>         out but Signal Changes Using Default Parameters
> To: Discussion and support forum for the users of MNE Software
>         <mne_analysis at nmr.mgh.harvard.edu>
> Message-ID:
>         <
> CADeotZpCnNZypyjXfYeoyxvdDMf-Hn9CapPwYvy3zE30T1VKww at mail.gmail.com>
> Content-Type: text/plain; charset="utf-8"
>
>         External Email - Use Caution
>
> Hi Alex,
>
> I could replicate the pb and start to investigate.
>
> You have a strong transient artifact in your data (stim artifact I suspect)
> and this affects the conditioning of the mixing matrix. So when computing
> the pinv here:
> https://github.com/mne-tools/mne-python/blob/master/mne/preprocessing/ica.py#L677
> the mixing is not numerically the inverse of the unmixing matrix.
>
> I don't know exactly how to fix this but that's a starting point.
> He someone can look into this it's great.
>
> Alex
>
> On Wed, Jul 3, 2019 at 3:33 PM Rockhill, Alexander P.
> <AROCKHILL at mgh.harvard.edu> wrote:
> >
> > Hi Alex and Mainak,
> >
> >     The n_components argument is given None which yields 57 components
> and there are 64 channels with 7 bad channels which are not included so no
> I don't think it's because of the dimensionality reduction. Maybe it's some
> whitening.
> >
> > To see something similar to what I'm looking at as far as scaling you
> can use the script below but I haven't been able to replicate the changes
> after ICA with sample data. I filedropped you both test epochs to the
> emails you responded to the thread with that does show that.
> >
> > from time import time
> > import matplotlib.pyplot as plt
> > import mne
> > from mne.preprocessing import ICA
> > from mne.datasets import sample
> >
> > '''data_path = sample.data_path()
> > raw_fname = data_path + '/MEG/sample/sample_audvis-raw.fif'
> >
> > raw = mne.io.Raw(raw_fname, preload=True)
> > events = mne.find_events(raw)
> > epochs = mne.Epochs(raw, events, preload=True)
> >
> > '''
> > epochs = mne.read_epochs('test-epo.fif', preload=True)
> >
> > epochs = epochs.pick_types(meg=False, eeg=True)
> >
> > fig, (ax0, ax1) = plt.subplots(1,2)
> > epochs.average().plot(axes=ax0, show=False)
> >
> > ica = ICA(method='fastica', random_state=0)
> > t0 = time()
> > ica.fit(epochs)
> > fit_time = time() - t0
> > epochs = ica.apply(epochs, exclude=ica.exclude)
> > epochs.average().plot(axes=ax1, show=False)
> > ica.plot_sources(epochs)
> >
> > Thanks,
> >
> > Alex
> >
> > Translational NeuroEngineering Laboratory
> > Division of Neurotherapeutics, Department of Psychiatry
> > Massachusetts General Hospital, Martinos Center
> > 149 13th St Charlestown #2301, Boston, MA 02129
> > ________________________________
> > From: mne_analysis-bounces at nmr.mgh.harvard.edu <
> mne_analysis-bounces at nmr.mgh.harvard.edu> on behalf of Alexandre Gramfort
> <alexandre.gramfort at inria.fr>
> > Sent: Wednesday, July 3, 2019 2:30 AM
> > To: Discussion and support forum for the users of MNE Software
> > Subject: Re: [Mne_analysis] Applying ICA with No Components Selected out
> but Signal Changes Using Default Parameters
> >
> >
> >         External Email - Use Caution
> >
> > hi,
> >
> > can you check that the number of components you fit is equal to the
> number of channels?
> > If it's less you have a dimensionality reduction step.
> >
> > Alex
> >
> >
> > On Tue, Jul 2, 2019 at 11:28 PM Mainak Jas <mainakjas at gmail.com> wrote:
> >
> >         External Email - Use Caution
> >
> > Hi Alex,
> >
> > Could you provide us a full script on the MNE sample data that we can
> run?
> >
> > Mainak
> >
> > On Tue, Jul 2, 2019 at 5:14 PM Rockhill, Alexander P. <
> AROCKHILL at mgh.harvard.edu> wrote:
> >
> > Also, of note the ica scale is off by quite a lot in the plot_sources
> plot, it is way too zoomed in.
> >
> > Alex
> >
> > Translational NeuroEngineering Laboratory
> > Division of Neurotherapeutics, Department of Psychiatry
> > Massachusetts General Hospital, Martinos Center
> > 149 13th St Charlestown #2301, Boston, MA 02129
> > ________________________________
> > From: mne_analysis-bounces at nmr.mgh.harvard.edu <
> mne_analysis-bounces at nmr.mgh.harvard.edu> on behalf of Rockhill,
> Alexander P. <AROCKHILL at mgh.harvard.edu>
> > Sent: Tuesday, July 2, 2019 3:25 PM
> > To: mne_analysis at nmr.mgh.harvard.edu
> > Subject: [Mne_analysis] Applying ICA with No Components Selected out but
> Signal Changes Using Default Parameters
> >
> > Hi,
> >
> >     In an analysis, I am running:
> >
> > ica = ICA(method='fastica', n_components=n_components,  #
> n_components=None
> >           random_state=seed)
> > ica.fit(inst2)
> > ...
> > inst2 = ica.apply(inst2, exclude=ica.exclude)
> >
> >     and when I skip all intermediate steps and just fit the ICA and
> apply it with an empty list for ica.exclude the signal still changes, quite
> a bit. I thought if no components were selected out and all the max PCA
> components were used the signal would be unchanged or basically unchanged.
> Is this a bug or something with my implementation?
> >
> > Thanks,
> >
> > Alex
> >
> > Translational NeuroEngineering Laboratory
> > Division of Neurotherapeutics, Department of Psychiatry
> > Massachusetts General Hospital, Martinos Center
> > 149 13th St Charlestown #2301, Boston, MA 02129
> > _______________________________________________
> > Mne_analysis mailing list
> > Mne_analysis at nmr.mgh.harvard.edu
> > https://mail.nmr.mgh.harvard.edu/mailman/listinfo/mne_analysis
> >
> > _______________________________________________
> > Mne_analysis mailing list
> > Mne_analysis at nmr.mgh.harvard.edu
> > https://mail.nmr.mgh.harvard.edu/mailman/listinfo/mne_analysis
> >
> > _______________________________________________
> > Mne_analysis mailing list
> > Mne_analysis at nmr.mgh.harvard.edu
> > https://mail.nmr.mgh.harvard.edu/mailman/listinfo/mne_analysis
>
>
>
> ------------------------------
>
> Message: 2
> Date: Wed, 3 Jul 2019 16:40:41 -0400
> From: Mainak Jas <mainakjas at gmail.com>
> Subject: Re: [Mne_analysis] Applying ICA with No Components Selected
>         out but Signal Changes Using Default Parameters
> To: Discussion and support forum for the users of MNE Software
>         <mne_analysis at nmr.mgh.harvard.edu>
> Message-ID:
>         <CANzrpG1ubBi7EQdykvAPA_q3=1MGv8MFJmhrpOyx=
> X8FDBnitg at mail.gmail.com>
> Content-Type: text/plain; charset="utf-8"
>
>         External Email - Use Caution
>
> I can confirm what Alex said. Here?s a simpler script to play with:
>
> import mnefrom mne.preprocessing import ICA
> from numpy.testing import assert_array_equal
>
> epochs = mne.read_epochs('test-epo.fif', preload=True)
>
> epochs.pick_types(meg=False, eeg=True)
> epochs.crop(0.2, None)
>
> epochs2 = epochs.copy()
>
> reject = dict(eeg=200e-6)
> ica = ICA(method='fastica', random_state=42, max_iter=500,
> n_components=0.95)
> ica.fit(epochs.copy().drop_bad(reject=reject), decim=10)
>
> ica.apply(epochs2, exclude=[])
>
> epochs.average().plot()
> epochs2.average().plot()
> # from mne import combine_evoked# evoked_diff =
> combine_evoked([epochs.average(), -epochs2.average()], 'equal')#
> evoked_diff.plot()
>
> assert_array_equal(epochs.get_data(), epochs2.get_data())
>
> Using n_components=0.95 vs n_components=1.0 actually seems to make a huge
> difference, perhaps for the reasons that Alex outlines. Ultimately, what
> you reconstruct depends on the quality of your decomposition -- and it's
> not perfect.
>
> Best,
> Mainak
>
> On Wed, Jul 3, 2019 at 4:23 PM Alexandre Gramfort <
> alexandre.gramfort at inria.fr> wrote:
>
> >         External Email - Use Caution
> >
> > Hi Alex,
> >
> > I could replicate the pb and start to investigate.
> >
> > You have a strong transient artifact in your data (stim artifact I
> suspect)
> > and this affects the conditioning of the mixing matrix. So when computing
> > the pinv here:
> >
> https://github.com/mne-tools/mne-python/blob/master/mne/preprocessing/ica.py#L677
> > the mixing is not numerically the inverse of the unmixing matrix.
> >
> > I don't know exactly how to fix this but that's a starting point.
> > He someone can look into this it's great.
> >
> > Alex
> >
> > On Wed, Jul 3, 2019 at 3:33 PM Rockhill, Alexander P.
> > <AROCKHILL at mgh.harvard.edu> wrote:
> > >
> > > Hi Alex and Mainak,
> > >
> > >     The n_components argument is given None which yields 57 components
> > and there are 64 channels with 7 bad channels which are not included so
> no
> > I don't think it's because of the dimensionality reduction. Maybe it's
> some
> > whitening.
> > >
> > > To see something similar to what I'm looking at as far as scaling you
> > can use the script below but I haven't been able to replicate the changes
> > after ICA with sample data. I filedropped you both test epochs to the
> > emails you responded to the thread with that does show that.
> > >
> > > from time import time
> > > import matplotlib.pyplot as plt
> > > import mne
> > > from mne.preprocessing import ICA
> > > from mne.datasets import sample
> > >
> > > '''data_path = sample.data_path()
> > > raw_fname = data_path + '/MEG/sample/sample_audvis-raw.fif'
> > >
> > > raw = mne.io.Raw(raw_fname, preload=True)
> > > events = mne.find_events(raw)
> > > epochs = mne.Epochs(raw, events, preload=True)
> > >
> > > '''
> > > epochs = mne.read_epochs('test-epo.fif', preload=True)
> > >
> > > epochs = epochs.pick_types(meg=False, eeg=True)
> > >
> > > fig, (ax0, ax1) = plt.subplots(1,2)
> > > epochs.average().plot(axes=ax0, show=False)
> > >
> > > ica = ICA(method='fastica', random_state=0)
> > > t0 = time()
> > > ica.fit(epochs)
> > > fit_time = time() - t0
> > > epochs = ica.apply(epochs, exclude=ica.exclude)
> > > epochs.average().plot(axes=ax1, show=False)
> > > ica.plot_sources(epochs)
> > >
> > > Thanks,
> > >
> > > Alex
> > >
> > > Translational NeuroEngineering Laboratory
> > > Division of Neurotherapeutics, Department of Psychiatry
> > > Massachusetts General Hospital, Martinos Center
> > > 149 13th St Charlestown #2301, Boston, MA 02129
> > > ________________________________
> > > From: mne_analysis-bounces at nmr.mgh.harvard.edu <
> > mne_analysis-bounces at nmr.mgh.harvard.edu> on behalf of Alexandre
> Gramfort
> > <alexandre.gramfort at inria.fr>
> > > Sent: Wednesday, July 3, 2019 2:30 AM
> > > To: Discussion and support forum for the users of MNE Software
> > > Subject: Re: [Mne_analysis] Applying ICA with No Components Selected
> out
> > but Signal Changes Using Default Parameters
> > >
> > >
> > >         External Email - Use Caution
> > >
> > > hi,
> > >
> > > can you check that the number of components you fit is equal to the
> > number of channels?
> > > If it's less you have a dimensionality reduction step.
> > >
> > > Alex
> > >
> > >
> > > On Tue, Jul 2, 2019 at 11:28 PM Mainak Jas <mainakjas at gmail.com>
> wrote:
> > >
> > >         External Email - Use Caution
> > >
> > > Hi Alex,
> > >
> > > Could you provide us a full script on the MNE sample data that we can
> > run?
> > >
> > > Mainak
> > >
> > > On Tue, Jul 2, 2019 at 5:14 PM Rockhill, Alexander P. <
> > AROCKHILL at mgh.harvard.edu> wrote:
> > >
> > > Also, of note the ica scale is off by quite a lot in the plot_sources
> > plot, it is way too zoomed in.
> > >
> > > Alex
> > >
> > > Translational NeuroEngineering Laboratory
> > > Division of Neurotherapeutics, Department of Psychiatry
> > > Massachusetts General Hospital, Martinos Center
> > > 149 13th St Charlestown #2301, Boston, MA 02129
> > > ________________________________
> > > From: mne_analysis-bounces at nmr.mgh.harvard.edu <
> > mne_analysis-bounces at nmr.mgh.harvard.edu> on behalf of Rockhill,
> > Alexander P. <AROCKHILL at mgh.harvard.edu>
> > > Sent: Tuesday, July 2, 2019 3:25 PM
> > > To: mne_analysis at nmr.mgh.harvard.edu
> > > Subject: [Mne_analysis] Applying ICA with No Components Selected out
> but
> > Signal Changes Using Default Parameters
> > >
> > > Hi,
> > >
> > >     In an analysis, I am running:
> > >
> > > ica = ICA(method='fastica', n_components=n_components,  #
> > n_components=None
> > >           random_state=seed)
> > > ica.fit(inst2)
> > > ...
> > > inst2 = ica.apply(inst2, exclude=ica.exclude)
> > >
> > >     and when I skip all intermediate steps and just fit the ICA and
> > apply it with an empty list for ica.exclude the signal still changes,
> quite
> > a bit. I thought if no components were selected out and all the max PCA
> > components were used the signal would be unchanged or basically
> unchanged.
> > Is this a bug or something with my implementation?
> > >
> > > Thanks,
> > >
> > > Alex
> > >
> > > Translational NeuroEngineering Laboratory
> > > Division of Neurotherapeutics, Department of Psychiatry
> > > Massachusetts General Hospital, Martinos Center
> > > 149 13th St Charlestown #2301, Boston, MA 02129
> > > _______________________________________________
> > > Mne_analysis mailing list
> > > Mne_analysis at nmr.mgh.harvard.edu
> > > https://mail.nmr.mgh.harvard.edu/mailman/listinfo/mne_analysis
> > >
> > > _______________________________________________
> > > Mne_analysis mailing list
> > > Mne_analysis at nmr.mgh.harvard.edu
> > > https://mail.nmr.mgh.harvard.edu/mailman/listinfo/mne_analysis
> > >
> > > _______________________________________________
> > > Mne_analysis mailing list
> > > Mne_analysis at nmr.mgh.harvard.edu
> > > https://mail.nmr.mgh.harvard.edu/mailman/listinfo/mne_analysis
> >
> > _______________________________________________
> > Mne_analysis mailing list
> > Mne_analysis at nmr.mgh.harvard.edu
> > https://mail.nmr.mgh.harvard.edu/mailman/listinfo/mne_analysis
> >
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL:
> http://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/attachments/20190703/ad2a76b3/attachment.html
>
> ------------------------------
>
> _______________________________________________
> Mne_analysis mailing list
> Mne_analysis at nmr.mgh.harvard.edu
> https://mail.nmr.mgh.harvard.edu/mailman/listinfo/mne_analysis
>
> End of Mne_analysis Digest, Vol 138, Issue 5
> ********************************************
> _______________________________________________
> Mne_analysis mailing list
> Mne_analysis at nmr.mgh.harvard.edu
> https://mail.nmr.mgh.harvard.edu/mailman/listinfo/mne_analysis
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/attachments/20190708/658b0595/attachment-0001.html 


More information about the Mne_analysis mailing list