非官方中文翻译 本页译自 MNE-Python 官方文档: 查看英文原文 ↗。 文档版权归 MNE Developers 所有(BSD-3-Clause)。

比较 MNE 中不同的 ICA 算法#

对原始 MEG 数据拟合不同的 ICA 算法,并显示相应的成分图。

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

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

print(__doc__)

读取并预处理数据。预处理包括:

  • 选择 MEG 通道

  • 1–30 Hz 带通滤波

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.
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 s)
General
Filename(s) sample_audvis_filt-0-40_raw.fif
MNE object type Raw
Measurement date 2002-12-03 at 19:01:10 UTC
Participant Unknown
Experimenter Unknown
Acquisition
Duration 00:01:01 (HH:MM:SS)
Sampling frequency 150.15 Hz
Time points 9,010
Channels
Magnetometers
Gradiometers and
Head & sensor digitization 146 points
Filters
Highpass 1.00 Hz
Lowpass 30.00 Hz
Projections PCA-v1 (off)
PCA-v2 (off)
PCA-v3 (off)


定义一个函数,在原始 MEG 数据上运行 ICA 并绘制成分

def run_ica(method, fit_params=None):
    ica = ICA(
        n_components=20,
        method=method,
        fit_params=fit_params,
        max_iter="auto",
        rng=29,
    )
    t0 = time()
    ica.fit(raw, reject=reject)
    fit_time = time() - t0
    title = f"ICA decomposition using {method} (took {fit_time:.1f}s)"
    ica.plot_components(title=title)

FastICA

run_ica("fastica")
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.3s.

Picard

run_ica("picard")
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.3s.

Infomax

run_ica("infomax")
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 Infomax ICA
Fitting ICA took 0.6s.

Extended Infomax

run_ica("infomax", fit_params=dict(extended=True))
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.3s.

脚本总运行时间:(0 分 12.268 秒)

图库由 Sphinx-Gallery 生成