-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathdrift_function.py
More file actions
71 lines (59 loc) · 1.56 KB
/
drift_function.py
File metadata and controls
71 lines (59 loc) · 1.56 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import numpy as np
def drift_func(t, P, epsilon, df_type, k, T):
match df_type:
case 1:
res = no_df()
case 2:
res = sudden_df(t=t, k=k, T=T)
case 3:
res = re_sudden_df(t=t, P=P)
case 4:
res = re_incremental_df(t=t, P=P)
case 5:
res = re_incremental_noise_df(t=t, P=P, epsilon=epsilon)
case _:
raise Exception("Error: no match drift function type.")
return res
def no_df():
return 0
def sudden_df(t, k=8, T=8):
if t == 0:
return 0
flag = False
ts = 0
np.random.seed(int(k))
big_lamda = np.sort(np.random.choice(np.arange(1, T + 1), size=k, replace=False))
t = int(t)
for i in big_lamda:
if t == i:
flag = True
elif t > i:
ts = i
if flag:
np.random.seed(t)
else:
np.random.seed(ts)
res = np.random.uniform(-1, 1)
np.random.seed(None)
return res
def re_sudden_df(t, P=20):
if t == 0:
return 0
t %= P
t_c = int(0.5 * P)
if t < t_c:
res = -0.5
else:
res = 0.5
return res
def re_incremental_df(t, P=20):
if t % P == 0:
return 0
res = np.cos(2 * np.pi * t / P + np.pi / 2)
return res
def re_incremental_noise_df(t, P=20, epsilon=0.01):
if t % P == 0:
return 0
noise = epsilon * np.random.uniform(-1, 1)
res = (1 - epsilon) * np.cos(2 * np.pi * t / P + np.pi / 2) + noise
return res