Example #1
1

###########################################################
# MAIN

trainsize = 4000
washout = 2000
testsize = 8000

# choose ESN: compare STD-ESN with BP-ESN
net, trainnoise, testnoise = setup_STD_ESN()
# net, trainnoise, testnoise = setup_ESN_BP()
net.init()

# generate signals
slsine = generate_slow_sine(trainsize + testsize)
trainin, trainout, testin, testout = get_esn_data(slsine, trainsize, testsize)

# ESN training
net.setNoise(trainnoise)
net.train(trainin, trainout, washout)
print "output weights:"
print "\tmean: ", net.getWout().mean(), "\tmax: ", abs(net.getWout()).max()

# ESN simulation
esnout = N.empty(testout.shape)
net.setNoise(testnoise)
net.simulate(testin, esnout)
print "\nNRMSE: ", errorcalc.nrmse(esnout, testout, 50)
plot(esnout, testout)
Example #2
0
washout = 200
testsize = 2200

# choose ESN: compare performance between square and STD-ESN
#net, trainnoise, testnoise = setup_STD_ESN()
net, trainnoise, testnoise = setup_SQUARE_ESN()

# generate train/test signals
size = trainsize+testsize
x = random.rand(size)*0.5
y = narma10(x)

# create in/outs with bias input
trainin, trainout, testin, testout = get_esn_data(x,y,trainsize,testsize)

# ESN training
net.setNoise(trainnoise)
print "training ..."
net.train(trainin,trainout,washout)
print "output weights:"
print "\tmean: ", net.getWout().mean(), "\tmax: ", abs(net.getWout()).max()

# ESN simulation
esnout = empty(testout.shape)
net.setNoise(testnoise)
net.simulate(testin,esnout)
nrmse = errorcalc.nrmse( esnout, testout, washout )
print "\nNRMSE: ", nrmse
print "\nNMSE: ", errorcalc.nmse( esnout, testout, washout )
plot(esnout,testout)
Example #3
0
x = random.rand(size) * 0.5

# choose system: for very large stepsize increase trainsize !!
#y = narma10sparse(x,10)
y = sparseSystem2(x, step=50)

# create in/out data
trainin, trainout, testin, testout = get_esn_data(x, y, trainsize, testsize)

# ESN training
net.setNoise(net.trainnoise)
net.train(trainin, trainout, washout)
if (net.ds == 1):
    delays = zeros((1, 102))
    net.getDelays(delays)
    print "trained delays:"
    print delays
print "output weights:"
print "\tmean: ", net.getWout().mean(), "\tmax: ", abs(net.getWout()).max()

# ESN simulation
esnout = empty(testout.shape)
net.setNoise(net.testnoise)
net.simulate(testin, esnout)
nrmse = errorcalc.nrmse(esnout, testout, washout)
print "\nNRMSE: ", nrmse
print "\nNMSE: ", errorcalc.nmse(esnout, testout, washout)

# final plotting
plot(esnout, testout)
Example #4
0
testsize = 300

# make sine
n = N.arange(float(trainsize+testsize))
signal = N.sin(2*N.pi*n* 0.05)

# generate train/test data
trainout = signal[0:trainsize]
trainout.shape = 1, -1
trainin = N.zeros(trainout.shape)
testout = signal[trainsize:trainsize+testsize]
testout.shape = 1, -1
testin = N.zeros(testout.shape)

# ESN training
net.train(trainin, trainout, washout)
delays = N.zeros((1,2))
net.getDelays(delays)
print "output weights:", net.getWout()
print "calculated delays:", delays

# ESN simulation
esnout = N.empty(testout.shape)
net.simulate(testin, esnout)
print "\nNRMSE: ", errorcalc.nrmse(esnout, testout, 50)

# some plotting
P.plot(testout.flatten())
P.plot(esnout.flatten(), 'r')
P.show()