-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsim_eval.py
More file actions
executable file
·60 lines (55 loc) · 1.52 KB
/
sim_eval.py
File metadata and controls
executable file
·60 lines (55 loc) · 1.52 KB
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
#!/usr/bin/env python
"""
Author: Tommaso Soru <tsoru@informatik.uni-leipzig.de>
"""
import sys
reload(sys)
sys.setdefaultencoding("utf-8")
def eval_with(theta, filename):
posneg = [[0, 0], [0, 0], [0, 0]]
with open(filename) as f:
for line in f:
line = line[:-1].split('\t')
if line[2] == "MFKC":
continue # skip headers
sims = [float(line[2]), float(line[3]), float(line[4])]
for i in range(len(sims)):
if sims[i] >= theta:
posneg[i][0] += 1.0 # add positive
else:
posneg[i][1] += 1.0 # add negative
return posneg
def evaluation(theta):
tpfn = eval_with(theta, 'p.tsv')
# print tpfn
fptn = eval_with(theta, 'n.tsv')
# print fptn
ev = list()
for i in range(len(tpfn)):
tp, fn = tpfn[i]
fp, tn = fptn[i]
if tp + fp > 0:
pre = tp / (tp + fp)
else:
pre = 0
if tp + fn > 0:
rec = tp / (tp + fn)
else:
rec = 0
if pre + rec > 0:
f1 = 2 * pre * rec / (pre + rec)
else:
f1 = 0.0
ev.append("{}\t{}\t{}\t{}\t{}".format(theta, i, pre, rec, f1))
return ev
def do_cycle(th):
theta = float(th) / 100.0
ev = evaluation(theta)
print('\n'.join(map(str, ev)))
# wide-range evaluation
for th in xrange(50, 105, 5):
do_cycle(th)
print "-----"
# to find the peaks
for th in xrange(88, 101, 1):
do_cycle(th)