-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbrain.py
70 lines (52 loc) · 1.79 KB
/
brain.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import matplotlib.pyplot as plt
import pickle
import numpy as np
from tqdm import tqdm
from mne.decoding import CSP, UnsupervisedSpatialFilter
import numpy as np
from sklearn.discriminant_analysis import LinearDiscriminantAnalysis
from sklearn.decomposition import PCA
from sklearn.pipeline import Pipeline
import pyriemann
from eeg.data import get_data
from eeg.laplacian import compute_scalp_eigenvectors_and_values
from eeg.utils import results, get_cv, avg_power_matrix
from eeg.experiments.eigen_fgmdm import OldED
from eeg.plot_reproduction import assemble_classifer_CSPLDA
from tqdm import tqdm
from sklearn.svm import SVC
from sklearn.model_selection import cross_val_score
from sklearn.preprocessing import StandardScaler
def load_np_array_from_pkl(file_path):
with open(file_path, 'rb') as file:
np_array = pickle.load(file)
return np_array
if __name__ == '__main__':
X, y = get_data()
cv = get_cv()
S_raw_tilde = load_np_array_from_pkl('inverseproblem/array_data.pkl')
S_raw = []
for sr, xr in zip(S_raw_tilde, X):
U, S, VT = np.linalg.svd(xr, full_matrices=False)
Psi_xr = VT.T
K = 3
Psi_xr_reduced = Psi_xr[:, :K]
s = sr @ Psi_xr_reduced.T
S_raw.append(s)
S = np.array([avg_power_matrix(m) for m in S_raw])
scaler = StandardScaler()
S_scaled = scaler.fit_transform(S)
svm_clf = SVC(kernel='linear', C=1)
score = results(svm_clf, S_scaled, y, cv)
print(score)
"""
files = glob.glob("covariance_matrices/*.pkl")
np_arrays = []
for file in files:
array = load_np_array_from_pkl(file)
np_arrays.append(array)
Xcov = np.array(np_arrays)
FgMDM = pyriemann.classification.FgMDM()
FgMDM_score = results(FgMDM, Xcov, y, cv)
print(FgMDM_score)
"""