File size: 1,800 Bytes
c2aae5f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# The included pre-generated Mackey-Glass time series were generated on 
# an M1 machine using the following script. Note that due to the reliance
# of jitcdde on lower-level solvers, this script may not produce the same
# results on different machines. (Tested on various x64 and M1 architectures,
# with consistent library versions.)
# Thus it is recommended to use the pre-generated time series.

# generates mackey-glass time series using jitcdde
from jitcdde import jitcdde, y, t
import numpy as np
import csv

def generator(tau, lyap_time, initial_condition):
	# MG parameters
	beta = 0.2
	gamma = 0.1
	n = 10

	# total time to integrate, 50 lyapunov times
	total_time = lyap_time*50
	
	# number of steps to integrate: 50 lyap_times, 75 steps each, plus one to eval
	steps = 50 * 75 + 1

	f = [beta*y(0,t-tau)/(1+y(0,t-tau)**n)-gamma*y(0)]
	DDE = jitcdde(f)

	# shrink integration parameters
	DDE.set_integration_parameters(atol=1e-17, rtol=1e-17, min_step=1e-17)

	DDE.constant_past([initial_condition])
	DDE.step_on_discontinuities()

	# generate
	data = []
	for time in np.linspace(DDE.t, DDE.t+total_time, steps):
		data.append(DDE.integrate(time)[0])

	return np.array(data)

if __name__ == '__main__':
	taus = []
	lyap_times = []
	initial_conditions = []

	# read csv
	with open('mackey_glass_parameters.csv', newline='') as csvfile:
		reader = csv.reader(csvfile, delimiter=',')
		for row in reader:
			# skip header
			if row[0] == 'tau':
				continue
			taus.append(int(row[0]))
			lyap_times.append(int(row[1]))
			initial_conditions.append(float(row[2]))
			
	# generate
	for tau, lyap_time, initial_condition in zip(taus, lyap_times, initial_conditions):
		data = generator(tau, lyap_time, initial_condition)
		assert(len(data) == 50*75+1)
		np.save('mg_{}.npy'.format(tau), data)