Switch to unified view

a b/python-scripts/runSimulationsAE.py
1
from sklearn.preprocessing import normalize
2
3
from myUtils import *
4
from AEclass import AE
5
import os
6
7
if __name__ == '__main__':
8
    datatypes=["equal","heterogeneous"]
9
    typenums=[5,10,15]
10
    for datatype in datatypes:
11
        for typenum in typenums:
12
            datapath='data/simulations/{}/{}'.format(datatype, typenum)
13
            resultpath='result/simulations/{}/{}'.format(datatype, typenum)
14
            groundtruth = np.loadtxt('{}/c.txt'.format(datapath))
15
            groundtruth = list(np.int_(groundtruth))
16
17
            omics1 = np.loadtxt('{}/o1.txt'.format(datapath))
18
            omics1 = np.transpose(omics1)
19
            omics1 = normalize(omics1, axis=0, norm='max')
20
21
            omics2 = np.loadtxt('{}/o2.txt'.format(datapath))
22
            omics2 = np.transpose(omics2)
23
            omics2 = normalize(omics2, axis=0, norm='max')
24
25
            omics3 = np.loadtxt('{}/o3.txt'.format(datapath))
26
            omics3 = np.transpose(omics3)
27
            omics3 = normalize(omics3, axis=0, norm='max')
28
29
            omics = np.concatenate((omics1, omics2, omics3), axis=1)
30
31
            data = omics
32
            input_dim = data.shape[1]
33
            encoding1_dim = 300
34
            encoding2_dim = 100
35
            middle_dim = typenum
36
            dims = [encoding1_dim, encoding2_dim, middle_dim]
37
            ae = AE(data, dims)
38
            #ae.autoencoder.summary()
39
            ae.train()
40
            encoded_factors = ae.predict(data)
41
            if not os.path.exists("{}/AE_FCTAE_EM.txt".format(resultpath)):
42
                os.mknod("{}/AE_FCTAE_EM.txt".format(resultpath))
43
            np.savetxt("{resultpath}/AE_FCTAE_EM_{typenum}.txt".format(resultpath=resultpath,typenum=typenum), encoded_factors)
44
45
            # if not os.path.exists("AE_FCTAE_Kmeans.txt"):
46
            #     os.mknod("AE_FCTAE_Kmeans.txt")
47
            # fo = open("AE_FCTAE_Kmeans.txt", "a")
48
            # clf = KMeans(n_clusters=typenum)
49
            # t0 = time.time()
50
            # clf.fit(encoded_factors)  # 模型训练
51
            # km_batch = time.time() - t0  # 使用kmeans训练数据消耗的时间
52
53
            # print(datatype, typenum)
54
            # print("K-Means算法模型训练消耗时间:%.4fs" % km_batch)
55
56
            # # 效果评估
57
            # score_funcs = [
58
            #     metrics.adjusted_rand_score,  # ARI(调整兰德指数)
59
            #     metrics.v_measure_score,  # 均一性与完整性的加权平均
60
            #     metrics.adjusted_mutual_info_score,  # AMI(调整互信息)
61
            #     metrics.mutual_info_score,  # 互信息
62
            # ]
63
            # centers = clf.cluster_centers_
64
            # #print("centers:")
65
            # #print(centers)
66
            # print("zlyzlyzlyzlyzlyzlyzlyzlyzlyzlyzlyzlyzlyzlyzlyzlyzlyzlyzlyzlyzlyzlyzlyzlyzlyzlyzlyzly")
67
            # labels = clf.labels_
68
            # print("labels:")
69
            # print(labels)
70
            # labels = list(np.int_(labels))
71
            # if not os.path.exists("{}/AE_FCTAE_CL.txt".format(resultpath)):
72
            #     os.mknod("{}/AE_FCTAE_CL.txt".format(resultpath))
73
            # np.savetxt("{}/AE_FCTAE_CL.txt".format(resultpath), labels,fmt='%d')
74
            # print("zlyzlyzlyzlyzlyzlyzlyzlyzlyzlyzlyzlyzlyzlyzlyzlyzlyzlyzlyzlyzlyzlyzlyzlyzlyzlyzlyzly")
75
            # # 2. 迭代对每个评估函数进行评估操作
76
            # for score_func in score_funcs:
77
            #     t0 = time.time()
78
            #     km_scores = score_func(groundtruth, labels)
79
            #     print("K-Means算法:%s评估函数计算结果值:%.5f;计算消耗时间:%0.3fs" % (score_func.__name__, km_scores, time.time() - t0))
80
            # t0 = time.time()
81
            # jaccard_score = jaccard_coefficient(groundtruth, labels)
82
            # print("K-Means算法:%s评估函数计算结果值:%.5f;计算消耗时间:%0.3fs" % (
83
            #     jaccard_coefficient.__name__, jaccard_score, time.time() - t0))
84
            # silhouetteScore = silhouette_score(encoded_factors, labels, metric='euclidean')
85
            # davies_bouldinScore = davies_bouldin_score(encoded_factors, labels)
86
            # print("silhouetteScore:", silhouetteScore)
87
            # print("davies_bouldinScore:", davies_bouldinScore)
88
            # print("zlyzlyzlyzlyzlyzlyzlyzlyzlyzlyzlyzlyzlyzlyzlyzlyzlyzlyzlyzlyzlyzlyzlyzlyzlyzlyzlyzly")
89
90
91
92
93
94