示例#1
0
def test_SimpleESN_initialization():
    esn = SimpleESN(n_readout,
                    n_components=100,
                    damping=0.5,
                    weight_scaling=0.9,
                    discard_steps=0,
                    random_state=None)
    echoes = esn.fit_transform(X)
    assert_true(echoes.shape == (n_samples, n_readout))
示例#2
0
    X = loadtxt('MackeyGlass_t17.txt')
    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')
示例#3
0
def test_SimpleESN_shape():
    esn =SimpleESN(n_readout = n_readout)
    echoes = esn.fit_transform(X)
    assert_true(echoes.shape == (n_samples, n_readout)) 
示例#4
0
def test_SimpleESN_initialization():
    esn = SimpleESN(n_readout, n_components=100, damping=0.5,
                    weight_scaling=0.9, discard_steps=0, random_state=None)
    echoes = esn.fit_transform(X)
    assert_true(echoes.shape == (n_samples, n_readout))
示例#5
0
def test_SimpleESN_incorrect_readout():
    n_readout, n_components = 10, 5
    esn =SimpleESN(n_readout = n_readout, n_components = n_components)
    echoes = esn.fit_transform(X)
    assert_true(echoes.shape == (n_samples, n_components)) 
示例#6
0
def test_SimpleESN_discard():
    discard_steps = 3
    esn =SimpleESN(n_readout = n_readout, discard_steps = discard_steps)
    echoes = esn.fit_transform(X)
    assert_true(echoes.shape == (n_samples-discard_steps, n_readout)) 
示例#7
0
    # train_input = data[0, :-1]
    # train_input=atleast_2d(train_input).T
    # train_target = data[0, 1:]
    # train_target=atleast_2d(train_target).T

    # test_input=data[-1,:-1]
    # test_input=atleast_2d(test_input).T
    # test_target=data[-1,1:]
    # test_target=atleast_2d(test_target).T

    # Simple training
    model_esn = SimpleESN(n_readout=1000,
                          n_components=1000,
                          damping=0.3,
                          weight_scaling=1.25)
    echo_train_state = model_esn.fit_transform(train_input)
    regr = Ridge(alpha=0.01)
    regr.fit(echo_train_state, train_target)

    # show the train result
    echo_train_target, echo_train_pred = train_target, regr.predict(
        echo_train_state)

    err_train = mean_squared_error(echo_train_target, echo_train_pred)

    data_figures = plt.figure(figsize=(12, 4))
    trainplot = data_figures.add_subplot(1, 3, 1)
    trainplot.plot(train_input[:], 'b')
    trainplot.set_title('Training Signal')

    echoplot = data_figures.add_subplot(1, 3, 2)
示例#8
0
def test_SimpleESN_incorrect_readout():
    n_readout, n_components = 10, 5
    esn = SimpleESN(n_readout=n_readout, n_components=n_components)
    echoes = esn.fit_transform(X)
    assert_true(echoes.shape == (n_samples, n_components))
示例#9
0
def test_SimpleESN_discard():
    discard_steps = 3
    esn = SimpleESN(n_readout=n_readout, discard_steps=discard_steps)
    echoes = esn.fit_transform(X)
    assert_true(echoes.shape == (n_samples - discard_steps, n_readout))
示例#10
0
def test_SimpleESN_shape():
    esn = SimpleESN(n_readout=n_readout)
    echoes = esn.fit_transform(X)
    assert_true(echoes.shape == (n_samples, n_readout))
示例#11
0
from simple_esn import SimpleESN
import numpy as np
n_samples, n_features = 10, 5
np.random.seed(0)
X = np.random.randn(n_samples, n_features)
esn = SimpleESN(n_readout=2)
echoes = esn.fit_transform(X)
示例#12
0
if __name__ == '__main__':
    X = loadtxt('MackeyGlass_t17.txt')
    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')