-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathHypeVolume.py
57 lines (43 loc) · 1.08 KB
/
HypeVolume.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
import os
import numpy as np
def calhy(x, y):
l = len(x)
res = 0.0
for i in range(l):
if i == 0:
res = res + x[1] * (1 - y[0])
elif i == l - 1:
res = res + (1 - x[i]) * (1 - y[i])
else:
res = res + (x[i + 1] - x[i]) * (1 - y[i]);
return res
def get_hv(filename):
m1 = np.loadtxt(filename)
x1, y1 = get_can(m1)
return calhy(x1, y1)
def get_can(m1):
index = np.argsort(m1, axis=0)
x1 = []
y1 = []
r = len(index)
for i in range(r):
a = index[i][0]
x1.append(m1[a][0])
y1.append(m1[a][1])
return x1, y1
def get_directory(path):
fp = []
if os.path.isdir(path):
for root, dirs, files in os.walk(path):
for f in files:
cur = root + "/" + f
fp.append(cur)
else:
fp.append(path)
return fp
def get_directory_hv(path):
fp = get_directory(path)
for path in fp:
print(path, get_hv(path))
if __name__ == '__main__':
get_directory_hv('/home/kaiqiang/file/创新实验/result')