Beispiel #1
0
def read_data(path=SAMPLES_PATH, windows=4, overlapping=3, raw_data=False):
    # datas 和 labels 都是 list. datas 中的每一项是 shape=(32, 128*windows) 的数组
    datas, labels = get_samples_data(path, windows, overlapping)
    datas_result = []
    for data in datas:
        data_list = []
        if not raw_data:
            # 数据预处理,提取特征(每一个样本处理后的结果是 numpy.narray 且 shape=(features, seq_length))
            for window in range(windows):  # 1S 为一个单位提取特征
                features_list = []
                for i in range(32):  # 依次处理 32 通道的 EEG 信号
                    X = data[i, 128 * (window):128 * ((window + 1))]
                    theta, alpha, beta, gamma = data_filter(
                        X, params)  # 获取各个频率段的数据
                    features_list.append(differential_entropy(theta))
                    features_list.append(differential_entropy(alpha))
                    features_list.append(differential_entropy(beta))
                    features_list.append(differential_entropy(gamma))
                _max = max(features_list)
                _min = min(features_list)
                data_list.append(
                    (np.array(features_list).reshape(-1, 1) - _min) /
                    (_max - _min))  # 0-1化处理
            datas_result.append(
                np.c_[tuple(data_list)])  # shape=(features, seq_length)
    if (raw_data):
        datas_result = datas
    del datas  # 释放内存
    assert len(datas_result) == len(labels)
    if not raw_data:
        np.save("./data_set/datas_features", datas_result)
        np.save("./data_set/label_features", labels)
    return (datas_result, labels)
Beispiel #2
0
def read_data(path=SAMPLES_PATH, train=True, test=False, seed=42, raw_data=False):
    '''默认读取训练集数据(880个)'''
    # datas 和 labels 都是 list. datas 中的每一项是 shape=(40, 7680) 的数组
    datas, labels = get_samples_data(path, train=train, test=test, seed=42)
    # 移除前 3S 的数据,利用后 60S 的数据
    datas_result = []
    time_window = 4 # 时间窗口大小是 2s
    for data in datas:
        data_list = []
        if not raw_data:
            # 数据预处理,提取特征(每一个样本处理后的结果是 numpy.narray 且 shape=(features, seq_length))
            for window in range(60 // time_window):
                features_list = []
                for i in range(32): # 依次处理 32 通道的 EEG 信号
                    X = data[i, 128*(window*time_window):128*(time_window*(window+1))]
                    theta, alpha, beta, gamma = data_filter(X, params) # 获取各个频率段的数据
                    features_list.append(differential_entropy(theta))
                    features_list.append(differential_entropy(alpha))
                    features_list.append(differential_entropy(beta))
                    features_list.append(differential_entropy(gamma))
                _max = max(features_list)
                _min = min(features_list)
                data_list.append((np.array(features_list).reshape(-1, 1) - _min)/(_max - _min)) # 0-1化处理
            datas_result.append(np.c_[tuple(data_list)]) # shape=(features, seq_length)
        else:
            datas_result.append(data[:32,:])
    
    datas.clear() # 释放内存
    if train:
        np.save("./data_set/datas_train", datas_result)
        np.save("./data_set/label_train", labels)
    if test:
        np.save("./data_set/datas_test", datas_result)
        np.save("./data_set/label_test", labels)
    return (datas_result, labels)
Beispiel #3
0
def read_data(path=SAMPLES_PATH,
              train=True,
              test=False,
              seed=42,
              raw_data=False):
    # datas 和 labels 都是 list. datas 中的每一项是 shape=(40, 8064) 的数组
    datas, labels = get_samples_data(path, train=train, test=test, seed=42)
    # 移除前 3S 的数据,利用后 60S 的数据
    datas_result = []
    time_window = 4  # 时间窗口大小是 2s
    for data in datas:
        data_list = []
        if not raw_data:
            # 数据预处理,提取特征(每一个样本处理后的结果是 numpy.narray 且 shape=(features, seq_length))
            for window in range(60 // time_window):
                features_list = []
                for i in range(32):  # 依次处理 32 通道的 EEG 信号
                    X = data[i, 128 * (3 + window * time_window):128 *
                             (3 + time_window * (window + 1))]
                    theta, alpha, beta, gamma = data_filter(
                        X, params)  # 获取各个频率段的数据
                    features_list.append(differential_entropy(theta))
                    features_list.append(differential_entropy(alpha))
                    features_list.append(differential_entropy(beta))
                    features_list.append(differential_entropy(gamma))
                data_list.append(np.array(features_list).reshape(-1, 1))
            datas_result.append(
                np.c_[tuple(data_list)])  # shape=(features, seq_length)
        else:
            datas_result.append(data[:32, 128 * 3:])

    datas.clear()  # 释放内存
    return (datas_result, labels)