-
Notifications
You must be signed in to change notification settings - Fork 3
/
Score_cluster.py
65 lines (39 loc) · 1.5 KB
/
Score_cluster.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
import numpy as np
# import pandas as pd
def evaluate(y_test, y_pred, particle = -1):
eff_total = 0.
fake_total = 0.
# evaluate hit efficiency
listtoscore = [particle]
if(particle < 0):
listtoscore = np.unique(y_test)
dummyarray = np.full(shape=len(y_test) + 1,fill_value=-1)
for particle in listtoscore:
eff = 0.
fake = 0.
# print "particle : ", particle
true_hits = y_test[y_test[:] == particle]
found_hits = y_pred[y_test[:] == particle]
nsubcluster=len(np.unique(found_hits[found_hits[:] >= 0]))
# if(particle >= 0):
# print "true hits : ", true_hits
# print "found hits : ", found_hits
# print "found clusters : ", nsubcluster
if(nsubcluster > 0):
# fix for degeneracy!
b=np.bincount(found_hits[found_hits[:] >= 0])
a=np.argmax(b)
maxcluster = a
eff = len(found_hits[found_hits[:] == maxcluster])/len(true_hits)
# evaluate noise
overlap = (y_pred[:] == maxcluster)
others = (y_test[:] != particle)
mask = overlap & others
noise_hits = y_pred[mask]
fake = len(noise_hits) / len(true_hits)
# print "efficiency : ", eff
# print "fake : ", fake
eff_total += eff
fake_total += fake
# remove combinatorials
return eff_total, fake_total