def _least_square_evoked(data, events, event_id, tmin, tmax, sfreq):
"""Least square estimation of evoked response from data.
Parameters
----------
data : ndarray, shape (n_channels, n_times)
The data to estimates evoked
events : ndarray, shape (n_events, 3)
The events typically returned by the read_events function.
If some events don't match the events of interest as specified
by event_id, they will be ignored.
event_id : dict
The id of the events to consider
tmin : float
Start time before event.
tmax : float
End time after event.
sfreq : float
Sampling frequency.
Returns
-------
evokeds_data : dict of ndarray
A dict of evoked data for each event type in event_id.
toeplitz : dict of ndarray
A dict of toeplitz matrix for each event type in event_id.
"""
nmin = int(tmin * sfreq)
nmax = int(tmax * sfreq)
window = nmax - nmin
n_samples = data.shape[1]
toeplitz_mat = dict()
full_toep = list()
for eid in event_id:
# select events by type
ix_ev = events[:, -1] == event_id[eid]
# build toeplitz matrix
trig = np.zeros((n_samples, 1))
ix_trig = (events[ix_ev, 0]) + nmin
trig[ix_trig] = 1
toep_mat = linalg.toeplitz(trig[0:window], trig)
toeplitz_mat[eid] = toep_mat
full_toep.append(toep_mat)
# Concatenate toeplitz
full_toep = np.concatenate(full_toep)
# least square estimation
predictor = np.dot(linalg.pinv(np.dot(full_toep, full_toep.T)), full_toep)
all_evokeds = np.dot(predictor, data.T)
all_evokeds = np.vsplit(all_evokeds, len(event_id))
# parse evoked response
evoked_data = dict()
for idx, eid in enumerate(event_id):
evoked_data[eid] = all_evokeds[idx].T
return evoked_data, toeplitz_mat
xdawn.py 文件源码
python
阅读 45
收藏 0
点赞 0
评论 0
评论列表
文章目录