|
a |
|
b/python-scripts/runSimulationsSVAE2.py |
|
|
1 |
from keras.layers import Input, Dense |
|
|
2 |
from keras.models import Model |
|
|
3 |
import numpy as np |
|
|
4 |
import pandas as pd |
|
|
5 |
import matplotlib.pyplot as plt |
|
|
6 |
from sklearn.cluster import KMeans |
|
|
7 |
from sklearn.cluster import k_means |
|
|
8 |
from sklearn.metrics import silhouette_score, davies_bouldin_score |
|
|
9 |
from sklearn.preprocessing import normalize |
|
|
10 |
import time |
|
|
11 |
from sklearn import metrics |
|
|
12 |
from myUtils import * |
|
|
13 |
#from AEclass import AE |
|
|
14 |
from SVAEclass import VAE |
|
|
15 |
import os |
|
|
16 |
|
|
|
17 |
if __name__ == '__main__': |
|
|
18 |
datatypes=["equal","heterogeneous"] |
|
|
19 |
typenums=[5,10,15] |
|
|
20 |
for datatype in datatypes: |
|
|
21 |
for typenum in typenums: |
|
|
22 |
datapath='data/simulations/{}/{}'.format(datatype, typenum) |
|
|
23 |
resultpath='result/simulations/{}/{}'.format(datatype, typenum) |
|
|
24 |
groundtruth = np.loadtxt('{}/c.txt'.format(datapath)) |
|
|
25 |
groundtruth = list(np.int_(groundtruth)) |
|
|
26 |
|
|
|
27 |
omics1 = np.loadtxt('{}/o1.txt'.format(datapath)) |
|
|
28 |
omics1 = np.transpose(omics1) |
|
|
29 |
omics1 = normalize(omics1, axis=0, norm='max') |
|
|
30 |
|
|
|
31 |
omics2 = np.loadtxt('{}/o2.txt'.format(datapath)) |
|
|
32 |
omics2 = np.transpose(omics2) |
|
|
33 |
omics2 = normalize(omics2, axis=0, norm='max') |
|
|
34 |
|
|
|
35 |
omics3 = np.loadtxt('{}/o3.txt'.format(datapath)) |
|
|
36 |
omics3 = np.transpose(omics3) |
|
|
37 |
omics3 = normalize(omics3, axis=0, norm='max') |
|
|
38 |
|
|
|
39 |
omics = np.concatenate((omics1, omics2, omics3), axis=1) |
|
|
40 |
|
|
|
41 |
data = omics |
|
|
42 |
#input_dim = data.shape[1] |
|
|
43 |
|
|
|
44 |
encoding1_dim1 = 100 |
|
|
45 |
encoding2_dim1 = 50 |
|
|
46 |
if typenum==15: |
|
|
47 |
middle_dim1 = 5 |
|
|
48 |
elif typenum==10: |
|
|
49 |
middle_dim1 = 4 |
|
|
50 |
elif typenum==5: |
|
|
51 |
middle_dim1 = 3 |
|
|
52 |
dims1 = [encoding1_dim1, encoding2_dim1, middle_dim1] |
|
|
53 |
ae1 = VAE(omics1, dims1) |
|
|
54 |
ae1.train() |
|
|
55 |
ae1.autoencoder.summary() |
|
|
56 |
encoded_factor1 = ae1.predict(omics1) |
|
|
57 |
|
|
|
58 |
encoding1_dim2 = 80 |
|
|
59 |
encoding2_dim2 = 50 |
|
|
60 |
if typenum==15: |
|
|
61 |
middle_dim2 = 5 |
|
|
62 |
elif typenum==10: |
|
|
63 |
middle_dim2 = 3 |
|
|
64 |
elif typenum==5: |
|
|
65 |
middle_dim2 = 1 |
|
|
66 |
|
|
|
67 |
dims2 = [encoding1_dim2, encoding2_dim2, middle_dim2] |
|
|
68 |
ae2 = VAE(omics2, dims2) |
|
|
69 |
ae2.train() |
|
|
70 |
ae2.autoencoder.summary() |
|
|
71 |
encoded_factor2 = ae2.predict(omics2) |
|
|
72 |
|
|
|
73 |
encoding1_dim3 = 80 |
|
|
74 |
encoding2_dim3 = 50 |
|
|
75 |
if typenum==15: |
|
|
76 |
middle_dim3 = 5 |
|
|
77 |
elif typenum==10: |
|
|
78 |
middle_dim3 = 3 |
|
|
79 |
elif typenum==5: |
|
|
80 |
middle_dim3 = 1 |
|
|
81 |
|
|
|
82 |
dims3 = [encoding1_dim3, encoding2_dim3, middle_dim3] |
|
|
83 |
ae3 = VAE(omics3, dims3) |
|
|
84 |
ae3.autoencoder.summary() |
|
|
85 |
ae3.train() |
|
|
86 |
encoded_factor3 = ae3.predict(omics3) |
|
|
87 |
|
|
|
88 |
encoded_factors = np.concatenate((encoded_factor1, encoded_factor2, encoded_factor3), axis=1) |
|
|
89 |
|
|
|
90 |
# if not os.path.exists("{}/AE_FAETC_EM.txt".format(resultpath)): |
|
|
91 |
# os.mknod("{}/AE_FAETC_EM.txt".format(resultpath)) |
|
|
92 |
np.savetxt("{resultpath}/SVAE_FAETC_EM_{typenum}.txt".format(resultpath=resultpath,typenum=typenum), encoded_factors) |
|
|
93 |
|
|
|
94 |
|
|
|
95 |
|
|
|
96 |
|
|
|
97 |
|
|
|
98 |
|
|
|
99 |
|
|
|
100 |
|