├── RSA ├── corrs │ ├── Alpha_runtime.txt │ ├── ERP_runtime.txt │ ├── ERP.h5 │ └── Alpha.h5 ├── eegrdms │ ├── ERP_runtime.txt │ ├── Alpha_runtime.txt │ ├── Alpha.h5 │ └── ERP.h5 ├── corrs_crosst │ ├── ERP_runtime.txt │ ├── Alpha_runtime.txt │ ├── ERP.h5 │ ├── ERP_201.h5 │ ├── ERP_202.h5 │ ├── ERP_203.h5 │ ├── ERP_204.h5 │ ├── ERP_205.h5 │ ├── ERP_206.h5 │ ├── ERP_207.h5 │ ├── ERP_208.h5 │ ├── ERP_209.h5 │ ├── ERP_210.h5 │ ├── ERP_212.h5 │ ├── ERP_213.h5 │ ├── ERP_215.h5 │ ├── ERP_216.h5 │ ├── ERP_217.h5 │ ├── ERP_218.h5 │ ├── Alpha_201.h5 │ ├── Alpha_202.h5 │ ├── Alpha_203.h5 │ ├── Alpha_204.h5 │ ├── Alpha_205.h5 │ ├── Alpha_206.h5 │ ├── Alpha_207.h5 │ ├── Alpha_208.h5 │ ├── Alpha_209.h5 │ ├── Alpha_210.h5 │ ├── Alpha_212.h5 │ ├── Alpha_213.h5 │ ├── Alpha_215.h5 │ ├── Alpha_216.h5 │ ├── Alpha_217.h5 │ ├── Alpha_218.h5 │ └── ERP_201.txt ├── demo_rdm.png ├── modelrdm │ ├── Thumbs.db │ ├── modelrdm.png │ └── modelrdm.txt ├── crosst_demo_rdm.png ├── results │ ├── timebytime │ │ ├── ERP_ori.png │ │ ├── ERP_pos.png │ │ ├── alpha_ori.png │ │ └── alpha_pos.png │ └── crosstemporal │ │ ├── ERP_ori.png │ │ ├── ERP_pos.png │ │ ├── alpha_ori.png │ │ └── alpha_pos.png ├── plot_demo_rdm.py ├── getcodingmodels.py ├── plot_crosst_demo_rdm.py ├── corrs_cal.py ├── plot_crosst.py ├── plot.py ├── eegrdms_cal.py ├── pre_data.py ├── corrs_crosst_cal.py └── corrs_crosst_cal_alpha.py ├── classification ├── svm_results │ ├── Alpha_ori_runtime.txt │ ├── Alpha_pos_runtime.txt │ ├── ERP_ori_runtime.txt │ ├── ERP_pos_runtime.txt │ ├── ERP_ori.h5 │ ├── ERP_pos.h5 │ ├── Alpha_ori.h5 │ ├── Alpha_pos.h5 │ ├── timebytime │ │ ├── Thumbs.db │ │ ├── ERP_ori.png │ │ ├── ERP_pos.png │ │ ├── alpha_ori.png │ │ └── alpha_pos.png │ └── crosstemporal │ │ ├── ERP_ori.png │ │ ├── ERP_pos.png │ │ ├── alpha_ori.png │ │ └── alpha_pos.png ├── svm_random_results │ ├── ERP_ori_runtime.txt │ ├── ERP_pos_runtime.txt │ ├── Alpha_ori_runtime.txt │ ├── Alpha_pos_runtime.txt │ ├── ERP_ori.h5 │ ├── ERP_pos.h5 │ ├── Alpha_ori.h5 │ └── Alpha_pos.h5 ├── plot_crosst.py ├── plot.py ├── pre_data.py └── svm_decoding.py └── README.md /RSA/corrs/Alpha_runtime.txt: -------------------------------------------------------------------------------- 1 | 6.980212200000000422e+00 2 | -------------------------------------------------------------------------------- /RSA/corrs/ERP_runtime.txt: -------------------------------------------------------------------------------- 1 | 6.979262799999999878e+00 2 | -------------------------------------------------------------------------------- /RSA/eegrdms/ERP_runtime.txt: -------------------------------------------------------------------------------- 1 | 7.140115580000001216e+01 2 | -------------------------------------------------------------------------------- /RSA/corrs_crosst/ERP_runtime.txt: -------------------------------------------------------------------------------- 1 | 3.750030807200000254e+03 2 | -------------------------------------------------------------------------------- /RSA/eegrdms/Alpha_runtime.txt: -------------------------------------------------------------------------------- 1 | 7.160285750000001315e+01 2 | -------------------------------------------------------------------------------- /RSA/corrs_crosst/Alpha_runtime.txt: -------------------------------------------------------------------------------- 1 | 3.643236594900000000e+03 2 | -------------------------------------------------------------------------------- /classification/svm_results/Alpha_ori_runtime.txt: -------------------------------------------------------------------------------- 1 | 4.033226907999996911e+02 2 | -------------------------------------------------------------------------------- /classification/svm_results/Alpha_pos_runtime.txt: -------------------------------------------------------------------------------- 1 | 4.038358791000027850e+02 2 | -------------------------------------------------------------------------------- /classification/svm_results/ERP_ori_runtime.txt: -------------------------------------------------------------------------------- 1 | 4.057457467000003817e+02 2 | -------------------------------------------------------------------------------- /classification/svm_results/ERP_pos_runtime.txt: -------------------------------------------------------------------------------- 1 | 4.015681500000009692e+02 2 | -------------------------------------------------------------------------------- /classification/svm_random_results/ERP_ori_runtime.txt: -------------------------------------------------------------------------------- 1 | 4.718265290999997887e+02 2 | -------------------------------------------------------------------------------- /classification/svm_random_results/ERP_pos_runtime.txt: -------------------------------------------------------------------------------- 1 | 7.395418788999995741e+02 2 | -------------------------------------------------------------------------------- /classification/svm_random_results/Alpha_ori_runtime.txt: -------------------------------------------------------------------------------- 1 | 7.024135268000027281e+02 2 | -------------------------------------------------------------------------------- /classification/svm_random_results/Alpha_pos_runtime.txt: -------------------------------------------------------------------------------- 1 | 6.529238140000015846e+02 2 | -------------------------------------------------------------------------------- /RSA/corrs/ERP.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZitongLu1996/Python_EEG_Decoding/HEAD/RSA/corrs/ERP.h5 -------------------------------------------------------------------------------- /RSA/demo_rdm.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZitongLu1996/Python_EEG_Decoding/HEAD/RSA/demo_rdm.png -------------------------------------------------------------------------------- /RSA/corrs/Alpha.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZitongLu1996/Python_EEG_Decoding/HEAD/RSA/corrs/Alpha.h5 -------------------------------------------------------------------------------- /RSA/eegrdms/Alpha.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZitongLu1996/Python_EEG_Decoding/HEAD/RSA/eegrdms/Alpha.h5 -------------------------------------------------------------------------------- /RSA/eegrdms/ERP.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZitongLu1996/Python_EEG_Decoding/HEAD/RSA/eegrdms/ERP.h5 -------------------------------------------------------------------------------- /RSA/modelrdm/Thumbs.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZitongLu1996/Python_EEG_Decoding/HEAD/RSA/modelrdm/Thumbs.db -------------------------------------------------------------------------------- /RSA/corrs_crosst/ERP.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZitongLu1996/Python_EEG_Decoding/HEAD/RSA/corrs_crosst/ERP.h5 -------------------------------------------------------------------------------- /RSA/crosst_demo_rdm.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZitongLu1996/Python_EEG_Decoding/HEAD/RSA/crosst_demo_rdm.png -------------------------------------------------------------------------------- /RSA/modelrdm/modelrdm.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZitongLu1996/Python_EEG_Decoding/HEAD/RSA/modelrdm/modelrdm.png -------------------------------------------------------------------------------- /RSA/corrs_crosst/ERP_201.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZitongLu1996/Python_EEG_Decoding/HEAD/RSA/corrs_crosst/ERP_201.h5 -------------------------------------------------------------------------------- /RSA/corrs_crosst/ERP_202.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZitongLu1996/Python_EEG_Decoding/HEAD/RSA/corrs_crosst/ERP_202.h5 -------------------------------------------------------------------------------- /RSA/corrs_crosst/ERP_203.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZitongLu1996/Python_EEG_Decoding/HEAD/RSA/corrs_crosst/ERP_203.h5 -------------------------------------------------------------------------------- /RSA/corrs_crosst/ERP_204.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZitongLu1996/Python_EEG_Decoding/HEAD/RSA/corrs_crosst/ERP_204.h5 -------------------------------------------------------------------------------- /RSA/corrs_crosst/ERP_205.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZitongLu1996/Python_EEG_Decoding/HEAD/RSA/corrs_crosst/ERP_205.h5 -------------------------------------------------------------------------------- /RSA/corrs_crosst/ERP_206.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZitongLu1996/Python_EEG_Decoding/HEAD/RSA/corrs_crosst/ERP_206.h5 -------------------------------------------------------------------------------- /RSA/corrs_crosst/ERP_207.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZitongLu1996/Python_EEG_Decoding/HEAD/RSA/corrs_crosst/ERP_207.h5 -------------------------------------------------------------------------------- /RSA/corrs_crosst/ERP_208.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZitongLu1996/Python_EEG_Decoding/HEAD/RSA/corrs_crosst/ERP_208.h5 -------------------------------------------------------------------------------- /RSA/corrs_crosst/ERP_209.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZitongLu1996/Python_EEG_Decoding/HEAD/RSA/corrs_crosst/ERP_209.h5 -------------------------------------------------------------------------------- /RSA/corrs_crosst/ERP_210.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZitongLu1996/Python_EEG_Decoding/HEAD/RSA/corrs_crosst/ERP_210.h5 -------------------------------------------------------------------------------- /RSA/corrs_crosst/ERP_212.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZitongLu1996/Python_EEG_Decoding/HEAD/RSA/corrs_crosst/ERP_212.h5 -------------------------------------------------------------------------------- /RSA/corrs_crosst/ERP_213.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZitongLu1996/Python_EEG_Decoding/HEAD/RSA/corrs_crosst/ERP_213.h5 -------------------------------------------------------------------------------- /RSA/corrs_crosst/ERP_215.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZitongLu1996/Python_EEG_Decoding/HEAD/RSA/corrs_crosst/ERP_215.h5 -------------------------------------------------------------------------------- /RSA/corrs_crosst/ERP_216.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZitongLu1996/Python_EEG_Decoding/HEAD/RSA/corrs_crosst/ERP_216.h5 -------------------------------------------------------------------------------- /RSA/corrs_crosst/ERP_217.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZitongLu1996/Python_EEG_Decoding/HEAD/RSA/corrs_crosst/ERP_217.h5 -------------------------------------------------------------------------------- /RSA/corrs_crosst/ERP_218.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZitongLu1996/Python_EEG_Decoding/HEAD/RSA/corrs_crosst/ERP_218.h5 -------------------------------------------------------------------------------- /RSA/corrs_crosst/Alpha_201.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZitongLu1996/Python_EEG_Decoding/HEAD/RSA/corrs_crosst/Alpha_201.h5 -------------------------------------------------------------------------------- /RSA/corrs_crosst/Alpha_202.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZitongLu1996/Python_EEG_Decoding/HEAD/RSA/corrs_crosst/Alpha_202.h5 -------------------------------------------------------------------------------- /RSA/corrs_crosst/Alpha_203.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZitongLu1996/Python_EEG_Decoding/HEAD/RSA/corrs_crosst/Alpha_203.h5 -------------------------------------------------------------------------------- /RSA/corrs_crosst/Alpha_204.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZitongLu1996/Python_EEG_Decoding/HEAD/RSA/corrs_crosst/Alpha_204.h5 -------------------------------------------------------------------------------- /RSA/corrs_crosst/Alpha_205.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZitongLu1996/Python_EEG_Decoding/HEAD/RSA/corrs_crosst/Alpha_205.h5 -------------------------------------------------------------------------------- /RSA/corrs_crosst/Alpha_206.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZitongLu1996/Python_EEG_Decoding/HEAD/RSA/corrs_crosst/Alpha_206.h5 -------------------------------------------------------------------------------- /RSA/corrs_crosst/Alpha_207.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZitongLu1996/Python_EEG_Decoding/HEAD/RSA/corrs_crosst/Alpha_207.h5 -------------------------------------------------------------------------------- /RSA/corrs_crosst/Alpha_208.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZitongLu1996/Python_EEG_Decoding/HEAD/RSA/corrs_crosst/Alpha_208.h5 -------------------------------------------------------------------------------- /RSA/corrs_crosst/Alpha_209.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZitongLu1996/Python_EEG_Decoding/HEAD/RSA/corrs_crosst/Alpha_209.h5 -------------------------------------------------------------------------------- /RSA/corrs_crosst/Alpha_210.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZitongLu1996/Python_EEG_Decoding/HEAD/RSA/corrs_crosst/Alpha_210.h5 -------------------------------------------------------------------------------- /RSA/corrs_crosst/Alpha_212.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZitongLu1996/Python_EEG_Decoding/HEAD/RSA/corrs_crosst/Alpha_212.h5 -------------------------------------------------------------------------------- /RSA/corrs_crosst/Alpha_213.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZitongLu1996/Python_EEG_Decoding/HEAD/RSA/corrs_crosst/Alpha_213.h5 -------------------------------------------------------------------------------- /RSA/corrs_crosst/Alpha_215.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZitongLu1996/Python_EEG_Decoding/HEAD/RSA/corrs_crosst/Alpha_215.h5 -------------------------------------------------------------------------------- /RSA/corrs_crosst/Alpha_216.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZitongLu1996/Python_EEG_Decoding/HEAD/RSA/corrs_crosst/Alpha_216.h5 -------------------------------------------------------------------------------- /RSA/corrs_crosst/Alpha_217.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZitongLu1996/Python_EEG_Decoding/HEAD/RSA/corrs_crosst/Alpha_217.h5 -------------------------------------------------------------------------------- /RSA/corrs_crosst/Alpha_218.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZitongLu1996/Python_EEG_Decoding/HEAD/RSA/corrs_crosst/Alpha_218.h5 -------------------------------------------------------------------------------- /RSA/corrs_crosst/ERP_201.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZitongLu1996/Python_EEG_Decoding/HEAD/RSA/corrs_crosst/ERP_201.txt -------------------------------------------------------------------------------- /RSA/results/timebytime/ERP_ori.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZitongLu1996/Python_EEG_Decoding/HEAD/RSA/results/timebytime/ERP_ori.png -------------------------------------------------------------------------------- /RSA/results/timebytime/ERP_pos.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZitongLu1996/Python_EEG_Decoding/HEAD/RSA/results/timebytime/ERP_pos.png -------------------------------------------------------------------------------- /RSA/results/crosstemporal/ERP_ori.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZitongLu1996/Python_EEG_Decoding/HEAD/RSA/results/crosstemporal/ERP_ori.png -------------------------------------------------------------------------------- /RSA/results/crosstemporal/ERP_pos.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZitongLu1996/Python_EEG_Decoding/HEAD/RSA/results/crosstemporal/ERP_pos.png -------------------------------------------------------------------------------- /RSA/results/timebytime/alpha_ori.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZitongLu1996/Python_EEG_Decoding/HEAD/RSA/results/timebytime/alpha_ori.png -------------------------------------------------------------------------------- /RSA/results/timebytime/alpha_pos.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZitongLu1996/Python_EEG_Decoding/HEAD/RSA/results/timebytime/alpha_pos.png -------------------------------------------------------------------------------- /classification/svm_results/ERP_ori.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZitongLu1996/Python_EEG_Decoding/HEAD/classification/svm_results/ERP_ori.h5 -------------------------------------------------------------------------------- /classification/svm_results/ERP_pos.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZitongLu1996/Python_EEG_Decoding/HEAD/classification/svm_results/ERP_pos.h5 -------------------------------------------------------------------------------- /RSA/results/crosstemporal/alpha_ori.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZitongLu1996/Python_EEG_Decoding/HEAD/RSA/results/crosstemporal/alpha_ori.png -------------------------------------------------------------------------------- /RSA/results/crosstemporal/alpha_pos.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZitongLu1996/Python_EEG_Decoding/HEAD/RSA/results/crosstemporal/alpha_pos.png -------------------------------------------------------------------------------- /classification/svm_results/Alpha_ori.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZitongLu1996/Python_EEG_Decoding/HEAD/classification/svm_results/Alpha_ori.h5 -------------------------------------------------------------------------------- /classification/svm_results/Alpha_pos.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZitongLu1996/Python_EEG_Decoding/HEAD/classification/svm_results/Alpha_pos.h5 -------------------------------------------------------------------------------- /classification/svm_random_results/ERP_ori.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZitongLu1996/Python_EEG_Decoding/HEAD/classification/svm_random_results/ERP_ori.h5 -------------------------------------------------------------------------------- /classification/svm_random_results/ERP_pos.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZitongLu1996/Python_EEG_Decoding/HEAD/classification/svm_random_results/ERP_pos.h5 -------------------------------------------------------------------------------- /classification/svm_random_results/Alpha_ori.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZitongLu1996/Python_EEG_Decoding/HEAD/classification/svm_random_results/Alpha_ori.h5 -------------------------------------------------------------------------------- /classification/svm_random_results/Alpha_pos.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZitongLu1996/Python_EEG_Decoding/HEAD/classification/svm_random_results/Alpha_pos.h5 -------------------------------------------------------------------------------- /classification/svm_results/timebytime/Thumbs.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZitongLu1996/Python_EEG_Decoding/HEAD/classification/svm_results/timebytime/Thumbs.db -------------------------------------------------------------------------------- /classification/svm_results/timebytime/ERP_ori.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZitongLu1996/Python_EEG_Decoding/HEAD/classification/svm_results/timebytime/ERP_ori.png -------------------------------------------------------------------------------- /classification/svm_results/timebytime/ERP_pos.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZitongLu1996/Python_EEG_Decoding/HEAD/classification/svm_results/timebytime/ERP_pos.png -------------------------------------------------------------------------------- /classification/svm_results/crosstemporal/ERP_ori.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZitongLu1996/Python_EEG_Decoding/HEAD/classification/svm_results/crosstemporal/ERP_ori.png -------------------------------------------------------------------------------- /classification/svm_results/crosstemporal/ERP_pos.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZitongLu1996/Python_EEG_Decoding/HEAD/classification/svm_results/crosstemporal/ERP_pos.png -------------------------------------------------------------------------------- /classification/svm_results/timebytime/alpha_ori.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZitongLu1996/Python_EEG_Decoding/HEAD/classification/svm_results/timebytime/alpha_ori.png -------------------------------------------------------------------------------- /classification/svm_results/timebytime/alpha_pos.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZitongLu1996/Python_EEG_Decoding/HEAD/classification/svm_results/timebytime/alpha_pos.png -------------------------------------------------------------------------------- /classification/svm_results/crosstemporal/alpha_ori.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZitongLu1996/Python_EEG_Decoding/HEAD/classification/svm_results/crosstemporal/alpha_ori.png -------------------------------------------------------------------------------- /classification/svm_results/crosstemporal/alpha_pos.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZitongLu1996/Python_EEG_Decoding/HEAD/classification/svm_results/crosstemporal/alpha_pos.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | **EEG Decoding Demo based on Python** 2 | 3 | Classification-based decoding: 4 | - 1> pre_data.py 5 | - 2> svm_decoding.py 6 | - 3> plot*.py 7 | 8 | Similarity-based decoding 9 | - 1> pre_data.py 10 | - 2> getcodingmodels.py 11 | - 3> eegrdms_cal.py 12 | - 4> cross_cal.py 13 | -------------------------------------------------------------------------------- /RSA/plot_demo_rdm.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 2 | 3 | import numpy as np 4 | from neurora.rsa_plot import plot_rdm 5 | 6 | rdm = np.random.rand(16, 16) 7 | for i in range(16): 8 | for j in range(16): 9 | if i>j: 10 | rdm[i, j] = rdm[j, i] 11 | rdm[i, i] = 0 12 | 13 | conditions = ["0°", "22.5°", "45°", "67.5°", "90°", "112.5°", "135°", "157.5°", "180°", 14 | "202.5°", "225°", "247.5°", "270°", "292.5°", "315°", "337.5°"] 15 | plot_rdm(rdm, conditions=conditions) -------------------------------------------------------------------------------- /RSA/getcodingmodels.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | rdm = np.zeros([16, 16], dtype=np.float) 4 | 5 | for i in range(16): 6 | for j in range(16): 7 | diff = np.abs(i-j) 8 | if diff <= 8: 9 | rdm[i, j] = diff/8 10 | else: 11 | rdm[i, j] = (16-diff)/8 12 | 13 | from neurora.rsa_plot import plot_rdm 14 | 15 | conditions = ["0°", "22.5°", "45°", "67.5°", "90°", "112.5°", "135°", "157.5°", "180°", 16 | "202.5°", "225°", "247.5°", "270°", "292.5°", "315°", "337.5°"] 17 | 18 | plot_rdm(rdm, conditions=conditions) 19 | 20 | np.savetxt("modelrdm/modelrdm.txt", rdm) 21 | -------------------------------------------------------------------------------- /RSA/plot_crosst_demo_rdm.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 2 | 3 | import numpy as np 4 | import matplotlib.pyplot as plt 5 | 6 | rdm = np.random.rand(16, 16) 7 | for i in range(16): 8 | rdm[i, i] = 0 9 | 10 | plt.imshow(rdm, extent=(0, 1, 0, 1), cmap=plt.cm.jet, clim=(0, 1)) 11 | 12 | # plt.axis("off") 13 | cb = plt.colorbar() 14 | cb.ax.tick_params(labelsize=16) 15 | font = {'size': 18} 16 | 17 | cb.set_label("Dissimilarity", fontdict=font) 18 | step = float(1 / 16) 19 | x = np.arange(0.5 * step, 1 + 0.5 * step, step) 20 | y = np.arange(1 - 0.5 * step, -0.5 * step, -step) 21 | conditions = ["0°", "22.5°", "45°", "67.5°", "90°", "112.5°", "135°", "157.5°", "180°", 22 | "202.5°", "225°", "247.5°", "270°", "292.5°", "315°", "337.5°"] 23 | plt.xticks(x, conditions, fontsize=12, rotation=30, ha="right") 24 | plt.yticks(y, conditions, fontsize=12) 25 | plt.xlabel("Time 1", fontsize=16) 26 | plt.ylabel("Time 2", fontsize=16) 27 | plt.show() -------------------------------------------------------------------------------- /RSA/corrs_cal.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | from neurora.corr_cal_by_rdm import rdms_corr 3 | import h5py 4 | import time 5 | 6 | modelrdm = np.loadtxt("modelrdm/modelrdm.txt") 7 | 8 | starttime = time.clock() 9 | f = h5py.File("eegrdms/ERP.h5", "r") 10 | ori_eegrdms = np.array(f["ori"]) 11 | pos_eegrdms = np.array(f["pos"]) 12 | f.close() 13 | f = h5py.File("corrs/ERP.h5", "w") 14 | corrs = rdms_corr(modelrdm, ori_eegrdms) 15 | f.create_dataset("ori", data=corrs) 16 | corrs = rdms_corr(modelrdm, pos_eegrdms) 17 | f.create_dataset("pos", data=corrs) 18 | f.close() 19 | runtime = np.zeros([1], dtype=np.float) 20 | runtime[0] = str(time.clock() - starttime) 21 | np.savetxt("corrs/ERP_runtime.txt", runtime) 22 | 23 | starttime = time.clock() 24 | f = h5py.File("eegrdms/Alpha.h5", "r") 25 | ori_eegrdms = np.array(f["ori"]) 26 | pos_eegrdms = np.array(f["pos"]) 27 | f.close() 28 | f = h5py.File("corrs/Alpha.h5", "w") 29 | corrs = rdms_corr(modelrdm, ori_eegrdms) 30 | f.create_dataset("ori", data=corrs) 31 | corrs = rdms_corr(modelrdm, pos_eegrdms) 32 | f.create_dataset("pos", data=corrs) 33 | f.close() 34 | runtime = np.zeros([1], dtype=np.float) 35 | runtime[0] = str(time.clock() - starttime) 36 | np.savetxt("corrs/Alpha_runtime.txt", runtime) -------------------------------------------------------------------------------- /RSA/plot_crosst.py: -------------------------------------------------------------------------------- 1 | import matplotlib.pyplot as plt 2 | import h5py 3 | import numpy as np 4 | 5 | subs = ["201", "202", "203", "204", "205", "206", "207", "208", "209", 6 | "210", "212", "213", "215", "216", "217", "218"] 7 | 8 | rlts = np.zeros([16, 100, 100], dtype=np.float) 9 | 10 | subindex = 0 11 | for sub in subs: 12 | f = h5py.File("corrs_crosst/ERP_"+sub+".h5", "r") 13 | rlts[subindex] = np.array(f["ori"])[:, :, 0] 14 | f.close() 15 | subindex = subindex + 1 16 | 17 | avg = np.average(rlts, axis=0) 18 | 19 | ax=plt.gca() 20 | ax.spines["top"].set_visible(False) 21 | ax.spines["right"].set_visible(False) 22 | ax.spines["left"].set_linewidth(2) 23 | ax.spines["bottom"].set_linewidth(2) 24 | plt.fill_between([0, 0.2], -0.5, 1.5, facecolor="grey", alpha=0.2) 25 | plt.fill_between([-0.5, 0], 0, 0.2, facecolor="grey", alpha=0.2) 26 | plt.fill_between([0.2, 1.5], 0, 0.2, facecolor="grey", alpha=0.2) 27 | plt.imshow(avg, extent=(-0.5, 1.5, -0.5, 1.5), origin='low', cmap="bwr", clim=(-0.09, 0.09)) 28 | cb=plt.colorbar(ticks=[-0.07, 0.07]) 29 | cb.ax.tick_params(labelsize=12) 30 | font = {'size': 15,} 31 | cb.set_label('Representational Similarity', fontdict=font) 32 | plt.yticks(fontsize=12) 33 | plt.xticks(fontsize=12) 34 | plt.xlabel("Training Time-point (s)", fontsize=16) 35 | plt.ylabel("Test Time-point (s)", fontsize=16) 36 | plt.show() -------------------------------------------------------------------------------- /RSA/plot.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import h5py 3 | import matplotlib.pyplot as plt 4 | from scipy.stats import ttest_1samp 5 | from neurora.stuff import permutation_test 6 | 7 | f = h5py.File("corrs/ERP.h5", "r") 8 | corrs = np.array(f["ori"]) 9 | rs = corrs[:, :, 0] 10 | 11 | for sub in range(16): 12 | for t in range(100): 13 | if t<=1: 14 | rs[sub, t] = np.average(rs[sub, :t+3]) 15 | if t>1 and t<98: 16 | rs[sub, t] = np.average(rs[sub, t-2:t+3]) 17 | if t>=98: 18 | rs[sub, t] = np.average(rs[sub, t-2:]) 19 | 20 | avg = np.average(rs, axis=0) 21 | err = np.zeros([100], dtype=np.float) 22 | for t in range(100): 23 | err[t] = np.std(rs[:, t], ddof=1)/np.sqrt(16) 24 | 25 | ps = np.zeros([100], dtype=np.float) 26 | chance = np.full([16], 0) 27 | for t in range(100-35): 28 | ps[t+35] = permutation_test(rs[:, t+35], chance) 29 | if ps[t+35] < 0.05 and avg[t+35] > 0: 30 | plt.plot(t * 0.02 + 0.2, 0.42, "s", color="orangered", alpha=1) 31 | xi = [t * 0.02 + 0.2, t * 0.02 + 0.02 + 0.2] 32 | ymin = [0] 33 | ymax = [avg[t+35]-err[t+35]] 34 | plt.fill_between(xi, ymax, ymin, facecolor="orangered", alpha=0.1) 35 | 36 | ax=plt.gca() 37 | ax.spines["top"].set_visible(False) 38 | ax.spines["right"].set_visible(False) 39 | ax.spines["left"].set_linewidth(3) 40 | ax.spines["bottom"].set_linewidth(3) 41 | ax.spines['bottom'].set_position(('data', 0)) 42 | 43 | x = np.arange(-0.5+0.012, 1.5+0.012, 0.02) 44 | plt.fill_between(x, avg+err, avg-err, facecolor="orangered", alpha=0.8) 45 | plt.fill_between([0, 0.2], -1, 1, facecolor="grey", alpha=0.1) 46 | plt.ylim(-0.04*3, 0.15*3) 47 | plt.xlim(-0.5, 1.5) 48 | plt.xticks([-0.25, 0, 0.25, 0.5, 0.75, 1, 1.25, 1.5]) 49 | plt.tick_params(labelsize=12) 50 | plt.xlabel("Time (s)", fontsize=16) 51 | plt.ylabel("Representational Similarity", fontsize=16) 52 | plt.show() -------------------------------------------------------------------------------- /classification/plot_crosst.py: -------------------------------------------------------------------------------- 1 | import matplotlib.pyplot as plt 2 | import h5py 3 | import numpy as np 4 | from scipy.stats import ttest_1samp 5 | from neurora.stuff import permutation_test 6 | 7 | subs = ["201", "202", "203", "204", "205", "206", "207", "208", "209", 8 | "210", "212", "213", "215", "216", "217", "218"] 9 | 10 | rlts = np.zeros([16, 100, 100], dtype=np.float) 11 | 12 | subindex = 0 13 | f = h5py.File("svm_results/ERP_ori.h5", "r") 14 | for sub in subs: 15 | rlts[subindex] = np.array(f[sub]) 16 | subindex = subindex + 1 17 | f.close() 18 | 19 | avg = np.average(rlts, axis=0) 20 | 21 | """ps = np.zeros([65, 65], dtype=np.float) 22 | chance = np.full([16], 0.0625) 23 | for i in range(65): 24 | for j in range(65): 25 | p = permutation_test(rlts[:, i+35, j+35], chance) 26 | if p < 0.05 and avg[i+35, j+35] > 0.0625: 27 | ps[i, j] = 1 28 | else: 29 | ps[i, j] = 0 30 | 31 | newps = np.zeros([102-35, 102-35]) 32 | newps[1:101-35, 1:101-35] = ps""" 33 | 34 | ax=plt.gca() 35 | ax.spines["top"].set_visible(False) 36 | ax.spines["right"].set_visible(False) 37 | ax.spines["left"].set_linewidth(2) 38 | ax.spines["bottom"].set_linewidth(2) 39 | plt.fill_between([0, 0.2], -0.5, 1.5, facecolor="grey", alpha=0.2) 40 | plt.fill_between([-0.5, 0], 0, 0.2, facecolor="grey", alpha=0.2) 41 | plt.fill_between([0.2, 1.5], 0, 0.2, facecolor="grey", alpha=0.2) 42 | plt.imshow(avg, extent=(-0.5, 1.5, -0.5, 1.5), origin='low', cmap="bwr", clim=(0.045, 0.08)) 43 | cb=plt.colorbar(ticks=[0.05, 0.075]) 44 | cb.ax.tick_params(labelsize=12) 45 | #x = np.linspace(-0.5-0.01+0.7, 1.5+0.01, 102-35) 46 | #y = np.linspace(-0.5-0.01+0.7, 1.5+0.01, 102-35) 47 | #X, Y = np.meshgrid(x, y) 48 | #plt.contour(X, Y, newps, (0.5), colors='dimgrey', linewidths=1.5) 49 | font = {'size': 15,} 50 | cb.set_label('Classification Accuracy', fontdict=font) 51 | plt.yticks(fontsize=12) 52 | plt.xticks(fontsize=12) 53 | plt.xlabel("Training Time-point (s)", fontsize=16) 54 | plt.ylabel("Test Time-point (s)", fontsize=16) 55 | plt.show() -------------------------------------------------------------------------------- /RSA/eegrdms_cal.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | from neurora.rdm_cal import eegRDM 3 | import h5py 4 | import time 5 | 6 | subs = ["201", "202", "203", "204", "205", "206", "207", "208", "209", 7 | "210", "212", "213", "215", "216", "217", "218"] 8 | 9 | nsubs = len(subs) 10 | 11 | starttime = time.clock() 12 | 13 | ori_data = np.zeros([16, nsubs, 40, 27, 500], dtype=np.float) 14 | pos_data = np.zeros([16, nsubs, 40, 27, 500], dtype=np.float) 15 | 16 | index = 0 17 | for sub in subs: 18 | f = h5py.File("data_for_RSA/ERP/"+sub+".h5", "r") 19 | ori_subdata = np.array(f["ori"]) 20 | pos_subdata = np.array(f["pos"]) 21 | f.close() 22 | ori_data[:, index, :, :, :] = ori_subdata 23 | pos_data[:, index, :, :, :] = pos_subdata 24 | index = index + 1 25 | 26 | ori_eegrdms = eegRDM(ori_data, sub_opt=1, time_opt=1, time_win=5, time_step=5) 27 | f = h5py.File("eegrdms/ERP.h5", "w") 28 | f.create_dataset("ori", data=ori_eegrdms) 29 | pos_eegrdms = eegRDM(pos_data, sub_opt=1, time_opt=1, time_win=5, time_step=5) 30 | f.create_dataset("pos", data=pos_eegrdms) 31 | f.close() 32 | 33 | runtime = np.zeros([1], dtype=np.float) 34 | runtime[0] = str(time.clock() - starttime) 35 | np.savetxt("eegrdms/ERP_runtime.txt", runtime) 36 | 37 | 38 | starttime = time.clock() 39 | 40 | ori_data = np.zeros([16, nsubs, 40, 27, 500], dtype=np.float) 41 | pos_data = np.zeros([16, nsubs, 40, 27, 500], dtype=np.float) 42 | 43 | index = 0 44 | for sub in subs: 45 | f = h5py.File("data_for_RSA/Alpha/"+sub+".h5", "r") 46 | ori_subdata = np.array(f["ori"]) 47 | pos_subdata = np.array(f["pos"]) 48 | f.close() 49 | ori_data[:, index, :, :, :] = ori_subdata 50 | pos_data[:, index, :, :, :] = pos_subdata 51 | index = index + 1 52 | 53 | ori_eegrdms = eegRDM(ori_data, sub_opt=1, time_opt=1, time_win=5, time_step=5) 54 | f = h5py.File("eegrdms/Alpha.h5", "w") 55 | f.create_dataset("ori", data=ori_eegrdms) 56 | pos_eegrdms = eegRDM(pos_data, sub_opt=1, time_opt=1, time_win=5, time_step=5) 57 | f.create_dataset("pos", data=pos_eegrdms) 58 | f.close() 59 | 60 | runtime = np.zeros([1], dtype=np.float) 61 | runtime[0] = str(time.clock() - starttime) 62 | np.savetxt("eegrdms/Alpha_runtime.txt", runtime) -------------------------------------------------------------------------------- /RSA/pre_data.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import scipy.io as sio 3 | import h5py 4 | 5 | subs = ["201", "202", "203", "204", "205", "206", "207", "208", "209", 6 | "210", "212", "213", "215", "216", "217", "218"] 7 | 8 | for sub in subs: 9 | data = sio.loadmat("../data/ERP" + sub + ".mat")["filtData"][:, :, 250:] 10 | print(data.shape) 11 | # data.shape: n_trials, n_channels, n_times 12 | 13 | ori_label = np.loadtxt("../labels/ori_" + sub + ".txt")[:, 1] 14 | pos_label = np.loadtxt("../labels/pos_" + sub + ".txt")[:, 1] 15 | 16 | ori_subdata = np.zeros([16, 40, 27, 500], dtype=np.float) 17 | pos_subdata = np.zeros([16, 40, 27, 500], dtype=np.float) 18 | 19 | ori_labelindex = np.zeros([16], dtype=np.int) 20 | pos_labelindex = np.zeros([16], dtype=np.int) 21 | 22 | for i in range(640): 23 | label = int(ori_label[i]) 24 | ori_subdata[label, ori_labelindex[label]] = data[i] 25 | ori_labelindex[label] = ori_labelindex[label] + 1 26 | label = int(pos_label[i]) 27 | pos_subdata[label, pos_labelindex[label]] = data[i] 28 | pos_labelindex[label] = pos_labelindex[label] + 1 29 | 30 | f = h5py.File("data_for_RSA/ERP/"+sub+".h5", "w") 31 | f.create_dataset("ori", data=ori_subdata) 32 | f.create_dataset("pos", data=pos_subdata) 33 | f.close() 34 | 35 | 36 | data = sio.loadmat("../data/Alpha" + sub + ".mat")["filtData"][:, :, 250:] 37 | print(data.shape) 38 | # data.shape: n_trials, n_channels, n_times 39 | 40 | ori_label = np.loadtxt("../labels/ori_" + sub + ".txt")[:, 1] 41 | pos_label = np.loadtxt("../labels/pos_" + sub + ".txt")[:, 1] 42 | 43 | ori_subdata = np.zeros([16, 40, 27, 500], dtype=np.float) 44 | pos_subdata = np.zeros([16, 40, 27, 500], dtype=np.float) 45 | 46 | ori_labelindex = np.zeros([16], dtype=np.int) 47 | pos_labelindex = np.zeros([16], dtype=np.int) 48 | 49 | for i in range(640): 50 | label = int(ori_label[i]) 51 | ori_subdata[label, ori_labelindex[label]] = data[i] 52 | ori_labelindex[label] = ori_labelindex[label] + 1 53 | label = int(pos_label[i]) 54 | pos_subdata[label, pos_labelindex[label]] = data[i] 55 | pos_labelindex[label] = pos_labelindex[label] + 1 56 | 57 | f = h5py.File("data_for_RSA/Alpha/" + sub + ".h5", "w") 58 | f.create_dataset("ori", data=ori_subdata) 59 | f.create_dataset("pos", data=pos_subdata) 60 | f.close() -------------------------------------------------------------------------------- /classification/plot.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import h5py 3 | import matplotlib.pyplot as plt 4 | from scipy.stats import ttest_1samp 5 | from neurora.stuff import permutation_test 6 | 7 | subs = ["201", "202", "203", "204", "205", "206", "207", "208", "209", 8 | "210", "212", "213", "215", "216", "217", "218"] 9 | nsubs = len(subs) 10 | 11 | f = h5py.File("svm_results/ERP_ori.h5", "r") 12 | rlts = np.zeros([nsubs, 100], dtype=np.float) 13 | 14 | subindex = 0 15 | for sub in subs: 16 | subrlts = np.array(f[sub]) 17 | for t in range(100): 18 | rlts[subindex, t] = subrlts[t, t] 19 | 20 | for t in range(100): 21 | if t<=1: 22 | rlts[subindex, t] = np.average(rlts[subindex, :t+3]) 23 | if t>1 and t<98: 24 | rlts[subindex, t] = np.average(rlts[subindex, t-2:t+3]) 25 | if t>=98: 26 | rlts[subindex, t] = np.average(rlts[subindex, t-2:]) 27 | 28 | subindex = subindex + 1 29 | 30 | f.close() 31 | 32 | avg = np.average(rlts, axis=0) 33 | err = np.zeros([100], dtype=np.float) 34 | for t in range(100): 35 | err[t] = np.std(rlts[:, t], ddof=1)/np.sqrt(nsubs) 36 | print(avg.shape) 37 | print(err.shape) 38 | 39 | ps = np.zeros([100], dtype=np.float) 40 | chance = np.full([16], 0.0625) 41 | for t in range(100-35): 42 | ps[t+35] = permutation_test(rlts[:, t+35], chance) 43 | if ps[t+35] < 0.05 and avg[t+35] > 0.0625: 44 | plt.plot(t * 0.02 + 0.2, 0.148, "s", color="orangered", alpha=0.8) 45 | xi = [t * 0.02 + 0.2, t * 0.02 + 0.02 + 0.2] 46 | ymin = [0.0625] 47 | ymax = [avg[t+35]-err[t+35]] 48 | plt.fill_between(xi, ymax, ymin, facecolor="orangered", alpha=0.15) 49 | 50 | ax=plt.gca() 51 | ax.spines["top"].set_visible(False) 52 | ax.spines["right"].set_visible(False) 53 | ax.spines["left"].set_linewidth(3) 54 | ax.spines["bottom"].set_linewidth(3) 55 | ax.spines['bottom'].set_position(('data', 0.0625)) 56 | 57 | x = np.arange(-0.5+0.008, 1.5+0.008, 0.02) 58 | 59 | #plt.plot(x, avg) 60 | plt.fill_between(x, avg+err, avg-err, facecolor="orangered", alpha=0.8) 61 | plt.fill_between([0, 0.2], -1, 1, facecolor="grey", alpha=0.1) 62 | #plt.axhline(y=0.0625, c="darkgrey", alpha=0.7, ls="--", linewidth="5") 63 | 64 | plt.ylim(0.05, 0.15) 65 | plt.xlim(-0.5, 1.5) 66 | plt.xticks([-0.25, 0, 0.25, 0.5, 0.75, 1, 1.25, 1.5]) 67 | plt.tick_params(labelsize=12) 68 | plt.xlabel("Time (s)", fontsize=16) 69 | plt.ylabel("Classification Accuracy", fontsize=16) 70 | plt.show() 71 | 72 | -------------------------------------------------------------------------------- /classification/pre_data.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import scipy.io as sio 3 | import h5py 4 | 5 | subs = ["201", "202", "203", "204", "205", "206", "207", "208", "209", 6 | "210", "212", "213", "215", "216", "217", "218"] 7 | 8 | for sub in subs: 9 | data = sio.loadmat("../data/ERP" + sub + ".mat")["filtData"][:, :, 250:] 10 | print(data.shape) 11 | # data.shape: n_trials, n_channels, n_times 12 | 13 | ori_label = np.loadtxt("../labels/ori_" + sub + ".txt")[:, 1] 14 | pos_label = np.loadtxt("../labels/pos_" + sub + ".txt")[:, 1] 15 | 16 | ori_subdata500 = np.zeros([16, 40, 27, 500], dtype=np.float) 17 | pos_subdata500 = np.zeros([16, 40, 27, 500], dtype=np.float) 18 | 19 | ori_labelindex = np.zeros([16], dtype=np.int) 20 | pos_labelindex = np.zeros([16], dtype=np.int) 21 | 22 | for i in range(640): 23 | label = int(ori_label[i]) 24 | ori_subdata500[label, ori_labelindex[label]] = data[i] 25 | ori_labelindex[label] = ori_labelindex[label] + 1 26 | label = int(pos_label[i]) 27 | pos_subdata500[label, pos_labelindex[label]] = data[i] 28 | pos_labelindex[label] = pos_labelindex[label] + 1 29 | 30 | ori_subdata = np.zeros([16, 40, 27, 100], dtype=np.float) 31 | pos_subdata = np.zeros([16, 40, 27, 100], dtype=np.float) 32 | 33 | for t in range(100): 34 | ori_subdata[:, :, :, t] = np.average(ori_subdata500[:, :, :, t*5:t*5+5], axis=3) 35 | pos_subdata[:, :, :, t] = np.average(pos_subdata500[:, :, :, t*5:t*5+5], axis=3) 36 | 37 | f = h5py.File("data_for_classification/ERP/"+sub+".h5", "w") 38 | f.create_dataset("ori", data=ori_subdata) 39 | f.create_dataset("pos", data=pos_subdata) 40 | f.close() 41 | 42 | data = sio.loadmat("../data/Alpha" + sub + ".mat")["filtData"][:, :, 250:] 43 | print(data.shape) 44 | # data.shape: n_trials, n_channels, n_times 45 | 46 | ori_label = np.loadtxt("../labels/ori_" + sub + ".txt")[:, 1] 47 | pos_label = np.loadtxt("../labels/pos_" + sub + ".txt")[:, 1] 48 | 49 | ori_subdata500 = np.zeros([16, 40, 27, 500], dtype=np.float) 50 | pos_subdata500 = np.zeros([16, 40, 27, 500], dtype=np.float) 51 | 52 | ori_labelindex = np.zeros([16], dtype=np.int) 53 | pos_labelindex = np.zeros([16], dtype=np.int) 54 | 55 | for i in range(640): 56 | label = int(ori_label[i]) 57 | ori_subdata500[label, ori_labelindex[label]] = data[i] 58 | ori_labelindex[label] = ori_labelindex[label] + 1 59 | label = int(pos_label[i]) 60 | pos_subdata500[label, pos_labelindex[label]] = data[i] 61 | pos_labelindex[label] = pos_labelindex[label] + 1 62 | 63 | ori_subdata = np.zeros([16, 40, 27, 100], dtype=np.float) 64 | pos_subdata = np.zeros([16, 40, 27, 100], dtype=np.float) 65 | 66 | for t in range(100): 67 | ori_subdata[:, :, :, t] = np.average(ori_subdata500[:, :, :, t * 5:t * 5 + 5], axis=3) 68 | pos_subdata[:, :, :, t] = np.average(pos_subdata500[:, :, :, t * 5:t * 5 + 5], axis=3) 69 | 70 | f = h5py.File("data_for_classification/Alpha/" + sub + ".h5", "w") 71 | f.create_dataset("ori", data=ori_subdata) 72 | f.create_dataset("pos", data=pos_subdata) 73 | f.close() -------------------------------------------------------------------------------- /RSA/corrs_crosst_cal.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | from neurora.rdm_cal import eegRDM 3 | from neurora.stuff import limtozero 4 | from scipy.stats import pearsonr, spearmanr 5 | import h5py 6 | import time 7 | 8 | def crosstime_corrs_cal(eegdata, modelrdm, time_win=5, time_step=5): 9 | # shape of data: [n_conditions, n_trials, n_channels, n_times] 10 | cons, trials, chls, ts = np.shape(eegdata) 11 | ts = int((ts - time_win) / time_step) + 1 12 | 13 | data = np.zeros([ts, cons, chls, time_win], dtype=np.float) 14 | for j in range(ts): 15 | for k in range(cons): 16 | for l in range(chls): 17 | for m in range(time_win): 18 | data[j, k, l, m] = np.average(eegdata[k, :, l, j * time_step + m]) 19 | data = np.reshape(data, [ts, cons, chls * time_win]) 20 | 21 | corrs = np.zeros([ts, ts, 2], dtype=np.float) 22 | 23 | v2 = np.zeros([cons*(cons-1)], dtype=np.float) 24 | index = 0 25 | for i in range(cons): 26 | for j in range(cons): 27 | if i != j: 28 | v2[index] = modelrdm[i, j] 29 | index = index + 1 30 | 31 | for t1 in range(ts): 32 | print(t1) 33 | for t2 in range(ts): 34 | v1 = np.zeros([cons*(cons-1)], dtype=np.float) 35 | index = 0 36 | for k in range(cons): 37 | for l in range(cons): 38 | if k != l: 39 | r = pearsonr(data[t1, k], data[t2, l])[0] 40 | v1[index] = limtozero(1 - abs(r)) 41 | index = index + 1 42 | corrs[t1, t2] = spearmanr(v1, v2) 43 | 44 | return corrs 45 | 46 | 47 | subs = ["201", "202", "203", "204", "205", "206", "207", "208", "209", 48 | "210", "212", "213", "215", "216", "217", "218"] 49 | 50 | nsubs = len(subs) 51 | 52 | modelrdm = np.loadtxt("modelrdm/modelrdm.txt") 53 | 54 | starttime = time.clock() 55 | 56 | for sub in subs: 57 | f = h5py.File("data_for_RSA/ERP/" + sub + ".h5", "r") 58 | ori_subdata = np.array(f["ori"]) 59 | pos_subdata = np.array(f["pos"]) 60 | f.close() 61 | f = h5py.File("corrs_crosst/ERP_"+str(sub)+".h5", "w") 62 | corrs = crosstime_corrs_cal(ori_subdata, modelrdm) 63 | f.create_dataset("ori", data=corrs) 64 | corrs = crosstime_corrs_cal(pos_subdata, modelrdm) 65 | f.create_dataset("pos", data=corrs) 66 | f.close() 67 | 68 | runtime = np.zeros([1], dtype=np.float) 69 | runtime[0] = str(time.clock() - starttime) 70 | np.savetxt("corrs_crosst/ERP_runtime.txt", runtime) 71 | 72 | 73 | """starttime = time.clock() 74 | 75 | for sub in subs: 76 | f = h5py.File("data_for_RSA/Alpha/" + sub + ".h5", "r") 77 | ori_subdata = np.array(f["ori"]) 78 | pos_subdata = np.array(f["pos"]) 79 | f.close() 80 | f = h5py.File("corrs_crosst/Alpha_"+str(sub)+".h5", "w") 81 | corrs = crosstime_corrs_cal(ori_subdata, modelrdm) 82 | f.create_dataset("ori", data=corrs) 83 | corrs = crosstime_corrs_cal(pos_subdata, modelrdm) 84 | f.create_dataset("pos", data=corrs) 85 | f.close() 86 | 87 | runtime = np.zeros([1], dtype=np.float) 88 | runtime[0] = str(time.clock() - starttime) 89 | np.savetxt("corrs_crosst/Alpha_runtime.txt", runtime)""" -------------------------------------------------------------------------------- /RSA/corrs_crosst_cal_alpha.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | from neurora.rdm_cal import eegRDM 3 | from neurora.stuff import limtozero 4 | from scipy.stats import pearsonr, spearmanr 5 | import h5py 6 | import time 7 | 8 | def crosstime_corrs_cal(eegdata, modelrdm, time_win=5, time_step=5): 9 | # shape of data: [n_conditions, n_trials, n_channels, n_times] 10 | cons, trials, chls, ts = np.shape(eegdata) 11 | ts = int((ts - time_win) / time_step) + 1 12 | 13 | data = np.zeros([ts, cons, chls, time_win], dtype=np.float) 14 | for j in range(ts): 15 | for k in range(cons): 16 | for l in range(chls): 17 | for m in range(time_win): 18 | data[j, k, l, m] = np.average(eegdata[k, :, l, j * time_step + m]) 19 | data = np.reshape(data, [ts, cons, chls * time_win]) 20 | 21 | corrs = np.zeros([ts, ts, 2], dtype=np.float) 22 | 23 | v2 = np.zeros([cons*(cons-1)], dtype=np.float) 24 | index = 0 25 | for i in range(cons): 26 | for j in range(cons): 27 | if i != j: 28 | v2[index] = modelrdm[i, j] 29 | index = index + 1 30 | 31 | for t1 in range(ts): 32 | print(t1) 33 | for t2 in range(ts): 34 | v1 = np.zeros([cons*(cons-1)], dtype=np.float) 35 | index = 0 36 | for k in range(cons): 37 | for l in range(cons): 38 | if k != l: 39 | r = pearsonr(data[t1, k], data[t2, l])[0] 40 | v1[index] = limtozero(1 - abs(r)) 41 | index = index + 1 42 | corrs[t1, t2] = spearmanr(v1, v2) 43 | 44 | return corrs 45 | 46 | 47 | subs = ["201", "202", "203", "204", "205", "206", "207", "208", "209", 48 | "210", "212", "213", "215", "216", "217", "218"] 49 | 50 | nsubs = len(subs) 51 | 52 | modelrdm = np.loadtxt("modelrdm/modelrdm.txt") 53 | 54 | """starttime = time.clock() 55 | 56 | for sub in subs: 57 | f = h5py.File("data_for_RSA/ERP/" + sub + ".h5", "r") 58 | ori_subdata = np.array(f["ori"]) 59 | pos_subdata = np.array(f["pos"]) 60 | f.close() 61 | f = h5py.File("corrs_crosst/ERP_"+str(sub)+".h5", "w") 62 | ori_eegrdms = crosstime_corrs_cal(ori_subdata, modelrdm) 63 | f.create_dataset("ori", data=ori_eegrdms) 64 | pos_eegrdms = crosstime_corrs_cal(pos_subdata, modelrdm) 65 | f.create_dataset("pos", data=pos_eegrdms) 66 | f.close() 67 | 68 | runtime = np.zeros([1], dtype=np.float) 69 | runtime[0] = str(time.clock() - starttime) 70 | np.savetxt("corrs_crosst/ERP_runtime.txt", runtime)""" 71 | 72 | 73 | starttime = time.clock() 74 | 75 | for sub in subs: 76 | f = h5py.File("data_for_RSA/Alpha/" + sub + ".h5", "r") 77 | ori_subdata = np.array(f["ori"]) 78 | pos_subdata = np.array(f["pos"]) 79 | f.close() 80 | f = h5py.File("corrs_crosst/Alpha_"+str(sub)+".h5", "w") 81 | ori_eegrdms = crosstime_corrs_cal(ori_subdata, modelrdm) 82 | f.create_dataset("ori", data=ori_eegrdms) 83 | pos_eegrdms = crosstime_corrs_cal(pos_subdata, modelrdm) 84 | f.create_dataset("pos", data=pos_eegrdms) 85 | f.close() 86 | 87 | runtime = np.zeros([1], dtype=np.float) 88 | runtime[0] = str(time.clock() - starttime) 89 | np.savetxt("corrs_crosst/Alpha_runtime.txt", runtime) -------------------------------------------------------------------------------- /RSA/modelrdm/modelrdm.txt: -------------------------------------------------------------------------------- 1 | 0.000000000000000000e+00 1.250000000000000000e-01 2.500000000000000000e-01 3.750000000000000000e-01 5.000000000000000000e-01 6.250000000000000000e-01 7.500000000000000000e-01 8.750000000000000000e-01 1.000000000000000000e+00 8.750000000000000000e-01 7.500000000000000000e-01 6.250000000000000000e-01 5.000000000000000000e-01 3.750000000000000000e-01 2.500000000000000000e-01 1.250000000000000000e-01 2 | 1.250000000000000000e-01 0.000000000000000000e+00 1.250000000000000000e-01 2.500000000000000000e-01 3.750000000000000000e-01 5.000000000000000000e-01 6.250000000000000000e-01 7.500000000000000000e-01 8.750000000000000000e-01 1.000000000000000000e+00 8.750000000000000000e-01 7.500000000000000000e-01 6.250000000000000000e-01 5.000000000000000000e-01 3.750000000000000000e-01 2.500000000000000000e-01 3 | 2.500000000000000000e-01 1.250000000000000000e-01 0.000000000000000000e+00 1.250000000000000000e-01 2.500000000000000000e-01 3.750000000000000000e-01 5.000000000000000000e-01 6.250000000000000000e-01 7.500000000000000000e-01 8.750000000000000000e-01 1.000000000000000000e+00 8.750000000000000000e-01 7.500000000000000000e-01 6.250000000000000000e-01 5.000000000000000000e-01 3.750000000000000000e-01 4 | 3.750000000000000000e-01 2.500000000000000000e-01 1.250000000000000000e-01 0.000000000000000000e+00 1.250000000000000000e-01 2.500000000000000000e-01 3.750000000000000000e-01 5.000000000000000000e-01 6.250000000000000000e-01 7.500000000000000000e-01 8.750000000000000000e-01 1.000000000000000000e+00 8.750000000000000000e-01 7.500000000000000000e-01 6.250000000000000000e-01 5.000000000000000000e-01 5 | 5.000000000000000000e-01 3.750000000000000000e-01 2.500000000000000000e-01 1.250000000000000000e-01 0.000000000000000000e+00 1.250000000000000000e-01 2.500000000000000000e-01 3.750000000000000000e-01 5.000000000000000000e-01 6.250000000000000000e-01 7.500000000000000000e-01 8.750000000000000000e-01 1.000000000000000000e+00 8.750000000000000000e-01 7.500000000000000000e-01 6.250000000000000000e-01 6 | 6.250000000000000000e-01 5.000000000000000000e-01 3.750000000000000000e-01 2.500000000000000000e-01 1.250000000000000000e-01 0.000000000000000000e+00 1.250000000000000000e-01 2.500000000000000000e-01 3.750000000000000000e-01 5.000000000000000000e-01 6.250000000000000000e-01 7.500000000000000000e-01 8.750000000000000000e-01 1.000000000000000000e+00 8.750000000000000000e-01 7.500000000000000000e-01 7 | 7.500000000000000000e-01 6.250000000000000000e-01 5.000000000000000000e-01 3.750000000000000000e-01 2.500000000000000000e-01 1.250000000000000000e-01 0.000000000000000000e+00 1.250000000000000000e-01 2.500000000000000000e-01 3.750000000000000000e-01 5.000000000000000000e-01 6.250000000000000000e-01 7.500000000000000000e-01 8.750000000000000000e-01 1.000000000000000000e+00 8.750000000000000000e-01 8 | 8.750000000000000000e-01 7.500000000000000000e-01 6.250000000000000000e-01 5.000000000000000000e-01 3.750000000000000000e-01 2.500000000000000000e-01 1.250000000000000000e-01 0.000000000000000000e+00 1.250000000000000000e-01 2.500000000000000000e-01 3.750000000000000000e-01 5.000000000000000000e-01 6.250000000000000000e-01 7.500000000000000000e-01 8.750000000000000000e-01 1.000000000000000000e+00 9 | 1.000000000000000000e+00 8.750000000000000000e-01 7.500000000000000000e-01 6.250000000000000000e-01 5.000000000000000000e-01 3.750000000000000000e-01 2.500000000000000000e-01 1.250000000000000000e-01 0.000000000000000000e+00 1.250000000000000000e-01 2.500000000000000000e-01 3.750000000000000000e-01 5.000000000000000000e-01 6.250000000000000000e-01 7.500000000000000000e-01 8.750000000000000000e-01 10 | 8.750000000000000000e-01 1.000000000000000000e+00 8.750000000000000000e-01 7.500000000000000000e-01 6.250000000000000000e-01 5.000000000000000000e-01 3.750000000000000000e-01 2.500000000000000000e-01 1.250000000000000000e-01 0.000000000000000000e+00 1.250000000000000000e-01 2.500000000000000000e-01 3.750000000000000000e-01 5.000000000000000000e-01 6.250000000000000000e-01 7.500000000000000000e-01 11 | 7.500000000000000000e-01 8.750000000000000000e-01 1.000000000000000000e+00 8.750000000000000000e-01 7.500000000000000000e-01 6.250000000000000000e-01 5.000000000000000000e-01 3.750000000000000000e-01 2.500000000000000000e-01 1.250000000000000000e-01 0.000000000000000000e+00 1.250000000000000000e-01 2.500000000000000000e-01 3.750000000000000000e-01 5.000000000000000000e-01 6.250000000000000000e-01 12 | 6.250000000000000000e-01 7.500000000000000000e-01 8.750000000000000000e-01 1.000000000000000000e+00 8.750000000000000000e-01 7.500000000000000000e-01 6.250000000000000000e-01 5.000000000000000000e-01 3.750000000000000000e-01 2.500000000000000000e-01 1.250000000000000000e-01 0.000000000000000000e+00 1.250000000000000000e-01 2.500000000000000000e-01 3.750000000000000000e-01 5.000000000000000000e-01 13 | 5.000000000000000000e-01 6.250000000000000000e-01 7.500000000000000000e-01 8.750000000000000000e-01 1.000000000000000000e+00 8.750000000000000000e-01 7.500000000000000000e-01 6.250000000000000000e-01 5.000000000000000000e-01 3.750000000000000000e-01 2.500000000000000000e-01 1.250000000000000000e-01 0.000000000000000000e+00 1.250000000000000000e-01 2.500000000000000000e-01 3.750000000000000000e-01 14 | 3.750000000000000000e-01 5.000000000000000000e-01 6.250000000000000000e-01 7.500000000000000000e-01 8.750000000000000000e-01 1.000000000000000000e+00 8.750000000000000000e-01 7.500000000000000000e-01 6.250000000000000000e-01 5.000000000000000000e-01 3.750000000000000000e-01 2.500000000000000000e-01 1.250000000000000000e-01 0.000000000000000000e+00 1.250000000000000000e-01 2.500000000000000000e-01 15 | 2.500000000000000000e-01 3.750000000000000000e-01 5.000000000000000000e-01 6.250000000000000000e-01 7.500000000000000000e-01 8.750000000000000000e-01 1.000000000000000000e+00 8.750000000000000000e-01 7.500000000000000000e-01 6.250000000000000000e-01 5.000000000000000000e-01 3.750000000000000000e-01 2.500000000000000000e-01 1.250000000000000000e-01 0.000000000000000000e+00 1.250000000000000000e-01 16 | 1.250000000000000000e-01 2.500000000000000000e-01 3.750000000000000000e-01 5.000000000000000000e-01 6.250000000000000000e-01 7.500000000000000000e-01 8.750000000000000000e-01 1.000000000000000000e+00 8.750000000000000000e-01 7.500000000000000000e-01 6.250000000000000000e-01 5.000000000000000000e-01 3.750000000000000000e-01 2.500000000000000000e-01 1.250000000000000000e-01 0.000000000000000000e+00 17 | -------------------------------------------------------------------------------- /classification/svm_decoding.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import scipy.io as sio 3 | import random 4 | import h5py 5 | from sklearn.svm import SVC 6 | from sklearn.model_selection import StratifiedKFold 7 | from sklearn.metrics import accuracy_score 8 | import time 9 | 10 | subs = ["201", "202", "203", "204", "205", "206", "207", "208", "209", 11 | "210", "212", "213", "215", "216", "217", "218"] 12 | 13 | runtime = np.zeros([len(subs)], dtype=np.float) 14 | subindex = 0 15 | f = h5py.File("svm_results/ERP_ori.h5", "w") 16 | for sub in subs: 17 | starttime = time.clock() 18 | fdata = h5py.File("data_for_classification/ERP/"+sub+".h5", "r") 19 | data = np.array(fdata["ori"]) 20 | fdata.close() 21 | print(data.shape) 22 | acc = np.zeros([100, 100, 100, 3], dtype=np.float) 23 | for k in range(100): 24 | print(sub, k) 25 | index_trials = np.array(range(40)) 26 | shuffle = np.random.permutation(index_trials) 27 | newdata = data[:, shuffle[:39]] 28 | block_data = np.zeros([3, 16, 27, 100], dtype=np.float) 29 | for i in range(3): 30 | block_data[i] = np.average(newdata[:, i*13:i*13+13], axis=1) 31 | y_train = np.zeros([2*16], dtype=np.int) 32 | for i in range(2): 33 | for j in range(16): 34 | y_train[i*16+j] = j 35 | y_test = np.zeros([16], dtype=np.int) 36 | for i in range(16): 37 | y_test[i] = i 38 | for i in range(3): 39 | x_test = block_data[i] 40 | x_train = np.zeros([2, 16, 27, 100], dtype=np.float) 41 | index = 0 42 | for j in range(3): 43 | if j != i: 44 | x_train[index] = block_data[j] 45 | index = index + 1 46 | x_train = np.reshape(x_train, [2*16, 27, 100]) 47 | for t in range(100): 48 | x_train_t = x_train[:, :, t] 49 | x_test_t = x_test[:, :, t] 50 | svm = SVC(kernel='linear', decision_function_shape='ovr') 51 | svm.fit(x_train_t, y_train) 52 | y_pred = svm.predict(x_test_t) 53 | acc[k, t, t, i] = accuracy_score(y_test, y_pred) 54 | for tt in range(99): 55 | if tt < t: 56 | x_test_tt = x_test[:, :, tt] 57 | y_pred = svm.predict(x_test_tt) 58 | acc[k, t, tt, i] = accuracy_score(y_test, y_pred) 59 | if tt >= t: 60 | x_test_tt = x_test[:, :, tt+1] 61 | y_pred = svm.predict(x_test_tt) 62 | acc[k, t, tt+1, i] = accuracy_score(y_test, y_pred) 63 | f.create_dataset(sub, data=np.average(acc, axis=(0, 3))) 64 | runtime = np.zeros([1], dtype=np.float) 65 | runtime[0] = str(time.clock() - starttime) 66 | np.savetxt("svm_results/ERP_ori_runtime.txt", runtime) 67 | 68 | 69 | runtime = np.zeros([len(subs)], dtype=np.float) 70 | subindex = 0 71 | f = h5py.File("svm_results/ERP_pos.h5", "w") 72 | for sub in subs: 73 | starttime = time.clock() 74 | fdata = h5py.File("data_for_classification/ERP/"+sub+".h5", "r") 75 | data = np.array(fdata["pos"]) 76 | fdata.close() 77 | print(data.shape) 78 | acc = np.zeros([100, 100, 100, 3], dtype=np.float) 79 | for k in range(100): 80 | print(sub, k) 81 | index_trials = np.array(range(40)) 82 | shuffle = np.random.permutation(index_trials) 83 | newdata = data[:, shuffle[:39]] 84 | block_data = np.zeros([3, 16, 27, 100], dtype=np.float) 85 | for i in range(3): 86 | block_data[i] = np.average(newdata[:, i*13:i*13+13], axis=1) 87 | y_train = np.zeros([2*16], dtype=np.int) 88 | for i in range(2): 89 | for j in range(16): 90 | y_train[i*16+j] = j 91 | y_test = np.zeros([16], dtype=np.int) 92 | for i in range(16): 93 | y_test[i] = i 94 | for i in range(3): 95 | x_test = block_data[i] 96 | x_train = np.zeros([2, 16, 27, 100], dtype=np.float) 97 | index = 0 98 | for j in range(3): 99 | if j != i: 100 | x_train[index] = block_data[j] 101 | index = index + 1 102 | x_train = np.reshape(x_train, [2*16, 27, 100]) 103 | for t in range(100): 104 | x_train_t = x_train[:, :, t] 105 | x_test_t = x_test[:, :, t] 106 | svm = SVC(kernel='linear', decision_function_shape='ovr') 107 | svm.fit(x_train_t, y_train) 108 | y_pred = svm.predict(x_test_t) 109 | acc[k, t, t, i] = accuracy_score(y_test, y_pred) 110 | for tt in range(99): 111 | if tt < t: 112 | x_test_tt = x_test[:, :, tt] 113 | y_pred = svm.predict(x_test_tt) 114 | acc[k, t, tt, i] = accuracy_score(y_test, y_pred) 115 | if tt >= t: 116 | x_test_tt = x_test[:, :, tt+1] 117 | y_pred = svm.predict(x_test_tt) 118 | acc[k, t, tt+1, i] = accuracy_score(y_test, y_pred) 119 | f.create_dataset(sub, data=np.average(acc, axis=(0, 3))) 120 | runtime = np.zeros([1], dtype=np.float) 121 | runtime[0] = str(time.clock() - starttime) 122 | np.savetxt("svm_results/ERP_pos_runtime.txt", runtime) 123 | 124 | 125 | runtime = np.zeros([len(subs)], dtype=np.float) 126 | subindex = 0 127 | f = h5py.File("svm_results/Alpha_ori.h5", "w") 128 | for sub in subs: 129 | starttime = time.clock() 130 | fdata = h5py.File("data_for_classification/Alpha/"+sub+".h5", "r") 131 | data = np.array(fdata["ori"]) 132 | fdata.close() 133 | print(data.shape) 134 | acc = np.zeros([100, 100, 100, 3], dtype=np.float) 135 | for k in range(100): 136 | print(sub, k) 137 | index_trials = np.array(range(40)) 138 | shuffle = np.random.permutation(index_trials) 139 | newdata = data[:, shuffle[:39]] 140 | block_data = np.zeros([3, 16, 27, 100], dtype=np.float) 141 | for i in range(3): 142 | block_data[i] = np.average(newdata[:, i*13:i*13+13], axis=1) 143 | y_train = np.zeros([2*16], dtype=np.int) 144 | for i in range(2): 145 | for j in range(16): 146 | y_train[i*16+j] = j 147 | y_test = np.zeros([16], dtype=np.int) 148 | for i in range(16): 149 | y_test[i] = i 150 | for i in range(3): 151 | x_test = block_data[i] 152 | x_train = np.zeros([2, 16, 27, 100], dtype=np.float) 153 | index = 0 154 | for j in range(3): 155 | if j != i: 156 | x_train[index] = block_data[j] 157 | index = index + 1 158 | x_train = np.reshape(x_train, [2*16, 27, 100]) 159 | for t in range(100): 160 | x_train_t = x_train[:, :, t] 161 | x_test_t = x_test[:, :, t] 162 | svm = SVC(kernel='linear', decision_function_shape='ovr') 163 | svm.fit(x_train_t, y_train) 164 | y_pred = svm.predict(x_test_t) 165 | acc[k, t, t, i] = accuracy_score(y_test, y_pred) 166 | for tt in range(99): 167 | if tt < t: 168 | x_test_tt = x_test[:, :, tt] 169 | y_pred = svm.predict(x_test_tt) 170 | acc[k, t, tt, i] = accuracy_score(y_test, y_pred) 171 | if tt >= t: 172 | x_test_tt = x_test[:, :, tt+1] 173 | y_pred = svm.predict(x_test_tt) 174 | acc[k, t, tt+1, i] = accuracy_score(y_test, y_pred) 175 | f.create_dataset(sub, data=np.average(acc, axis=(0, 3))) 176 | runtime = np.zeros([1], dtype=np.float) 177 | runtime[0] = str(time.clock() - starttime) 178 | np.savetxt("svm_results/Alpha_ori_runtime.txt", runtime) 179 | 180 | 181 | runtime = np.zeros([len(subs)], dtype=np.float) 182 | subindex = 0 183 | f = h5py.File("svm_results/Alpha_pos.h5", "w") 184 | for sub in subs: 185 | starttime = time.clock() 186 | fdata = h5py.File("data_for_classification/Alpha/"+sub+".h5", "r") 187 | data = np.array(fdata["pos"]) 188 | fdata.close() 189 | print(data.shape) 190 | acc = np.zeros([100, 100, 100, 3], dtype=np.float) 191 | for k in range(100): 192 | print(sub, k) 193 | index_trials = np.array(range(40)) 194 | shuffle = np.random.permutation(index_trials) 195 | newdata = data[:, shuffle[:39]] 196 | block_data = np.zeros([3, 16, 27, 100], dtype=np.float) 197 | for i in range(3): 198 | block_data[i] = np.average(newdata[:, i*13:i*13+13], axis=1) 199 | y_train = np.zeros([2*16], dtype=np.int) 200 | for i in range(2): 201 | for j in range(16): 202 | y_train[i*16+j] = j 203 | y_test = np.zeros([16], dtype=np.int) 204 | for i in range(16): 205 | y_test[i] = i 206 | for i in range(3): 207 | x_test = block_data[i] 208 | x_train = np.zeros([2, 16, 27, 100], dtype=np.float) 209 | index = 0 210 | for j in range(3): 211 | if j != i: 212 | x_train[index] = block_data[j] 213 | index = index + 1 214 | x_train = np.reshape(x_train, [2*16, 27, 100]) 215 | for t in range(100): 216 | x_train_t = x_train[:, :, t] 217 | x_test_t = x_test[:, :, t] 218 | svm = SVC(kernel='linear', decision_function_shape='ovr') 219 | svm.fit(x_train_t, y_train) 220 | y_pred = svm.predict(x_test_t) 221 | acc[k, t, t, i] = accuracy_score(y_test, y_pred) 222 | for tt in range(99): 223 | if tt < t: 224 | x_test_tt = x_test[:, :, tt] 225 | y_pred = svm.predict(x_test_tt) 226 | acc[k, t, tt, i] = accuracy_score(y_test, y_pred) 227 | if tt >= t: 228 | x_test_tt = x_test[:, :, tt+1] 229 | y_pred = svm.predict(x_test_tt) 230 | acc[k, t, tt+1, i] = accuracy_score(y_test, y_pred) 231 | f.create_dataset(sub, data=np.average(acc, axis=(0, 3))) 232 | runtime = np.zeros([1], dtype=np.float) 233 | runtime[0] = str(time.clock() - starttime) 234 | np.savetxt("svm_results/Alpha_pos_runtime.txt", runtime) --------------------------------------------------------------------------------