本文整理汇总了Python中mne.preprocessing.ICA._transform_raw方法的典型用法代码示例。如果您正苦于以下问题:Python ICA._transform_raw方法的具体用法?Python ICA._transform_raw怎么用?Python ICA._transform_raw使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mne.preprocessing.ICA
的用法示例。
在下文中一共展示了ICA._transform_raw方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ica_routine
# 需要导入模块: from mne.preprocessing import ICA [as 别名]
# 或者: from mne.preprocessing.ICA import _transform_raw [as 别名]
def ica_routine(params, subj_inds, subj_d):
"""Loop over all classification parameters using extended infomax ICA"""
scores = np.empty((len(params['t_wind_binned']),
len(params['n_components_list']), len(subj_inds),
params['cvs'], len(params['kernel_list']),
len(params['C_range']), len(params['g_range'])))
scores[:] = np.nan
for t_wind_i, t_wind in enumerate(params['t_wind_binned']):
print '\t' + 'Time window: ' + str(t_wind),
for comp_i, var_explained in enumerate(params['n_components_list']):
ica = ICA(n_components=var_explained,
method=ICA_PARAMS['ica_init_params']['method'],
max_iter=ICA_PARAMS['ica_init_params']['max_iter'])
for si, di in enumerate(subj_inds):
# Pull data structures from dict
maint_all = subj_d[di]['epo_mat'][patterns[0]][:, :, t_wind[0]:t_wind[1]]
switch_all = subj_d[di]['epo_mat'][patterns[1]][:, :, t_wind[0]:t_wind[1]]
'''
temp_m = maint_all.reshape(maint_all.shape[0], -1)
temp_s = switch_all.reshape(switch_all.shape[0], -1)
data = np.concatenate((temp_m, temp_s), axis=0)
'''
target = np.concatenate((np.ones(maint_all.shape[0]) * -1,
np.ones(switch_all.shape[0])), axis=0)
# Construct dummy Raw object to use MNE's ICA computations
info = create_info(ch_names=subj_d[di]['epo_mat'][patterns[0]].shape[1],
sfreq=1. / bin_width, ch_types='eeg')
info['bads'] = []
# Set up cross-validation
cv = StratifiedKFold(target, n_folds=params['cvs'])
for ti, (train_idx, test_idx) in enumerate(cv):
# Refactor training data to (n_chan x n_features) for ICA
data_train = np.concatenate((maint_all, switch_all))[train_idx, :, :]
raw_train, train_shape = roll_raw(data_train, info)
# Fit ICA to training data
ica.fit(raw_train, verbose=False)
###########################################################
# Construct raw from reshaped data
all_data = np.concatenate((maint_all, switch_all), axis=0)
raw_all, all_data_shape = roll_raw(all_data, info)
# Transform training and testing data
all_data_trans = ica._transform_raw(raw_all, None, None)
# Un-reshape training and testing data
all_data_trans = \
all_data_trans.reshape((all_data_trans.shape[0],
all_data_shape[1],
all_data_shape[2]))
all_data_trans = np.rollaxis(all_data_trans, axis=1)
# Formally construct training and testing data
# Reshape to (n_trials x n_features)
data_train_trans = all_data_trans[train_idx, :, :]
data_train_trans = data_train_trans.reshape(data_train_trans.shape[0], -1)
data_test_trans = all_data_trans[test_idx, :, :]
data_test_trans = data_test_trans.reshape(data_test_trans.shape[0], -1)
# Create training and test sets
data_dict = dict(X_train=data_train_trans,
X_test=data_test_trans,
y_train=target[train_idx],
y_test=target[test_idx])
# Compute scores over given SVM parameters and store
try:
scores[t_wind_i, comp_i, si, ti, :, :, :] = \
cross_val_ica(data_dict, params['kernel_list'],
params['C_range'], params['g_range'])
except:
'Error raised\nsubj: ' + str(di)
raise
print ' ... Done.'
return scores
示例2: ica_routine
# 需要导入模块: from mne.preprocessing import ICA [as 别名]
# 或者: from mne.preprocessing.ICA import _transform_raw [as 别名]
def ica_routine(data_m, data_s, params):
"""Loop over all classification parameters using extended infomax ICA"""
scores = np.empty((len(params['n_components_list']), params['cvs'],
len(params['kernel_list']), len(params['C_range']),
len(params['g_range'])))
# Iterate over time window, ICA components variance, subject, cross-val
for comp_i, var_explained in enumerate(params['n_components_list']):
ica = ICA(n_components=var_explained,
method=params['ica_init_params']['method'],
max_iter=params['ica_init_params']['max_iter'])
# Get data and trial labels
target = np.concatenate((np.ones(data_m.shape[0]) * -1,
np.ones(data_s.shape[0])), axis=0)
# Construct dummy Raw object to link into MNE's ICA computations
info = create_info(ch_names=data_m.shape[1], sfreq=1. / bin_width,
ch_types='eeg')
info['bads'] = []
# Prepare cross-validation
cv = StratifiedKFold(target, n_folds=params['cvs'])
for ti, (train_idx, test_idx) in enumerate(cv):
# Refactor training data to (n_chan x n_features) for ICA
data_train = np.concatenate((data_m, data_s), axis=0)[train_idx, :, :]
data_train = np.rollaxis(data_train, 1)
raw_train = RawArray(data_train.reshape(data_train.shape[0], -1),
info, verbose=False)
# Fit ICA to training data
ica.fit(raw_train, verbose=False)
###########################################################
# Construct raw from reshaped data
all_data = np.rollaxis(np.concatenate((data_m, data_s), axis=0), 1)
all_data_shape = all_data.shape
raw_all = RawArray(all_data.reshape(all_data.shape[0], -1),
info, verbose=False)
# Transform training and testing data
all_data_trans = ica._transform_raw(raw_all, None, None)
# Un-reshape training and testing data to (n_comp x n_trials x n_times)
all_data_trans = \
all_data_trans.reshape((all_data_trans.shape[0],
all_data_shape[1],
all_data_shape[2]))
all_data_trans = np.rollaxis(all_data_trans, axis=1)
# Formally construct training and testing data
# Reshape to (n_trials x n_features)
data_train_trans = all_data_trans[train_idx, :, :]
data_train_trans = data_train_trans.reshape(data_train_trans.shape[0], -1)
data_test_trans = all_data_trans[test_idx, :, :]
data_test_trans = data_test_trans.reshape(data_test_trans.shape[0], -1)
# Create training and test sets
data_dict = dict(X_train=data_train_trans,
X_test=data_test_trans,
y_train=target[train_idx],
y_test=target[test_idx])
# Compute scores over given SVM parameters
scores[comp_i, ti, :, :, :] = \
cross_val_ica(data_dict, params['kernel_list'],
params['C_range'], params['g_range'])
return scores