-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgenerate_pamap.py
42 lines (35 loc) · 913 Bytes
/
generate_pamap.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
import pandas as pd
from scipy.stats import poisson
import scipy
import numpy as np
from itertools import accumulate
import scipy.io
if __name__ == "__main__":
mu = 0.5
df = pd.read_csv(
f"dataset/PAMAP2_Dataset/Protocol/subject103.dat", delim_whitespace=True
)
A = df.values.astype(np.float64)
A = A[:, 2:]
A[np.isnan(A)] = 1
n, d = A.shape
dt = poisson.rvs(mu, size=n)
t = list(accumulate(dt))
i, j = 0, 0
max_row = 0
total_row = 0
total_count = 0
while j < len(t):
if t[j] - t[i] >= 5000:
rows = j - i
max_row = max(max_row, rows)
total_row += rows
total_count += 1
i += 1
else:
j += 1
avg_row = total_row / total_count
print(max_row, avg_row)
t = np.array(t)
mdic = {"t": t}
scipy.io.savemat("dataset/pamap_timestamp2.mat", mdic)