-
Notifications
You must be signed in to change notification settings - Fork 0
/
4_compute_PCA.py
35 lines (32 loc) · 1.53 KB
/
4_compute_PCA.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
#THIS CODE IS USED TO COMPUTE THE PCA ON SOAP
import numpy as np
from sklearn.decomposition import PCA
import matplotlib.pyplot as plt
import pandas as pd
#SOAP cutoff
SOAP_CUTOFF = 10
#number of PCA components
pc_components = 3
print(f"{'-'*10}\nPCA SOAP\n{'-'*10}")
soap_av = np.load(f"arrays/fullvect_SOAP_{SOAP_CUTOFF}.npy")
print(soap_av.shape)
SOAP=soap_av.reshape(np.shape(soap_av)[0]*np.shape(soap_av)[1],np.shape(soap_av)[2])
pca = PCA(n_components=pc_components)
pc_soap = pca.fit_transform(SOAP)
np.save(f"arrays/SOAP_{SOAP_CUTOFF}_PC1.npy",np.transpose(pc_soap[:,0].reshape(500,2048)))
#To compute other components....
#np.save(f"arrays/SOAP_{SOAP_CUTOFF}_PC2.npy",np.transpose(pc_soap[:,1].reshape(500,2048)))
#np.save(f"arrays/SOAP_{SOAP_CUTOFF}_PC3.npy",np.transpose(pc_soap[:,2].reshape(500,2048)))
print(f"{'-'*10}\nPCA SP SOAP\n{'-'*10}")
sp_cutoff = [10]
for cutoff in sp_cutoff:
soap_av = np.load(f"arrays/sp_{cutoff}_SOAP_{int(SOAP_CUTOFF)}.npy")
soap_av = soap_av.transpose(2,1,0)
print(soap_av.shape)
SOAP=soap_av.reshape(np.shape(soap_av)[0]*np.shape(soap_av)[1],np.shape(soap_av)[2])
pca = PCA(n_components=pc_components)
pc_soap = pca.fit_transform(SOAP)
#To save other components....
np.save(f"arrays/sp_{cutoff}_SOAP_{SOAP_CUTOFF}_PC1.npy",np.transpose(pc_soap[:,0].reshape(500,2048)))
#np.save(f"arrays/sp_{cutoff}_SOAP_{SOAP_CUTOFF}_PC2.npy",np.transpose(pc_soap[:,1].reshape(500,2048)))
#np.save(f"arrays/sp_{cutoff}_SOAP_{SOAP_CUTOFF}_PC3.npy",np.transpose(pc_soap[:,2].reshape(500,2048)))