forked from yinhanyan/DS-FD
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_year.py
41 lines (34 loc) · 928 Bytes
/
generate_year.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
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
deltaN = 50000
df = pd.read_csv("dataset/YearPredictionMSD.txt", delim_whitespace=False)
A = df.values.astype(np.float64)
# A = A[-51630:, 1:]
A = A.astype(np.float64)
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] >= deltaN:
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(f"dataset/year_timestamp,mu={mu},all.mat", mdic)