Esempio n. 1
0
def _read_epochs(epochs_mat_fname, info, return_fixations_motor):
    """read the epochs from matfile"""
    data = scio.loadmat(epochs_mat_fname, squeeze_me=True)['data']
    ch_names = [ch for ch in data['label'].tolist()]
    info['sfreq'] = data['fsample'].tolist()
    times = data['time'].tolist()[0]
    # deal with different event lengths
    if return_fixations_motor is not None:
        fixation_mask = data['trialinfo'].tolist()[:, 1] == 6
        if return_fixations_motor is False:
            fixation_mask = ~fixation_mask
        data = np.array(data['trial'].tolist()[fixation_mask].tolist())
    else:
        data = np.array(data['trial'].tolist().tolist())

    # warning: data are not chronologically ordered but
    # match the trial info
    events = np.zeros((len(data), 3), dtype=np.int)
    events[:, 0] = np.arange(len(data))
    events[:, 2] = 99  # all events
    # we leave it to the user to construct his events
    # as from the data['trialinfo'] arbitrary events can be constructed.
    # and it is task specific.
    this_info = _hcp_pick_info(info, ch_names)
    epochs = EpochsArray(data=data,
                         info=this_info,
                         events=events,
                         tmin=times.min())
    # XXX hack for now due to issue with EpochsArray constructor
    # cf https://github.com/mne-tools/mne-hcp/issues/9
    epochs.times = times
    return epochs
Esempio n. 2
0
def _read_epochs(epochs_mat_fname, info, return_fixations_motor):
    """read the epochs from matfile"""
    data = scio.loadmat(epochs_mat_fname,
                        squeeze_me=True)['data']
    ch_names = [ch for ch in data['label'].tolist()]
    info['sfreq'] = data['fsample'].tolist()
    times = data['time'].tolist()[0]
    # deal with different event lengths
    if return_fixations_motor is not None:
        fixation_mask = data['trialinfo'].tolist()[:, 1] == 6
        if return_fixations_motor is False:
            fixation_mask = ~fixation_mask
        data = np.array(data['trial'].tolist()[fixation_mask].tolist())
    else:
        data = np.array(data['trial'].tolist().tolist())

    # warning: data are not chronologically ordered but
    # match the trial info
    events = np.zeros((len(data), 3), dtype=np.int)
    events[:, 0] = np.arange(len(data))
    events[:, 2] = 99  # all events
    # we leave it to the user to construct his events
    # as from the data['trialinfo'] arbitrary events can be constructed.
    # and it is task specific.
    this_info = _hcp_pick_info(info, ch_names)
    epochs = EpochsArray(data=data, info=this_info, events=events,
                         tmin=times.min())
    # XXX hack for now due to issue with EpochsArray constructor
    # cf https://github.com/mne-tools/mne-hcp/issues/9
    epochs.times = times
    return epochs
Esempio n. 3
0
data_pln = np.asarray(pln_all)

# Setup data for epochs and cross validation
X = np.vstack([data_cls, data_pln])
y = np.concatenate([np.zeros(len(data_cls)), np.ones(len(data_pln))])
cv = StratifiedKFold(n_splits=7, shuffle=True)

# Create epochs to use for classification
n_trial, n_chan, n_time = X.shape
events = np.vstack((range(n_trial), np.zeros(n_trial, int), y.astype(int))).T
chan_names = ['MEG %i' % chan for chan in range(n_chan)]
chan_types = ['mag'] * n_chan
sfreq = 250
info = create_info(chan_names, sfreq, chan_types)
epochs = EpochsArray(data=X, info=info, events=events, verbose=False)
epochs.times = selected_times[:n_time]

# make classifier
clf = LogisticRegression(C=0.0001)

# fit model and score
gat = GeneralizationAcrossTime(clf=clf,
                               scorer="roc_auc",
                               cv=cv,
                               predict_method="predict")
gat.fit(epochs, y=y)
gat.score(epochs, y=y)

# Save model
joblib.dump(gat, data_path + "decode_time_gen/gat_ge.jl")
data_pln = np.asarray(pln_all)

# Setup data for epochs and cross validation
X = np.vstack([data_cls, data_pln])
y = np.concatenate([np.zeros(len(data_cls)), np.ones(len(data_pln))])
cv = StratifiedKFold(n_splits=7, shuffle=True)

# Create epochs to use for classification
n_trial, n_chan, n_time = X.shape
events = np.vstack((range(n_trial), np.zeros(n_trial, int), y.astype(int))).T
chan_names = ['MEG %i' % chan for chan in range(n_chan)]
chan_types = ['mag'] * n_chan
sfreq = 250
info = create_info(chan_names, sfreq, chan_types)
epochs = EpochsArray(data=X, info=info, events=events, verbose=False)
epochs.times = selected_times[:n_time]

# make classifier
clf = LogisticRegression(C=0.0001)

# fit model and score
gat = GeneralizationAcrossTime(
    clf=clf, scorer="roc_auc", cv=cv, predict_method="predict")
gat.fit(epochs, y=y)
gat.score(epochs, y=y)

# Save model
joblib.dump(gat, data_path + "decode_time_gen/gat_ge.jl")

# make matrix plot and save it
fig = gat.plot(