Compare the different ICA algorithms in MNE#

Different ICA algorithms are fit to raw MEG data, and the corresponding maps are displayed.

# Authors: Pierre Ablin <pierreablin@gmail.com>
#
# License: BSD-3-Clause
from time import time

import mne
from mne.preprocessing import ICA
from mne.datasets import sample


print(__doc__)

Read and preprocess the data. Preprocessing consists of:

  • MEG channel selection

  • 1-30 Hz band-pass filter

data_path = sample.data_path()
meg_path = data_path / 'MEG' / 'sample'
raw_fname = meg_path / 'sample_audvis_filt-0-40_raw.fif'

raw = mne.io.read_raw_fif(raw_fname).crop(0, 60).pick('meg').load_data()

reject = dict(mag=5e-12, grad=4000e-13)
raw.filter(1, 30, fir_design='firwin')
Opening raw data file /home/circleci/mne_data/MNE-sample-data/MEG/sample/sample_audvis_filt-0-40_raw.fif...
    Read a total of 4 projection items:
        PCA-v1 (1 x 102)  idle
        PCA-v2 (1 x 102)  idle
        PCA-v3 (1 x 102)  idle
        Average EEG reference (1 x 60)  idle
    Range : 6450 ... 48149 =     42.956 ...   320.665 secs
Ready.
Removing projector <Projection | Average EEG reference, active : False, n_channels : 60>
Reading 0 ... 9009  =      0.000 ...    59.999 secs...
Filtering raw data in 1 contiguous segment
Setting up band-pass filter from 1 - 30 Hz

FIR filter parameters
---------------------
Designing a one-pass, zero-phase, non-causal bandpass filter:
- Windowed time-domain design (firwin) method
- Hamming window with 0.0194 passband ripple and 53 dB stopband attenuation
- Lower passband edge: 1.00
- Lower transition bandwidth: 1.00 Hz (-6 dB cutoff frequency: 0.50 Hz)
- Upper passband edge: 30.00 Hz
- Upper transition bandwidth: 7.50 Hz (-6 dB cutoff frequency: 33.75 Hz)
- Filter length: 497 samples (3.310 sec)

[Parallel(n_jobs=1)]: Using backend SequentialBackend with 1 concurrent workers.
[Parallel(n_jobs=1)]: Done   1 out of   1 | elapsed:    0.0s remaining:    0.0s
[Parallel(n_jobs=1)]: Done   2 out of   2 | elapsed:    0.0s remaining:    0.0s
[Parallel(n_jobs=1)]: Done   3 out of   3 | elapsed:    0.0s remaining:    0.0s
[Parallel(n_jobs=1)]: Done   4 out of   4 | elapsed:    0.0s remaining:    0.0s
[Parallel(n_jobs=1)]: Done 306 out of 306 | elapsed:    0.2s finished
Measurement date December 03, 2002 19:01:10 GMT
Experimenter Unknown
Participant Unknown
Digitized points 146 points
Good channels 204 Gradiometers, 102 Magnetometers
Bad channels MEG 2443
EOG channels Not available
ECG channels Not available
Sampling frequency 150.15 Hz
Highpass 1.00 Hz
Lowpass 30.00 Hz
Projections PCA-v1 : off
PCA-v2 : off
PCA-v3 : off
Filenames sample_audvis_filt-0-40_raw.fif
Duration 00:00:59 (HH:MM:SS)


Define a function that runs ICA on the raw MEG data and plots the components

def run_ica(method, fit_params=None):
    ica = ICA(n_components=20, method=method, fit_params=fit_params,
              max_iter='auto', random_state=0)
    t0 = time()
    ica.fit(raw, reject=reject)
    fit_time = time() - t0
    title = ('ICA decomposition using %s (took %.1fs)' % (method, fit_time))
    ica.plot_components(title=title)

FastICA

run_ica('fastica')
ICA decomposition using fastica (took 0.7s), ICA000 (mag), ICA001 (mag), ICA002 (mag), ICA003 (mag), ICA004 (mag), ICA005 (mag), ICA006 (mag), ICA007 (mag), ICA008 (mag), ICA009 (mag), ICA010 (mag), ICA011 (mag), ICA012 (mag), ICA013 (mag), ICA014 (mag), ICA015 (mag), ICA016 (mag), ICA017 (mag), ICA018 (mag), ICA019 (mag)
Fitting ICA to data using 305 channels (please be patient, this may take a while)
Selecting by number: 20 components
Fitting ICA took 0.6s.

Picard

run_ica('picard')
ICA decomposition using picard (took 2.5s), ICA000 (mag), ICA001 (mag), ICA002 (mag), ICA003 (mag), ICA004 (mag), ICA005 (mag), ICA006 (mag), ICA007 (mag), ICA008 (mag), ICA009 (mag), ICA010 (mag), ICA011 (mag), ICA012 (mag), ICA013 (mag), ICA014 (mag), ICA015 (mag), ICA016 (mag), ICA017 (mag), ICA018 (mag), ICA019 (mag)
Fitting ICA to data using 305 channels (please be patient, this may take a while)
Selecting by number: 20 components
Fitting ICA took 2.4s.

Infomax

run_ica('infomax')
ICA decomposition using infomax (took 1.7s), ICA000 (mag), ICA001 (mag), ICA002 (mag), ICA003 (mag), ICA004 (mag), ICA005 (mag), ICA006 (mag), ICA007 (mag), ICA008 (mag), ICA009 (mag), ICA010 (mag), ICA011 (mag), ICA012 (mag), ICA013 (mag), ICA014 (mag), ICA015 (mag), ICA016 (mag), ICA017 (mag), ICA018 (mag), ICA019 (mag)
Fitting ICA to data using 305 channels (please be patient, this may take a while)
Selecting by number: 20 components

Fitting ICA took 1.7s.

Extended Infomax

run_ica('infomax', fit_params=dict(extended=True))
ICA decomposition using infomax (took 2.9s), ICA000 (mag), ICA001 (mag), ICA002 (mag), ICA003 (mag), ICA004 (mag), ICA005 (mag), ICA006 (mag), ICA007 (mag), ICA008 (mag), ICA009 (mag), ICA010 (mag), ICA011 (mag), ICA012 (mag), ICA013 (mag), ICA014 (mag), ICA015 (mag), ICA016 (mag), ICA017 (mag), ICA018 (mag), ICA019 (mag)
Fitting ICA to data using 305 channels (please be patient, this may take a while)
Selecting by number: 20 components
Computing Extended Infomax ICA
Fitting ICA took 2.9s.

Total running time of the script: ( 0 minutes 28.440 seconds)

Estimated memory usage: 11 MB

Gallery generated by Sphinx-Gallery