-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path2.prepare.py
112 lines (67 loc) · 2.48 KB
/
2.prepare.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# -*- coding: utf-8 -*-
"""
Created on Sun Sep 27 11:19:15 2020
@author: REZA
"""
# -*- coding: utf-8 -*-
"""
Created on Thu Aug 27 10:29:14 2020
@author: REZA
"""
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from scipy.io import loadmat
import csv
#%%
Alldata = np.load('data/Alldata.npy').astype('float32')
print('[info] All data of 64 electrodes are here!')
#%%Normalize
xx= np.array(Alldata)
NormalizedAll = xx - xx.min();
NormalizedAll = NormalizedAll / xx.max();
NormalizedAll=NormalizedAll.reshape(64,Alldata.shape[0])
print('[info] Normalizezed')
#%%Covariance
print('[info] Calculating Covariance matrix')
covariance_matrix = np.cov(NormalizedAll);
print('[info] covariance of Normalized/Standardize data is calculated')
np.save("matrices/covariance", covariance_matrix)
plt.style.use('seaborn-poster')
plt.imshow(covariance_matrix,extent=[0,64, 0, 64],cmap='viridis')
#%% Pearson matrix and its ABS
print('[info] Calculating Pearson matrix')
Pearson_matrix= np.corrcoef(NormalizedAll)
np.savetxt("matrices/Pearson_matrix.csv", Pearson_matrix)
print('[info] Pearson matrix of Normalized/Standardize data is calculated')
print('[info] Calculating Absolute Pearson matrix')
Absolute_Pearson_matrix = abs(Pearson_matrix);
np.save("matrices/Absolute_Pearson_matrix", Absolute_Pearson_matrix)
print('[info] Absolute Pearson matrix Calculated')
plt.figure()
plt.imshow(Pearson_matrix,extent=[0,64, 0, 64],cmap='viridis')
plt.figure()
plt.imshow(Absolute_Pearson_matrix,extent=[0,64, 0, 64],cmap='viridis')
#%% Adjacency Matrix
print('[info] Calculating Adjacency Matrix')
Eye_Matrix = np.eye(64, 64);
Adjacency_Matrix = Absolute_Pearson_matrix - Eye_Matrix;
np.save("matrices/Adjacency_Matrix", Adjacency_Matrix)
print('[info] Adjacency Matrix is Calculated')
plt.figure()
plt.imshow(Adjacency_Matrix,extent=[0,64,0, 64],cmap='viridis')
#%% Degree Matrix
print('[info] Calculating Degree Matrix')
diagonal_vector = np.sum(Adjacency_Matrix,axis=1)
Degree_Matrix = np.diag(diagonal_vector)
np.savetxt("matrices/Degree_Matrix.csv", Degree_Matrix)
print('[info] Degree Matrix Calculated')
plt.figure()
plt.imshow(Degree_Matrix,extent=[0,64,0, 64],cmap='viridis')
#%% Laplacian Matrix
print('[info] Calculating Laplacian Matrix')
Laplacian_Matrix = Degree_Matrix - Adjacency_Matrix;
np.savetxt("matrices/Laplacian_Matrix.csv", Laplacian_Matrix)
print('[info] Laplacian Matrix Calculated ')
plt.figure()
plt.imshow(Laplacian_Matrix,extent=[0,64,0, 64],cmap='viridis')