Beispiel #1
0
def make_class(subject_id=[1, 10],
               crop=False,
               problem='hf',
               all_subject=False):
    bpfilter = [0.5, 45]
    if problem == "hf":
        if crop:
            pass
        else:
            X, y = get_data_multi(sub_id_range=subject_id,
                                  event_code=[6, 10, 14],
                                  t=[0, 4.0],
                                  filter=bpfilter)
    if problem == "lr":
        if crop:
            X, y, _, _ = get_crops_multi(sub_id_range=subject_id,
                                         event_code=[4, 8, 12],
                                         t=[0, 4.0],
                                         filter=bpfilter,
                                         time_window=2.0,
                                         time_step=1.0)
        else:
            X, y = get_data_multi(sub_id_range=subject_id,
                                  event_code=[4, 8, 12],
                                  t=[0, 4.0],
                                  filter=bpfilter)
    return X, y
Beispiel #2
0
from braindecode.datautil.iterators import CropsFromTrialsIterator
from braindecode.torch_ext.util import np_to_var, var_to_np
import torch.nn.functional as F
from numpy.random import RandomState
import torch as th
from braindecode.experiments.monitors import compute_preds_per_trial_for_set
import os, sys
os.chdir('/home/seigyo/Documents/pytorch/brain_decoder')
from load_data import get_data, get_data_multi

# X, y = get_data(id=10, event_code=[5,6,9,10,13,14], filter=None, t=[-0.5, 4])
# train_X, train_y = X[:60], y[:60]
# test_X, test_y = X[60:], y[60:]

train_X, train_y = get_data_multi(sub_id_range=[1, 88],
                                  event_code=[6, 10, 14],
                                  filter=None,
                                  t=[1, 4.1])
test_X, test_y = get_data_multi(sub_id_range=[89, 99],
                                event_code=[6, 10, 14],
                                filter=None,
                                t=[1, 4.1])

train_set = SignalAndTarget(train_X, y=train_y)
test_set = SignalAndTarget(test_X, y=test_y)

# Set if you want to use GPU
# You can also use torch.cuda.is_available() to determine if cuda is available on your machine.
cuda = True
set_random_seeds(seed=20170629, cuda=cuda)

# This will determine how many crops are processed in parallel
Beispiel #3
0
def make_class(idx=0, crop=False, problem='hf', all_subject=False):
    bpfilter = [0.5, 45]
    if all_subject:
        if problem == "hf":
            if crop:
                pass
            else:
                X, y = get_data_multi(sub_id_range=[1, 99],
                                      event_code=[6, 10, 14],
                                      t=[0, 4.0],
                                      filter=bpfilter)
        if problem == "lr":
            if crop:
                pass
            else:
                X, y = get_data_multi(sub_id_range=[1, 99],
                                      event_code=[4, 8, 12],
                                      t=[0, 4.0],
                                      filter=bpfilter)
    else:
        if problem == "hf":
            if crop:
                pass
            else:
                X, y = get_data(id=idx + 1,
                                event_code=[6, 10, 14],
                                filter=bpfilter,
                                t=[0., 4])
        if problem == "lr":
            if crop:
                X, y, _, _ = get_crops(id=idx + 1,
                                       event_code=[6, 10, 14],
                                       filter=bpfilter,
                                       t=[0, 4.0],
                                       time_window=3.0,
                                       time_step=0.1)
            else:
                X, y = get_data(id=idx + 1,
                                event_code=[4, 8, 12],
                                filter=bpfilter,
                                t=[0., 4])
        if problem == "lh":
            if crop:
                pass
            else:
                Xl, yl = get_data_one_class(id=idx + 1,
                                            event_code=[4, 8, 12],
                                            filter=bpfilter,
                                            t=[0, 4],
                                            classid=2)
                Xh, yh = get_data_one_class(id=idx + 1,
                                            event_code=[6, 10, 14],
                                            filter=bpfilter,
                                            t=[0, 4],
                                            classid=2)
                X = np.vstack((Xl, Xh))
                y = np.hstack((yl, yh + 1))
        if problem == "rh":
            if crop:
                pass
            else:
                Xr, yr = get_data_one_class(id=idx + 1,
                                            event_code=[4, 8, 12],
                                            filter=bpfilter,
                                            t=[0, 4],
                                            classid=3)
                Xh, yh = get_data_one_class(id=idx + 1,
                                            event_code=[6, 10, 14],
                                            filter=bpfilter,
                                            t=[0, 4],
                                            classid=2)
                X = np.vstack((Xr, Xh))
                y = np.hstack((yr - 1, yh + 1))
        if problem == "lf":
            if crop:
                pass
            else:
                Xl, yl = get_data_one_class(id=idx + 1,
                                            event_code=[4, 8, 12],
                                            filter=bpfilter,
                                            t=[0, 4],
                                            classid=2)
                Xf, yf = get_data_one_class(id=idx + 1,
                                            event_code=[6, 10, 14],
                                            filter=bpfilter,
                                            t=[0, 4],
                                            classid=3)
                X = np.vstack((Xl, Xf))
                y = np.hstack((yl, yf))
        if problem == "rf":
            if crop:
                pass
            else:
                Xr, yr = get_data_one_class(id=idx + 1,
                                            event_code=[4, 8, 12],
                                            filter=bpfilter,
                                            t=[0, 4],
                                            classid=3)
                Xf, yf = get_data_one_class(id=idx + 1,
                                            event_code=[6, 10, 14],
                                            filter=bpfilter,
                                            t=[0, 4],
                                            classid=3)
                X = np.vstack((Xr, Xf))
                y = np.hstack((yr - 1, yf))
    return X, y