-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentropy.py
More file actions
56 lines (38 loc) · 1.3 KB
/
Copy pathentropy.py
File metadata and controls
56 lines (38 loc) · 1.3 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
import numpy as np
import math
def count_edge(xy,lineO,lineL,res):
lineO = lineO
lineL = lineL
for line in range(np.shape(xy)[0]-1):
lineO.append(np.rad2deg(np.arctan((xy[line][1]-xy[line+1][1])/(xy[line][0]-xy[line+1][0]+1e-10))))
lineL.append(math.dist(xy[line], xy[line+1])*res)
return(lineO,lineL)
def cal_entropy(lineO,lineL):
angle = np.zeros(np.shape(lineO)[0])
for i in range(np.shape(lineO)[0]):
angle[i] = np.round(lineO[i]/10)*10
x,y=zip(*sorted(zip(angle.flatten(),np.array(lineL).flatten())))
weighted = np.zeros(np.unique(angle).size)
i = 0
idx = 0
while i < angle.size-1:
if x[i] == x[i+1]:
weighted[idx] = weighted[idx] + y[i]
i += 1
else:
weighted[idx] = weighted[idx] + y[i]
i += 1
idx += 1
weighted[idx] += y[-1]
angle = np.unique(angle)
if (angle[0] == -90) and (angle[-1] == 90):
print('Merged two angle data')
#weighted.size == 19: # in case 19 directions are recorded
weighted[-1] += weighted[0]
weighted = np.delete(weighted, 0)
angle = np.delete(angle, 0)
################
x = np.deg2rad(angle)
y = weighted
#################
return(x,y)