-
Notifications
You must be signed in to change notification settings - Fork 0
/
data.py
54 lines (46 loc) · 1.59 KB
/
data.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
# =============================================================================
# Import required libraries
# =============================================================================
import math
import matplotlib.pyplot as plt
import csv
# =============================================================================
# Define hyperparameters
# =============================================================================
t_min = 18
t_max = 1100
beta = 0.2
gamma = 0.1
tao = 17
n = 10
# =============================================================================
# Mackey-Glass time series
# =============================================================================
x = []
for i in range(1, t_min) :
x.append(0.0)
x.append(1.2)
for t in range(t_min, t_max):
h = x[t-1] + (beta * x[t-tao-1] / (1 + math.pow(x[t-tao-1], n))) - (gamma * x[t-1])
h = float("{:0.4f}".format(h))
x.append(h)
# =============================================================================
# Plot Data
# =============================================================================
plt.plot(range(t_min, t_max+1), x[t_min-1:t_max])
# =============================================================================
# Prepare Data
# =============================================================================
data = []
x = x[t_min-1:t_max]
for t in range(3, len(x)):
d = []
d.append(x[t-3])
d.append(x[t-2])
d.append(x[t-1])
d.append(x[t])
data.append(d)
with open('data.csv', 'w', encoding='UTF8', newline='') as f:
writer = csv.writer(f)
# write the data
writer.writerows(data)