本文整理汇总了Python中mne.preprocessing.ICA类的典型用法代码示例。如果您正苦于以下问题:Python ICA类的具体用法?Python ICA怎么用?Python ICA使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ICA类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_ica_rank_reduction
def test_ica_rank_reduction(method):
"""Test recovery ICA rank reduction."""
_skip_check_picard(method)
# Most basic recovery
raw = read_raw_fif(raw_fname).crop(0.5, stop).load_data()
picks = pick_types(raw.info, meg=True, stim=False, ecg=False,
eog=False, exclude='bads')[:10]
n_components = 5
max_pca_components = len(picks)
for n_pca_components in [6, 10]:
with pytest.warns(UserWarning, match='did not converge'):
ica = ICA(n_components=n_components,
max_pca_components=max_pca_components,
n_pca_components=n_pca_components,
method=method, max_iter=1).fit(raw, picks=picks)
rank_before = _compute_rank_int(raw.copy().pick(picks), proj=False)
assert_equal(rank_before, len(picks))
raw_clean = ica.apply(raw.copy())
rank_after = _compute_rank_int(raw_clean.copy().pick(picks),
proj=False)
# interaction between ICA rejection and PCA components difficult
# to preduct. Rank_after often seems to be 1 higher then
# n_pca_components
assert (n_components < n_pca_components <= rank_after <=
rank_before)
开发者ID:Eric89GXL,项目名称:mne-python,代码行数:26,代码来源:test_ica.py
示例2: test_ica_rank_reduction
def test_ica_rank_reduction():
"""Test recovery of full data when no source is rejected"""
# Most basic recovery
raw = Raw(raw_fname).crop(0.5, stop, False)
raw.load_data()
picks = pick_types(raw.info, meg=True, stim=False, ecg=False,
eog=False, exclude='bads')[:10]
n_components = 5
max_pca_components = len(picks)
for n_pca_components in [6, 10]:
with warnings.catch_warnings(record=True): # non-convergence
warnings.simplefilter('always')
ica = ICA(n_components=n_components,
max_pca_components=max_pca_components,
n_pca_components=n_pca_components,
method='fastica', max_iter=1).fit(raw, picks=picks)
rank_before = raw.estimate_rank(picks=picks)
assert_equal(rank_before, len(picks))
raw_clean = ica.apply(raw, copy=True)
rank_after = raw_clean.estimate_rank(picks=picks)
# interaction between ICA rejection and PCA components difficult
# to preduct. Rank_after often seems to be 1 higher then
# n_pca_components
assert_true(n_components < n_pca_components <= rank_after <=
rank_before)
开发者ID:mdclarke,项目名称:mne-python,代码行数:26,代码来源:test_ica.py
示例3: test_ica_reset
def test_ica_reset(method):
"""Test ICA resetting."""
_skip_check_picard(method)
raw = read_raw_fif(raw_fname).crop(0.5, stop).load_data()
picks = pick_types(raw.info, meg=True, stim=False, ecg=False,
eog=False, exclude='bads')[:10]
run_time_attrs = (
'pre_whitener_',
'unmixing_matrix_',
'mixing_matrix_',
'n_components_',
'n_samples_',
'pca_components_',
'pca_explained_variance_',
'pca_mean_'
)
with pytest.warns(UserWarning, match='did not converge'):
ica = ICA(
n_components=3, max_pca_components=3, n_pca_components=3,
method=method, max_iter=1).fit(raw, picks=picks)
assert (all(hasattr(ica, attr) for attr in run_time_attrs))
assert ica.labels_ is not None
ica._reset()
assert (not any(hasattr(ica, attr) for attr in run_time_attrs))
assert ica.labels_ is not None
开发者ID:Eric89GXL,项目名称:mne-python,代码行数:27,代码来源:test_ica.py
示例4: test_plot_ica_panel
def test_plot_ica_panel():
"""Test plotting of ICA panel
"""
ica = ICA(noise_cov=read_cov(cov_fname), n_components=2,
max_pca_components=3, n_pca_components=3)
ica.decompose_raw(raw, picks=ica_picks)
ica.plot_sources_raw(raw)
开发者ID:emanuele,项目名称:mne-python,代码行数:7,代码来源:test_viz.py
示例5: test_n_components_and_max_pca_components_none
def test_n_components_and_max_pca_components_none(method):
"""Test n_components and max_pca_components=None."""
_skip_check_picard(method)
raw = read_raw_fif(raw_fname).crop(1.5, stop).load_data()
events = read_events(event_name)
picks = pick_types(raw.info, eeg=True, meg=False)
epochs = Epochs(raw, events, event_id, tmin, tmax, picks=picks,
baseline=(None, 0), preload=True)
max_pca_components = None
n_components = None
random_state = 12345
tempdir = _TempDir()
output_fname = op.join(tempdir, 'test_ica-ica.fif')
ica = ICA(max_pca_components=max_pca_components, method=method,
n_components=n_components, random_state=random_state)
with pytest.warns(None): # convergence
ica.fit(epochs)
ica.save(output_fname)
ica = read_ica(output_fname)
# ICA.fit() replaced max_pca_components, which was previously None,
# with the appropriate integer value.
assert_equal(ica.max_pca_components, epochs.info['nchan'])
assert ica.n_components is None
开发者ID:Eric89GXL,项目名称:mne-python,代码行数:27,代码来源:test_ica.py
示例6: test_eog_channel
def test_eog_channel(method):
"""Test that EOG channel is included when performing ICA."""
_skip_check_picard(method)
raw = read_raw_fif(raw_fname, preload=True)
events = read_events(event_name)
picks = pick_types(raw.info, meg=True, stim=True, ecg=False,
eog=True, exclude='bads')
epochs = Epochs(raw, events, event_id, tmin, tmax, picks=picks,
baseline=(None, 0), preload=True)
n_components = 0.9
ica = ICA(n_components=n_components, method=method)
# Test case for MEG and EOG data. Should have EOG channel
for inst in [raw, epochs]:
picks1a = pick_types(inst.info, meg=True, stim=False, ecg=False,
eog=False, exclude='bads')[:4]
picks1b = pick_types(inst.info, meg=False, stim=False, ecg=False,
eog=True, exclude='bads')
picks1 = np.append(picks1a, picks1b)
ica.fit(inst, picks=picks1)
assert (any('EOG' in ch for ch in ica.ch_names))
# Test case for MEG data. Should have no EOG channel
for inst in [raw, epochs]:
picks1 = pick_types(inst.info, meg=True, stim=False, ecg=False,
eog=False, exclude='bads')[:5]
ica.fit(inst, picks=picks1)
assert not any('EOG' in ch for ch in ica.ch_names)
开发者ID:Eric89GXL,项目名称:mne-python,代码行数:26,代码来源:test_ica.py
示例7: test_ica_reset
def test_ica_reset(method):
"""Test ICA resetting."""
_skip_check_picard(method)
raw = read_raw_fif(raw_fname).crop(0.5, stop).load_data()
picks = pick_types(raw.info, meg=True, stim=False, ecg=False,
eog=False, exclude='bads')[:10]
run_time_attrs = (
'_pre_whitener',
'unmixing_matrix_',
'mixing_matrix_',
'n_components_',
'n_samples_',
'pca_components_',
'pca_explained_variance_',
'pca_mean_'
)
with warnings.catch_warnings(record=True): # convergence
ica = ICA(
n_components=3, max_pca_components=3, n_pca_components=3,
method=method, max_iter=1).fit(raw, picks=picks)
assert_true(all(hasattr(ica, attr) for attr in run_time_attrs))
assert_not_equal(ica.labels_, None)
ica._reset()
assert_true(not any(hasattr(ica, attr) for attr in run_time_attrs))
assert_not_equal(ica.labels_, None)
开发者ID:jdammers,项目名称:mne-python,代码行数:27,代码来源:test_ica.py
示例8: apply_ica
def apply_ica(fname_filtered, n_components=0.99, decim=None):
''' Applies ICA to a list of (filtered) raw files. '''
import mne
from mne.preprocessing import ICA
import os
if isinstance(fname_filtered, list):
fnfilt = fname_filtered
else:
if isinstance(fname_filtered, str):
fnfilt = list([fname_filtered])
else:
fnfilt = list(fname_filtered)
# loop across all filenames
for fname in fnfilt:
name = os.path.split(fname)[1]
print ">>>> perform ICA signal decomposition on : "+name
# load filtered data
raw = mne.io.Raw(fname,preload=True)
picks = mne.pick_types(raw.info, meg=True, exclude='bads')
# ICA decomposition
ica = ICA(n_components=n_components, max_pca_components=None)
ica.fit(raw, picks=picks, decim=decim, reject={'mag': 5e-12})
# save ICA object
fnica_out = fname.strip('-raw.fif') + '-ica.fif'
# fnica_out = fname[0:len(fname)-4]+'-ica.fif'
ica.save(fnica_out)
开发者ID:dengemann,项目名称:jumeg-1,代码行数:33,代码来源:jumeg_preprocessing.py
示例9: run_ica
def run_ica(method):
ica = ICA(n_components=20, method=method, random_state=0)
t0 = time()
ica.fit(raw, picks=picks, reject=reject)
fit_time = time() - t0
title = ('ICA decomposition using %s (took %.1fs)' % (method, fit_time))
ica.plot_components(title=title)
开发者ID:SherazKhan,项目名称:mne-python,代码行数:7,代码来源:plot_ica_comparison.py
示例10: test_plot_instance_components
def test_plot_instance_components():
"""Test plotting of components as instances of raw and epochs."""
import matplotlib.pyplot as plt
raw = _get_raw()
picks = _get_picks(raw)
ica = ICA(noise_cov=read_cov(cov_fname), n_components=2,
max_pca_components=3, n_pca_components=3)
with pytest.warns(RuntimeWarning, match='projection'):
ica.fit(raw, picks=picks)
fig = ica.plot_sources(raw, exclude=[0], title='Components')
for key in ['down', 'up', 'right', 'left', 'o', '-', '+', '=', 'pageup',
'pagedown', 'home', 'end', 'f11', 'b']:
fig.canvas.key_press_event(key)
ax = fig.get_axes()[0]
line = ax.lines[0]
_fake_click(fig, ax, [line.get_xdata()[0], line.get_ydata()[0]],
'data')
_fake_click(fig, ax, [-0.1, 0.9]) # click on y-label
fig.canvas.key_press_event('escape')
plt.close('all')
epochs = _get_epochs()
fig = ica.plot_sources(epochs, exclude=[0], title='Components')
for key in ['down', 'up', 'right', 'left', 'o', '-', '+', '=', 'pageup',
'pagedown', 'home', 'end', 'f11', 'b']:
fig.canvas.key_press_event(key)
# Test a click
ax = fig.get_axes()[0]
line = ax.lines[0]
_fake_click(fig, ax, [line.get_xdata()[0], line.get_ydata()[0]], 'data')
_fake_click(fig, ax, [-0.1, 0.9]) # click on y-label
fig.canvas.key_press_event('escape')
plt.close('all')
开发者ID:SherazKhan,项目名称:mne-python,代码行数:32,代码来源:test_ica.py
示例11: test_n_components_none
def test_n_components_none():
"""Test n_components=None."""
raw = read_raw_fif(raw_fname).crop(1.5, stop).load_data()
events = read_events(event_name)
picks = pick_types(raw.info, eeg=True, meg=False)
epochs = Epochs(raw, events, event_id, tmin, tmax, picks=picks,
baseline=(None, 0), preload=True)
max_pca_components = 10
n_components = None
random_state = 12345
tempdir = _TempDir()
output_fname = op.join(tempdir, 'test_ica-ica.fif')
ica = ICA(max_pca_components=max_pca_components,
n_components=n_components, random_state=random_state)
with warnings.catch_warnings(record=True): # convergence
ica.fit(epochs)
ica.save(output_fname)
ica = read_ica(output_fname)
# ICA.fit() replaced max_pca_components, which was previously None,
# with the appropriate integer value.
assert_equal(ica.max_pca_components, 10)
assert_is_none(ica.n_components)
开发者ID:Lx37,项目名称:mne-python,代码行数:27,代码来源:test_ica.py
示例12: test_ica_reset
def test_ica_reset():
"""Test ICA resetting"""
raw = Raw(raw_fname).crop(0.5, stop, False)
raw.load_data()
picks = pick_types(raw.info, meg=True, stim=False, ecg=False,
eog=False, exclude='bads')[:10]
run_time_attrs = (
'_pre_whitener',
'unmixing_matrix_',
'mixing_matrix_',
'n_components_',
'n_samples_',
'pca_components_',
'pca_explained_variance_',
'pca_mean_'
)
with warnings.catch_warnings(record=True):
ica = ICA(
n_components=3, max_pca_components=3, n_pca_components=3,
method='fastica', max_iter=1).fit(raw, picks=picks)
assert_true(all(hasattr(ica, attr) for attr in run_time_attrs))
ica._reset()
assert_true(not any(hasattr(ica, attr) for attr in run_time_attrs))
开发者ID:mdclarke,项目名称:mne-python,代码行数:25,代码来源:test_ica.py
示例13: decompose
def decompose(self, X, y=None):
raw_inst = RawArray(X.T, create_info(self.channel_names, self.fs, 'eeg', None))
ica = ICA(method='extended-infomax')
ica.fit(raw_inst)
filters = np.dot(ica.unmixing_matrix_, ica.pca_components_[:ica.n_components_]).T
topographies = np.linalg.inv(filters).T
scores = self.get_scores(X, filters)
return scores, filters, topographies
开发者ID:nikolaims,项目名称:nfb,代码行数:8,代码来源:decompositions.py
示例14: test_plot_ica_panel
def test_plot_ica_panel():
"""Test plotting of ICA panel
"""
ica_picks = fiff.pick_types(raw.info, meg=True, eeg=False, stim=False, ecg=False, eog=False, exclude="bads")
cov = read_cov(cov_fname)
ica = ICA(noise_cov=cov, n_components=2, max_pca_components=3, n_pca_components=3)
ica.decompose_raw(raw, picks=ica_picks)
ica.plot_sources_raw(raw)
开发者ID:pauldelprato,项目名称:mne-python,代码行数:8,代码来源:test_viz.py
示例15: test_plot_ica_scores
def test_plot_ica_scores():
"""Test plotting of ICA scores
"""
raw = _get_raw()
ica_picks = pick_types(raw.info, meg=True, eeg=False, stim=False, ecg=False, eog=False, exclude="bads")
ica = ICA(noise_cov=read_cov(cov_fname), n_components=2, max_pca_components=3, n_pca_components=3)
ica.fit(raw, picks=ica_picks)
ica.plot_scores([0.3, 0.2], axhline=[0.1, -0.1])
assert_raises(ValueError, ica.plot_scores, [0.2])
plt.close("all")
开发者ID:rgoj,项目名称:mne-python,代码行数:10,代码来源:test_viz.py
示例16: test_plot_ica_panel
def test_plot_ica_panel():
"""Test plotting of ICA panel
"""
raw = _get_raw()
ica_picks = pick_types(raw.info, meg=True, eeg=False, stim=False,
ecg=False, eog=False, exclude='bads')
ica = ICA(noise_cov=read_cov(cov_fname), n_components=2,
max_pca_components=3, n_pca_components=3)
ica.decompose_raw(raw, picks=ica_picks)
ica.plot_sources_raw(raw)
plt.close('all')
开发者ID:anywave,项目名称:aw-export-fif,代码行数:11,代码来源:test_viz.py
示例17: test_plot_ica_scores
def test_plot_ica_scores():
"""Test plotting of ICA scores
"""
raw = _get_raw()
picks = _get_picks(raw)
ica = ICA(noise_cov=read_cov(cov_fname), n_components=2,
max_pca_components=3, n_pca_components=3)
ica.fit(raw, picks=picks)
ica.plot_scores([0.3, 0.2], axhline=[0.1, -0.1])
assert_raises(ValueError, ica.plot_scores, [0.2])
plt.close('all')
开发者ID:BushraR,项目名称:mne-python,代码行数:11,代码来源:test_ica.py
示例18: apply_ica
def apply_ica(fname_filtered, n_components=0.99, decim=None,
reject={'mag': 5e-12}, ica_method='fastica',
flow=None, fhigh=None, verbose=True):
''' Applies ICA to a list of (filtered) raw files. '''
from mne.preprocessing import ICA
fnfilt = get_files_from_list(fname_filtered)
# loop across all filenames
for fname in fnfilt:
name = os.path.split(fname)[1]
print ">>>> perform ICA signal decomposition on : " + name
# load filtered data
raw = mne.io.Raw(fname, preload=True)
picks = mne.pick_types(raw.info, meg=True, ref_meg=False, exclude='bads')
# check if data to estimate the optimal
# de-mixing matrix should be filtered
if flow or fhigh:
from jumeg.filter import jumeg_filter
# define filter type
if not flow:
filter_type = 'lp'
filter_info = " --> filter parameter : filter type=low pass %dHz" % flow
elif not fhigh:
filter_type = 'hp'
filter_info = " --> filter parameter : filter type=high pass %dHz" % flow
else:
filter_type = 'bp'
filter_info = " --> filter parameter: filter type=band pass %d-%dHz" % (flow, fhigh)
if verbose:
print ">>>> NOTE: Optimal cleaning parameter are estimated from filtered data!"
print filter_info
fi_mne_notch = jumeg_filter(fcut1=flow, fcut2=fhigh, filter_type=filter_type,
remove_dcoffset=False,
sampling_frequency=raw.info['sfreq'])
fi_mne_notch.apply_filter(raw._data, picks=picks)
# ICA decomposition
ica = ICA(method=ica_method, n_components=n_components,
max_pca_components=None)
ica.fit(raw, picks=picks, decim=decim, reject=reject)
# save ICA object
fnica_out = fname[:fname.rfind(ext_raw)] + ext_ica
# fnica_out = fname[0:len(fname)-4]+'-ica.fif'
ica.save(fnica_out)
开发者ID:VolkanChen,项目名称:jumeg,代码行数:53,代码来源:jumeg_preprocessing.py
示例19: test_ica_full_data_recovery
def test_ica_full_data_recovery(method):
"""Test recovery of full data when no source is rejected."""
# Most basic recovery
_skip_check_picard(method)
raw = read_raw_fif(raw_fname).crop(0.5, stop).load_data()
events = read_events(event_name)
picks = pick_types(raw.info, meg=True, stim=False, ecg=False,
eog=False, exclude='bads')[:10]
with pytest.warns(RuntimeWarning, match='projection'):
epochs = Epochs(raw, events[:4], event_id, tmin, tmax, picks=picks,
baseline=(None, 0), preload=True)
evoked = epochs.average()
n_channels = 5
data = raw._data[:n_channels].copy()
data_epochs = epochs.get_data()
data_evoked = evoked.data
raw.set_annotations(Annotations([0.5], [0.5], ['BAD']))
methods = [method]
for method in methods:
stuff = [(2, n_channels, True), (2, n_channels // 2, False)]
for n_components, n_pca_components, ok in stuff:
ica = ICA(n_components=n_components, random_state=0,
max_pca_components=n_pca_components,
n_pca_components=n_pca_components,
method=method, max_iter=1)
with pytest.warns(UserWarning, match=None): # sometimes warns
ica.fit(raw, picks=list(range(n_channels)))
raw2 = ica.apply(raw.copy(), exclude=[])
if ok:
assert_allclose(data[:n_channels], raw2._data[:n_channels],
rtol=1e-10, atol=1e-15)
else:
diff = np.abs(data[:n_channels] - raw2._data[:n_channels])
assert (np.max(diff) > 1e-14)
ica = ICA(n_components=n_components, method=method,
max_pca_components=n_pca_components,
n_pca_components=n_pca_components, random_state=0)
with pytest.warns(None): # sometimes warns
ica.fit(epochs, picks=list(range(n_channels)))
epochs2 = ica.apply(epochs.copy(), exclude=[])
data2 = epochs2.get_data()[:, :n_channels]
if ok:
assert_allclose(data_epochs[:, :n_channels], data2,
rtol=1e-10, atol=1e-15)
else:
diff = np.abs(data_epochs[:, :n_channels] - data2)
assert (np.max(diff) > 1e-14)
evoked2 = ica.apply(evoked.copy(), exclude=[])
data2 = evoked2.data[:n_channels]
if ok:
assert_allclose(data_evoked[:n_channels], data2,
rtol=1e-10, atol=1e-15)
else:
diff = np.abs(evoked.data[:n_channels] - data2)
assert (np.max(diff) > 1e-14)
pytest.raises(ValueError, ICA, method='pizza-decomposision')
开发者ID:Eric89GXL,项目名称:mne-python,代码行数:58,代码来源:test_ica.py
示例20: test_plot_ica_components
def test_plot_ica_components():
"""Test plotting of ICA solutions."""
res = 8
fast_test = {"res": res, "contours": 0, "sensors": False}
raw = _get_raw()
ica = ICA(noise_cov=read_cov(cov_fname), n_components=2,
max_pca_components=3, n_pca_components=3)
ica_picks = _get_picks(raw)
with pytest.warns(RuntimeWarning, match='projection'):
ica.fit(raw, picks=ica_picks)
for components in [0, [0], [0, 1], [0, 1] * 2, None]:
ica.plot_components(components, image_interp='bilinear',
colorbar=True, **fast_test)
plt.close('all')
# test interactive mode (passing 'inst' arg)
ica.plot_components([0, 1], image_interp='bilinear', inst=raw, res=16)
fig = plt.gcf()
# test title click
# ----------------
lbl = fig.axes[1].get_label()
ica_idx = int(lbl[-3:])
titles = [ax.title for ax in fig.axes]
title_pos_midpoint = (titles[1].get_window_extent().extents
.reshape((2, 2)).mean(axis=0))
# first click adds to exclude
_fake_click(fig, fig.axes[1], title_pos_midpoint, xform='pix')
assert ica_idx in ica.exclude
# clicking again removes from exclude
_fake_click(fig, fig.axes[1], title_pos_midpoint, xform='pix')
assert ica_idx not in ica.exclude
# test topo click
# ---------------
_fake_click(fig, fig.axes[1], (0., 0.), xform='data')
c_fig = plt.gcf()
labels = [ax.get_label() for ax in c_fig.axes]
for l in ['topomap', 'image', 'erp', 'spectrum', 'variance']:
assert (l in labels)
topomap_ax = c_fig.axes[labels.index('topomap')]
title = topomap_ax.get_title()
assert (lbl == title)
ica.info = None
with pytest.raises(RuntimeError, match='fit the ICA'):
ica.plot_components(1, ch_type='mag')
plt.close('all')
开发者ID:Eric89GXL,项目名称:mne-python,代码行数:52,代码来源:test_ica.py
注:本文中的mne.preprocessing.ICA类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论