Пример #1
0
    accs = []
    bcas = []
    asrs = []
    s_id = np.random.permutation(np.arange(subject_number))
    results_dir = os.path.join(save_dir, data_name, model_used,
                               'run{}'.format(r))
    if not os.path.exists(results_dir):
        os.makedirs(results_dir)
    for s in range(1, subject_number):
        # Load dataset
        train_idx = [x for x in range(0, subject_number)]
        train_idx.remove(s_id[0])
        train_idx.remove(s_id[s])
        _, x_train, y_train = load(data_name,
                                   train_idx[0],
                                   npp_params,
                                   clean=True,
                                   downsample=True)
        for i in train_idx[1:]:
            _, x_i, y_i = load(data_name,
                               i,
                               npp_params,
                               clean=True,
                               downsample=True)
            x_train = np.concatenate((x_train, x_i), axis=0)
            y_train = np.concatenate((y_train, y_i), axis=0)

        x_train, y_train, x_validation, y_validation = utils.split_data(
            [x_train, y_train], split=0.8, shuffle=True)

        # create poison data
Пример #2
0
    s_id = np.random.permutation(np.arange(subject_number))
    results_dir = os.path.join(save_dir, data_name, model_used,
                               'run{}'.format(r))
    if not os.path.exists(results_dir):
        os.makedirs(results_dir)
    for param in params:
        npp_params = [amplitude, param[0], param[1]]
        s_asrs = []
        for s in range(1, subject_number):
            # Load dataset
            train_idx = [x for x in range(0, subject_number)]
            train_idx.remove(s_id[0])
            train_idx.remove(s_id[s])
            _, x_train, y_train = load(data_name,
                                       train_idx[0],
                                       npp_params,
                                       clean=True,
                                       physical=True,
                                       downsample=True)
            for i in train_idx[1:]:
                _, x_i, y_i = load(data_name,
                                   i,
                                   npp_params,
                                   clean=True,
                                   physical=True,
                                   downsample=True)
                x_train = np.concatenate((x_train, x_i), axis=0)
                y_train = np.concatenate((y_train, y_i), axis=0)

            x_train, y_train, x_validation, y_validation = utils.split_data(
                [x_train, y_train], split=0.8, shuffle=True)
Пример #3
0
import numpy as np
import matplotlib.pyplot as plt
from lib.load_data import load
from methods import pulse_noise

data_name = 'P300'
npp_params = [0.005, 5, 0.1]
linewidth = 1.0
fontsize = 8
figsize = (3.5, 2.5)
sample_freqs = {'ERN': 200, 'MI': 512, 'P300': 2048}
ams = {'ERN': 5, 'MI': 1, 'P300': 500}
sample_freq = sample_freqs[data_name]

poisoned_eeg, poisoned, _ = load(data_name, 7, npp_params, clean=False, physical=False, downsample=False)
clean_eeg, clean, _ = load(data_name, 7, npp_params, clean=True, physical=False, downsample=False)
npp = pulse_noise(clean_eeg.shape[1:], npp_params[1], sample_freqs[data_name], npp_params[2])

EEG = np.squeeze(clean_eeg[0])
EEG_P = np.squeeze(poisoned_eeg[0])
x = np.squeeze(clean[0])
x_p = np.squeeze(poisoned[0])
npp = np.squeeze(npp)

max_, min_ = np.max(EEG), np.min(EEG)
EEG = (EEG - min_) / (max_ - min_)
EEG_P = (EEG_P - min_) / (max_ - min_)
max_, min_ = np.max(x), np.min(x)
x = (x - min_) / (max_ - min_)
x_p = (x_p - min_) / (max_ - min_)