-
Notifications
You must be signed in to change notification settings - Fork 2
/
qos_inversek2j.py
64 lines (44 loc) · 1.26 KB
/
qos_inversek2j.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
#!/usr/bin/python
import sys
import math
class bcolors:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
def printUsage():
print "Usage: python qos.py <original file> <nn file>"
exit(1)
pass;
if(len(sys.argv) != 3):
printUsage()
origFilename = sys.argv[1]
nnFilename = sys.argv[2]
origLines = open(origFilename).readlines()
nnLines = open(nnFilename).readlines()
e = 0.0
absError = 0.0
for i in range(len(origLines)):
origLine = origLines[i].rstrip()
nnLine = nnLines[i].rstrip()
origItem1 = float(origLine.split("\t")[0])
origItem2 = float(origLine.split("\t")[1])
nnItem1 = float(nnLine.split("\t")[0])
nnItem2 = float(nnLine.split("\t")[1])
diff1 = origItem1 - nnItem1
diff2 = origItem2 - nnItem2
nominator = math.sqrt(diff1*diff1 + diff2*diff2)
denominator = math.sqrt(origItem1*origItem1 + origItem2*origItem2)
if(denominator == 0):
e = math.sqrt(diff1*diff1 + diff2*diff2)
elif(math.isnan(nominator) or (math.isnan(denominator))):
e = 1.0
else:
e = nominator / denominator
absError += e
pass;
print bcolors.FAIL + "*** Error: %1.8f" % (absError/len(origLines)) + bcolors.ENDC