forked from cknd/pyESN
/
mackey.py
26 lines (21 loc) · 890 Bytes
/
mackey.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
import numpy as np
from pyESN import ESN
from matplotlib import pyplot as plt
data = np.load('mackey_glass_t17.npy') # http://minds.jacobs-university.de/mantas/code
esn = ESN(n_inputs = 1,
n_outputs = 1,
n_reservoir = 500,
spectral_radius = 1.5,
random_state=42)
trainlen = 2000
future = 2000
pred_training = esn.fit(np.ones(trainlen),data[:trainlen])
prediction = esn.predict(np.ones(future))
print("test error: \n"+str(np.sqrt(np.mean((prediction.flatten() - data[trainlen:trainlen+future])**2))))
plt.figure(figsize=(11,1.5))
plt.plot(range(0,trainlen+future),data[0:trainlen+future],'k',label="target system")
plt.plot(range(trainlen,trainlen+future),prediction,'r', label="free running ESN")
lo,hi = plt.ylim()
plt.plot([trainlen,trainlen],[lo+np.spacing(1),hi-np.spacing(1)],'k:')
plt.legend(loc=(0.61,1.1),fontsize='x-small')
plt.show()