-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclassifier.py
55 lines (47 loc) · 1.19 KB
/
classifier.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
from operator import itemgetter
import math
def euclid_dist(a,b):
res=0.0
for i in range(1,49):
res+=(float(a[i])-float(b[i]))*(float(a[i])-float(b[i]))
return math.sqrt(res)
def trueLabel(frame):
frame=int(frame)
for i in posture1:
if frame>= i[0] and frame<= i[1]:
return 1
for i in posture2:
if frame>= i[0] and frame<= i[1]:
return 2
for i in posture3:
if frame>= i[0] and frame<= i[1]:
return 3
f=open('bsplineder.txt','r')
frames=f.readlines()
posture1=[(0,94),(138,182),(222,272),(309,355),(396,439),(461,481),(504,539),(578,622),(660,677)]
posture2=[(95,137),(273,308),(440,460),(540,577)]
posture3=[(183,221),(356,395),(482,503),(623,659)]
a=dict()
for feature in open('features.csv'):
l=feature.split(',')
for i in range(0,len(l)):
l[i]=l[i].rstrip()
a[l[0]]=l
test_label=dict()
c=0
c1=0
for feature in open('features.csv'):
l=feature.split(',')
for i in range(0,len(l)):
l[i]=l[i].rstrip()
dist=[]
for frame in frames:
frame=frame.rstrip()
d=euclid_dist(l,a[frame])
dist.append((frame,d))
dist=sorted(dist,key=itemgetter(1))
test_label[l[0]]=trueLabel(dist[0][0])
if test_label[l[0]]==trueLabel(l[0]):
c1+=1
c+=1
print (c1*100.0)/(c)