forked from oxpig/AEV-PLIG
-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.py
95 lines (76 loc) · 1.96 KB
/
helpers.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
import torch
import numpy as np
from math import sqrt
from scipy import stats
from model_defs import GATv2Net
model_dict = {"GATv2Net": GATv2Net}
def get_num_parameters(model):
"""
counts the number of parameters
"""
return sum(p.numel() for p in model.parameters() if p.requires_grad)
def collate_fn(batch):
"""
function needed for data loaders
"""
feature_list, protein_seq_list, label_list = [], [], []
for _features, _protein_seq, _label in batch:
#print(type(_features), type(_protein_seq), type(_label))
feature_list.append(_features)
protein_seq_list.append(_protein_seq)
label_list.append(_label)
return torch.Tensor(feature_list), torch.Tensor(protein_seq_list), torch.Tensor(label_list)
def rmse(y,f):
"""
taken from https://github.com/thinng/GraphDTA
computes the RMSE
"""
rmse = sqrt(((y - f)**2).mean(axis=0))
return rmse
def mse(y,f):
"""
taken from https://github.com/thinng/GraphDTA
computes the MSE
"""
mse = ((y - f)**2).mean(axis=0)
return mse
def pearson(y,f):
"""
taken from https://github.com/thinng/GraphDTA
computes the pearson correlation coefficient
"""
rp = np.corrcoef(y, f)[0,1]
return rp
def spearman(y,f):
"""
taken from https://github.com/thinng/GraphDTA
computes the spearman correlation coefficient
"""
rs = stats.spearmanr(y, f)[0]
return rs
def ci(y,f):
"""
taken from https://github.com/thinng/GraphDTA
computes the concordance index
"""
ind = np.argsort(y)
y = y[ind]
f = f[ind]
i = len(y)-1
j = i-1
z = 0.0
S = 0.0
while i > 0:
while j >= 0:
if y[i] > y[j]:
z = z+1
u = f[i] - f[j]
if u > 0:
S = S + 1
elif u == 0:
S = S + 0.5
j = j - 1
i = i - 1
j = i-1
ci = S/z
return ci