mackey_glass / generator.py
jyik's picture
Upload 16 files
c2aae5f
# 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)