-
Notifications
You must be signed in to change notification settings - Fork 2
/
combination_performance.py
202 lines (178 loc) · 10.7 KB
/
combination_performance.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# Initialize connection with rest of lib
import logging
import rdkit
from utils import *
from DL_ClassifierModel import *
import os
from pathlib import Path
import torch
log_file = 'results_combination_of_models.log'
log_format = '%(asctime)s : %(levelname)s : %(message)s'
fhandler = logging.FileHandler(filename=log_file, mode='a')
logging.basicConfig(format=log_format, filename = log_file, level=logging.DEBUG)
logger = logging.getLogger()
logger.addHandler(fhandler)
def log(setting, training_data, valid_data, test_data):
logger.debug(f'Conditions --> pEmbeddings: {setting["pEmbeddings"]}, kmers: {setting["kmers"]}, pSeq: {setting["pSeq"]}, FP: {setting["FP"]}, dSeq: {setting["dSeq"]}, ST_fingerprint: {setting["ST_fingerprint"]}\n')
logger.info(f'Training --> AUC = {training_data[1]}, ACC = {training_data[0]}\n')
logger.info(f'Validation --> AUC = {valid_data[1]}, ACC = {valid_data[0]}\n')
logger.info(f'Test --> AUC = {test_data[1]}, ACC = {test_data[0]}\n')
logger.info('\n')
#Training data binding DB
data = "bindingdb"
save_path = "TEST_bindingdb"
data_path = Path(os.path.join("data", data))
assert data_path.exists()
#Iterate on the separate possible methods
for method in ['DTI_Bridge', 'ST_Bridge', 'p_Embedding_Bridge', 'p_Emb_ST_Bridge']:
#Get the bindingDB class
data_class = LoadBindingDB(dataPath=data_path, model_name = method)
#Set up the test set
test = np.array(data_class.eSeqData['test'])
if method == 'DTI_Bridge':
model_name = 'DTI_Bridge'
for (kmers, pSeq) in [(True, True), (True, False), (False, True), (False, False)]:
for (FP, dSeq) in [(True, True), (True, False), (False, True), (False, False)]:
if (kmers, pSeq, FP, dSeq) == (False, False, False, False):
break
pEmbeddings = False
ST_fingerprint = False
train_stats = []
valid_stats = []
test_stats = []
useFeatures={"pEmbeddings": pEmbeddings, "kmers": kmers, "pSeq": pSeq,
"FP": FP, "dSeq": dSeq, "ST_fingerprint": ST_fingerprint}
print(f'Training model with pEmbeddings: {useFeatures["pEmbeddings"]}, kmers: {useFeatures["kmers"]}, pSeq: {useFeatures["pSeq"]}, FP: {useFeatures["FP"]}, dSeq: {useFeatures["dSeq"]}, ST_fingerprint: {useFeatures["ST_fingerprint"]}\n')
for iter in range(3):
model = DTI_Bridge(outSize=128,
cHiddenSizeList=[1024],
fHiddenSizeList=[1024, 256],
fSize=1024, cSize=data_class.pContFeat.shape[1],
gcnHiddenSizeList=[128, 128], fcHiddenSizeList=[128], nodeNum=64,
hdnDropout=0.5, fcDropout=0.5, device=torch.device('cuda'),
useFeatures=useFeatures)
model.train(data_class, trainSize=512, batchSize=512, epoch=128,
stopRounds=-1, earlyStop=30,
savePath=save_path, metrics="AUC", report=["ACC", "AUC", "LOSS"],
preheat=0)
train_stats.append(model.final_res['training'])
valid_stats.append(model.final_res['valid'])
#Get test results
model.to_eval_mode()
Ypre, Y, seenbool = model.calculate_y_with_seenbool(data_class.one_epoch_batch_data_stream(batchSize=128, type='test', device=torch.device('cuda')))
metrictor = Metrictor()
metrictor.set_data(Ypre, Y)
test_stats.append([metrictor.ACC(), metrictor.AUC()])
train_mean = np.mean(np.array(train_stats), axis = 0)
valid_mean = np.mean(np.array(valid_stats), axis = 0)
test_mean = np.mean(np.array(test_stats), axis = 0)
log(useFeatures, train_mean, valid_mean, test_mean)
elif method == 'ST_Bridge':
for (kmers, pSeq) in [(True, True), (True, False), (False, True), (False, False)]:
pEmbeddings = False
ST_fingerprint = True
dSeq = False
FP = False
train_stats = []
valid_stats = []
test_stats = []
useFeatures={"pEmbeddings": pEmbeddings, "kmers": kmers, "pSeq": pSeq,
"FP": FP, "dSeq": dSeq, "ST_fingerprint": ST_fingerprint}
print(f'Training model with pEmbeddings: {useFeatures["pEmbeddings"]}, kmers: {useFeatures["kmers"]}, pSeq: {useFeatures["pSeq"]}, FP: {useFeatures["FP"]}, dSeq: {useFeatures["dSeq"]}, ST_fingerprint: {useFeatures["ST_fingerprint"]}\n')
for iter in range(3):
model = ST_Bridge(outSize=128,
cHiddenSizeList=[1024],
fHiddenSizeList=[1024, 256],
fSize=1024, cSize=data_class.pContFeat.shape[1],
gcnHiddenSizeList=[128, 128], fcHiddenSizeList=[128], nodeNum=64,
hdnDropout=0.5, fcDropout=0.5, device=torch.device('cuda'),
useFeatures=useFeatures)
model.train(data_class, trainSize=512, batchSize=512, epoch=128,
stopRounds=-1, earlyStop=30,
savePath=save_path, metrics="AUC", report=["ACC", "AUC", "LOSS"],
preheat=0)
train_stats.append(model.final_res['training'])
valid_stats.append(model.final_res['valid'])
#Get test results
model.to_eval_mode()
Ypre, Y, seenbool = model.calculate_y_with_seenbool(data_class.one_epoch_batch_data_stream(batchSize=128, type='test', device=torch.device('cuda')))
metrictor = Metrictor()
metrictor.set_data(Ypre, Y)
test_stats.append([metrictor.ACC(), metrictor.AUC()])
train_mean = np.mean(np.array(train_stats), axis = 0)
valid_mean = np.mean(np.array(valid_stats), axis = 0)
test_mean = np.mean(np.array(test_stats), axis = 0)
log(useFeatures, train_mean, valid_mean, test_mean)
elif method == 'p_Embedding_Bridge':
for (FP, dSeq) in [(True, True), (True, False), (False, True), (False, False)]:
pEmbeddings = True
ST_fingerprint = False
kmers = False
pSeq = False
train_stats = []
valid_stats = []
test_stats = []
useFeatures={"pEmbeddings": pEmbeddings, "kmers": kmers, "pSeq": pSeq,
"FP": FP, "dSeq": dSeq, "ST_fingerprint": ST_fingerprint}
print(f'Training model with pEmbeddings: {useFeatures["pEmbeddings"]}, kmers: {useFeatures["kmers"]}, pSeq: {useFeatures["pSeq"]}, FP: {useFeatures["FP"]}, dSeq: {useFeatures["dSeq"]}, ST_fingerprint: {useFeatures["ST_fingerprint"]}\n')
for iter in range(3):
model = p_Embedding_Bridge(outSize=128,
cHiddenSizeList=[1024],
fHiddenSizeList=[1024, 256],
fSize=1024, cSize=data_class.pContFeat.shape[1],
gcnHiddenSizeList=[128, 128], fcHiddenSizeList=[128], nodeNum=64,
hdnDropout=0.5, fcDropout=0.5, device=torch.device('cuda'),
useFeatures=useFeatures)
model.train(data_class, trainSize=512, batchSize=512, epoch=128,
stopRounds=-1, earlyStop=30,
savePath=save_path, metrics="AUC", report=["ACC", "AUC", "LOSS"],
preheat=0)
train_stats.append(model.final_res['training'])
valid_stats.append(model.final_res['valid'])
#Get test results
model.to_eval_mode()
Ypre, Y, seenbool = model.calculate_y_with_seenbool(data_class.one_epoch_batch_data_stream(batchSize=128, type='test', device=torch.device('cuda')))
metrictor = Metrictor()
metrictor.set_data(Ypre, Y)
test_stats.append([metrictor.ACC(), metrictor.AUC()])
train_mean = np.mean(np.array(train_stats), axis = 0)
valid_mean = np.mean(np.array(valid_stats), axis = 0)
test_mean = np.mean(np.array(test_stats), axis = 0)
log(useFeatures, train_mean, valid_mean, test_mean)
elif method == 'p_Emb_ST_Bridge':
pEmbeddings = True
ST_fingerprint = True
FP = False
dSeq = False
kmers = False
pSeq = False
train_stats = []
valid_stats = []
test_stats = []
useFeatures={"pEmbeddings": pEmbeddings, "kmers": kmers, "pSeq": pSeq,
"FP": FP, "dSeq": dSeq, "ST_fingerprint": ST_fingerprint}
print(f'Training model with pEmbeddings: {useFeatures["pEmbeddings"]}, kmers: {useFeatures["kmers"]}, pSeq: {useFeatures["pSeq"]}, FP: {useFeatures["FP"]}, dSeq: {useFeatures["dSeq"]}, ST_fingerprint: {useFeatures["ST_fingerprint"]}\n')
for iter in range(3):
model = p_Embedding_Bridge(outSize=128,
cHiddenSizeList=[1024],
fHiddenSizeList=[1024, 256],
fSize=1024, cSize=data_class.pContFeat.shape[1],
gcnHiddenSizeList=[128, 128], fcHiddenSizeList=[128], nodeNum=64,
hdnDropout=0.5, fcDropout=0.5, device=torch.device('cuda'),
useFeatures=useFeatures)
model.train(data_class, trainSize=512, batchSize=512, epoch=128,
stopRounds=-1, earlyStop=30,
savePath=save_path, metrics="AUC", report=["ACC", "AUC", "LOSS"],
preheat=0)
train_stats.extend([model.final_res['training']['ACC'], model.final_res['training']['AUC']])
valid_stats.extend([model.final_res['valid']['ACC'], model.final_res['valied']['AUC']])
#Get test results
model.to_eval_mode()
Ypre, Y, seenbool = model.calculate_y_with_seenbool(data_class.one_epoch_batch_data_stream(batchSize=128, type='test', device=torch.device('cuda')))
metrictor = Metrictor()
metrictor.set_data(Ypre, Y)
test_stats.append([metrictor.ACC(), metrictor.AUC()])
train_mean = np.mean(np.array(train_stats), axis = 0)
valid_mean = np.mean(np.array(valid_stats), axis = 0)
test_mean = np.mean(np.array(test_stats), axis = 0)
log(useFeatures, train_mean, valid_mean, test_mean)