-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrefs_classifier.py
More file actions
executable file
·109 lines (91 loc) · 2.4 KB
/
refs_classifier.py
File metadata and controls
executable file
·109 lines (91 loc) · 2.4 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
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
101
102
103
104
105
106
107
108
109
#!/usr/bin/python
import sys
import getopt
def cluster3(filename):
# Low, Mid, High
# (1,2], (2,4], (4,infi)
count = [0, 0, 0]
file_object = open(filename, "r")
try:
for line in file_object:
ref = float(line)
if ref > 4:
count[2] += 1
elif ref > 2:
count[1] += 1
elif ref > 1:
count[0] += 1
finally:
file_object.close()
return count
def cluster5(filename):
# 1, 2, [3,4], [5,6,7], [8,infi)
count = [0, 0, 0, 0, 0]
max = 1
file_object = open(filename, "r")
try:
for line in file_object:
ref = float(line)
if ref > 7:
count[4] += 1
elif ref > 4:
count[3] += 1
elif ref > 2:
count[2] += 1
elif ref == 2:
count[1] += 1
elif ref == 1:
count[0] += 1
if ref > max:
max = ref
print max
finally:
file_object.close()
return count
def cluster10(filename):
# (1,2], (2,3], (3,4], (4,5], (5,6], (6,7], (7,8], (8,9], (9,10], (10, infi)
count = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
file_object = open(filename, "r")
try:
for line in file_object:
ref = float(line)
if ref > 10:
count[10] += 1
elif ref > 9:
count[9] += 1
elif ref > 8:
count[8] += 1
elif ref > 7:
count[7] += 1
elif ref > 6:
count[6] += 1
elif ref > 5:
count[5] += 1
elif ref > 4:
count[4] += 1
elif ref > 3:
count[3] += 1
elif ref > 2:
count[2] += 1
elif ref > 1:
count[1] += 1
elif ref > 0:
count[0] += 1
finally:
file_object.close()
return count
if __name__ == "__main__":
(opts, args) = getopt.gnu_getopt(sys.argv[1:], "c:", ["cluster"])
c = 5
for o, a in opts:
if o in ["-c"]:
c = int(a)
if c == 10:
count = cluster10(args[0])
elif c == 5:
count = cluster5(args[0])
else:
count = cluster3(args[0])
s = sum(count)
for i in range(len(count)):
print 1.0 * count[i]/s