def test_SimpleESN_transform(): esn =SimpleESN(n_readout = n_readout) echoes = esn.transform(X) assert_true(esn.weights_ is not None) assert_true(esn.input_weights_ is not None) assert_true(esn.readout_idx_ is not None) repeated_echoes = esn.transform(X) assert_array_equal (echoes, repeated_echoes)
def test_SimpleESN_transform(): esn = SimpleESN(n_readout=n_readout) echoes = esn.transform(X) assert_true(esn.weights_ is not None) assert_true(esn.input_weights_ is not None) assert_true(esn.readout_idx_ is not None) repeated_echoes = esn.transform(X) assert_array_equal(echoes, repeated_echoes)
test_length = 2000 X_train = X[:train_length] y_train = X[1:train_length + 1] X_test = X[train_length:train_length + test_length] y_test = X[train_length + 1:train_length + test_length + 1] # Simple training my_esn = SimpleESN(n_readout=1000, n_components=1000, damping=0.3, weight_scaling=1.25) echo_train = my_esn.fit_transform(X_train) regr = Ridge(alpha=0.01) regr.fit(echo_train, y_train) echo_test = my_esn.transform(X_test) y_true, y_pred = y_test, regr.predict(echo_test) err = mean_squared_error(y_true, y_pred) fp = plt.figure(figsize=(12, 4)) trainplot = fp.add_subplot(1, 3, 1) trainplot.plot(X_train[100:600], 'b') trainplot.set_title('Some training signal') echoplot = fp.add_subplot(1, 3, 2) echoplot.plot(echo_train[100:600, :20]) echoplot.set_title('Some reservoir activation') testplot = fp.add_subplot(1, 3, 3) testplot.plot(X_test[-500:], 'b', label='test signal') testplot.plot(y_pred[-500:], 'g', label='prediction') testplot.set_title('Prediction (MSE %0.3f)' % err) testplot.legend(loc='lower right')
echoplot = data_figures.add_subplot(1, 3, 2) # echoplot.plot(echo_train_state[0, :20]) echoplot.plot(echo_train_state[:, :8]) echoplot.set_title('Some Reservoir Activation') testplot = data_figures.add_subplot(1, 3, 3) testplot.plot(train_target[:], 'r', label='Target Signal') testplot.plot(echo_train_pred[:], 'g', label='Prediction') testplot.set_title('Prediction (MSE %0.8f)' % err_train) testplot.legend(loc='upper right') plt.tight_layout(0.5) plt.savefig('MackeyGlass_ESN_Train_Prediction.png') # show the test result echo_test_state = model_esn.transform(test_input) echo_test_target, echo_test_pred = test_target, regr.predict( echo_test_state) err_test = mean_squared_error(echo_test_target, echo_test_pred) data_figures = plt.figure(figsize=(12, 4)) trainplot = data_figures.add_subplot(1, 3, 1) trainplot.plot(test_input[:], 'b') trainplot.set_title('Test Signal') echoplot = data_figures.add_subplot(1, 3, 2) echoplot.plot(echo_test_state[:, :8]) echoplot.set_title('Some reservoir activation') testplot = data_figures.add_subplot(1, 3, 3)
X = atleast_2d(X).T train_length = 2000 test_length = 2000 X_train = X[:train_length] y_train = X[1:train_length+1] X_test = X[train_length:train_length+test_length] y_test = X[train_length+1:train_length+test_length+1] # Simple training my_esn = SimpleESN(n_readout=1000, n_components=1000, damping = 0.3, weight_scaling = 1.25) echo_train = my_esn.fit_transform(X_train) regr = Ridge(alpha = 0.01) regr.fit(echo_train, y_train) echo_test = my_esn.transform(X_test) y_true, y_pred = y_test, regr.predict(echo_test) err = mean_squared_error(y_true, y_pred) fp = plt.figure(figsize=(12, 4)) trainplot = fp.add_subplot(1, 3, 1) trainplot.plot(X_train[100:600], 'b') trainplot.set_title('Some training signal') echoplot = fp.add_subplot(1, 3, 2) echoplot.plot(echo_train[100:600,:20]) echoplot.set_title('Some reservoir activation') testplot = fp.add_subplot(1, 3, 3) testplot.plot(X_test[-500:], 'b', label='test signal') testplot.plot(y_pred[-500:], 'g', label='prediction') testplot.set_title('Prediction (MSE %0.3f)' % err) testplot.legend(loc='lower right')