-
Notifications
You must be signed in to change notification settings - Fork 0
/
getResultsvngp.py
executable file
·104 lines (75 loc) · 2.49 KB
/
getResultsvngp.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
import os
import fnmatch
numAttacks=17 # 5 attacks and no attack -w 0
#TPR
TPR = [None] * numAttacks
for i in range(len(TPR)):
TPR[i] = [None] * 3
#FPR
FPR = [None] * numAttacks
for i in range(len(FPR)):
FPR[i] = [None] * 3
#ACC
ACC = [None] * numAttacks
for i in range(len(ACC)):
ACC[i] = [None] * 3
#F2
F2 = [None] * numAttacks
for i in range(len(F2)):
F2[i] = [None] * 3
desc = os.path.dirname(os.path.realpath(__file__)).split(os.sep)[-2]
def __writeFile(resultsList, type):
resultType = type
dir = os.path.join('.', desc)
if not os.path.exists(dir):
os.mkdir(dir)
f = open( os.path.join(dir, resultType), 'w' )
f.write("#"+desc+"\n")
for entry in resultsList:
f.write( str(entry[0])+'\t'+str(entry[1])+'\t'+str(entry[2])+"\n" )
f.close()
def extract(exp,ttype):
for (path, dirs, files) in os.walk('.'):
for myfile in files:
if fnmatch.fnmatch(myfile, '*binary'):
print myfile
fileLines = [line.strip() for line in open(os.path.join('.', myfile))]
for fileLine in fileLines:
if not fileLine.startswith("tpr"):
lineResults = fileLine.split(",") # [tpr , fpr , Acc , F2 , tp , tn , fp , fn , File ID]
C = int(myfile.split(".C")[1].split(".")[0])
w = int(myfile.split(".w")[1].split(".")[0])
exptype = int(myfile.split(".o")[1].split(".")[0])
train = int(myfile.split(".t")[1].split(".")[0])
if str(exptype) == str(exp) and str(ttype) == str(train):
print w
print len(TPR)
TPR[w][0] = w
FPR[w][0] = w
ACC[w][0] = w
F2[w][0] = w
if C == 3:
TPR[w][1] = '%.2f' % (float(lineResults[0]) * 100)
FPR[w][1] = '%.2f' % (float(lineResults[1]) * 100)
ACC[w][1] = '%.2f' % (float(lineResults[2]) * 100)
F2[w][1] = '%.2f' % (float(lineResults[3]) * 100)
elif C == 15:
TPR[w][2] = '%.2f' % (float(lineResults[0]) * 100)
FPR[w][2] = '%.2f' % (float(lineResults[1]) * 100)
ACC[w][2] = '%.2f' % (float(lineResults[2]) * 100)
F2[w][2] = '%.2f' % (float(lineResults[3]) * 100)
else:
print "Code shouldn't come to here!"
print 'tpr'
for entry in TPR:
print entry
print '\n'
print 'fpr'
for entry in FPR:
print entry
print '\n'
__writeFile(TPR, 'tpr'+str(exp)+"_"+str(ttype))
__writeFile(FPR, 'fpr'+str(exp)+"_"+str(ttype))
__writeFile(ACC, 'acc'+str(exp)+"_"+str(ttype))
__writeFile(F2, 'f2'+str(exp)+"_"+str(ttype))
extract(1,100)