本文整理汇总了Python中sklearn.decomposition.FastICA.components_[:]方法的典型用法代码示例。如果您正苦于以下问题:Python FastICA.components_[:]方法的具体用法?Python FastICA.components_[:]怎么用?Python FastICA.components_[:]使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sklearn.decomposition.FastICA
的用法示例。
在下文中一共展示了FastICA.components_[:]方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: fastica
# 需要导入模块: from sklearn.decomposition import FastICA [as 别名]
# 或者: from sklearn.decomposition.FastICA import components_[:] [as 别名]
def fastica(eeg_data):
"""
Sample function to apply `FastICA`_ to the EEG data.
Parameters
----------
eeg_data : array
EEG data in a CxTxE array. With C the number of channels, T the number
of time samples and E the number of events.
Returns
-------
ica : ICA object
Trained `FastICA`_ object.
ica_data : array
EEG projected data in a CxTxE array. With C the number of components, T
the number of time samples and E the number of events.
"""
# Dimension shapes
ch_len = eeg_data.shape[ch_dim]
t_len = eeg_data.shape[t_dim]
ev_len = eeg_data.shape[ev_dim]
# -------------------------------------------------------------------------
# 1. Fit the FastICA model
# We need to collapse time and events dimensions
coll_data = eeg_data.transpose([t_dim, ev_dim, ch_dim])\
.reshape([t_len*ev_len, ch_len])
# Fit model
ica = FastICA()
ica.fit(coll_data)
# Normalize ICs to unit norm
k = np.linalg.norm(ica.mixing_, axis=0) # Frobenius norm
ica.mixing_ /= k
ica.components_[:] = (ica.components_.T * k).T
# -------------------------------------------------------------------------
# 2. Transform data
# Project data
bss_data = ica.transform(coll_data)
# Adjust shape and dimensions back to "eeg_data" shape
ic_len = bss_data.shape[1]
bss_data = np.reshape(bss_data, [ev_len, t_len, ic_len])
new_order = [0, 0, 0]
# TODO: Check the following order
new_order[ev_dim] = 0
new_order[ch_dim] = 2
new_order[t_dim] = 1
bss_data = bss_data.transpose(new_order)
# End
return ica, bss_data