-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils2.py
81 lines (62 loc) · 1.93 KB
/
utils2.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
from numpy import true_divide
from utils import *
def remove_anomalies(X,y, anom=1):
indices = np.where(y==anom)
intervals = []
left = None
right = None
for i in list(indices[0]):
if left is None:
left = i
right = i
elif right + 1 == i:
right = i
else:
intervals.append((left, right))
left = None
right = None
if left is not None and intervals[-1] != (left, right):
intervals.append((left, right))
return intervals
def load_data(name,len_seq,stride, removeAnom = False):
Xs = []
ys = []
## Use glob module and wildcard to build a list of files to load from data directory
path = "data/{}_data_*".format(name)
data = glob.glob(path)
for file in data:
X, y = load_dataset(file)
if removeAnom:
ranges = remove_anomalies(X,y)
print(ranges)
last = 0
for interval in ranges:
Xi, yi = slide(X[last:interval[0]-1], y[last:interval[0]-1], len_seq, stride, save=False)
last = interval[1]+1
Xs.append(Xi)
ys.append(yi)
Xi, yi = slide(X[last:], y[last:], len_seq, stride, save=False)
Xs.append(Xi)
ys.append(yi)
else:
X, y = slide(X, y, len_seq, stride, save=False)
Xs.append(X)
ys.append(y)
return Xs, ys
# X,y = load_data('train',24,1, removeAnom=True)
# X = np.array(X)
# y = np.array(y)
# for i in range(len(X)):
# print(y[i].shape)
# print(len(X), len(y))
def load_data_plain(name):
Xs = []
ys = []
## Use glob module and wildcard to build a list of files to load from data directory
path = "data/{}_data_*".format(name)
data = glob.glob(path)
for file in data:
X, y = load_dataset(file)
Xs.append(X)
ys.append(y)
return Xs, ys