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_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))
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_fit(): esn = SimpleESN(n_readout = n_readout) esn = esn.fit(X) assert_true(esn.weights_ is not None) assert_true(esn.input_weights_ is not None) assert_true(esn.readout_idx_ is not None)
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))
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))
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))
# # load data and make training set # data = torch.load('MackeyGlass_t17.txt') # # data shape should be (lens_ts, n_features) # 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')
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)
def test_SimpleESN_fit(): esn = SimpleESN(n_readout=n_readout) esn = esn.fit(X) assert_true(esn.weights_ is not None) assert_true(esn.input_weights_ is not None) assert_true(esn.readout_idx_ is not None)
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))
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))
def test_SimpleESN_shape(): esn = SimpleESN(n_readout=n_readout) echoes = esn.fit_transform(X) assert_true(echoes.shape == (n_samples, n_readout))
test_data = Utils.readDataFile(test_data_file) trainData=Utils.importTrainingData(training_data) testData= Utils.importTestData(test_data) trainSongsNotes = trainData[0] testSongsNotes = testData[0] trainSongsRhythm = trainData[1] testSongsRhythm = testData[1] ####################### Reservoir Part #fixed reservoir #n_readout = 3 #discard = 40 #esn = SimpleESN(n_readout, n_components = 100, damping = 0.2, weight_scaling = 0.99, random_state = 1, discard_steps = discard) esn = SimpleESN(n_readout, n_components=n_components, damping = damping, weight_scaling = weight_scaling, random_state = random_seed, discard_steps=discard) #### feed one or more songs to the reservoir and collect the echoes ####################### Learning Part possibleComposers = list(np.unique(training_data[:,1])) possibleInstruments = list(np.unique(training_data[:,3])) possibleStyles = list(np.unique(training_data[:,4])) possibleYears = list(np.unique(training_data[:,5]))
def test_SimpleESN_shape(): esn =SimpleESN(n_readout = n_readout) echoes = esn.fit_transform(X) assert_true(echoes.shape == (n_samples, n_readout))
for index, i in enumerate(update): client.send_message(f"/ESN/{index}", ((i+1)/2)) #client.send_message(f'/ESN/6', update[6]) if __name__ == '__main__': <<<<<<< HEAD esn = SimpleESN(n_readout=20, n_components=20, n_inputs=1, input_gain=3, input_sparcity=1, damping=0.9, weight_scaling=1.5, sparcity=1.0, random_state=31337) ======= # esn = SimpleESN(n_readout=7, n_components=7, n_inputs=1, input_gain=6, input_sparcity=1, damping=0.9, random_state=95326, weight_scaling=1.55, sparcity=0.7) #esn = SimpleESN(n_readout=7, n_components=7, n_inputs=1, input_gain=3, input_sparcity=1, damping=0.9, random_state=95326, weight_scaling=1.55, sparcity=0.7) #esn = SimpleESN(n_readout=7, n_components=7, n_inputs=1, input_gain=3, input_sparcity=1, damping=0.9, random_state=95326, weight_scaling=1.25, sparcity=0.7) #esn = SimpleESN(n_readout=25, n_components=25, n_inputs=1, input_gain=1, input_sparcity=1, damping=0.9, random_state=95326, weight_scaling=1.15, sparcity=0.95) #esn = SimpleESN(n_readout=16, n_components=16, n_inputs=2, input_gain=3, input_sparcity=0.3, damping=0.8, random_state=95328, weight_scaling=3, sparcity=0.0685) #esn = SimpleESN(n_readout=16, n_components=16, n_inputs=2, input_gain=3, input_sparcity=0.3, damping=0.8, random_state=95328, weight_scaling=1.15, sparcity=0.7) #esn = SimpleESN(n_readout=16, n_components=16, n_inputs=2, input_gain=3, input_sparcity=0.3, damping=0.8, random_state=95398, weight_scaling=1.25, sparcity=0.7) #esn = SimpleESN(n_readout=16, n_components=16, n_inputs=2, input_gain=3, input_sparcity=0.7, damping=0.9, random_state=95398, weight_scaling=1.65, sparcity=0.7) #esn = SimpleESN(n_readout=16, n_components=16, n_inputs=2, input_gain=3, input_sparcity=0.7, damping=0.4, random_state=95398, weight_scaling=2.0, sparcity=0.7)
import numpy as np 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')
from time import time import numpy as np 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)