Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import neurolab as nl
- import numpy as np
- # Create train samples
- x = np.linspace(-7, 7, 20)
- y = np.sin(x)
- xG = np.linspace(-7, 7, 200)
- yG = np.sin(xG)
- size = len(x)
- inp = x.reshape(size,1)
- tar = y.reshape(size,1)
- # Create network with 2 layers and random initialized
- net = nl.net.newff([[-7, 7]],[5, 1])
- # Train network
- error = net.train(inp, tar, epochs=500, show=100, goal=0.00001)
- # Simulate network
- out = net.sim(inp)
- # Plot result
- import pylab as pl
- pl.subplot(211)
- pl.plot(error)
- pl.xlabel('Epoch number')
- pl.ylabel('error (default SSE)')
- y2 = net.sim(xG.reshape(xG.size,1)).reshape(xG.size)
- y3 = out.reshape(size)
- pl.subplot(212)
- pl.plot(x , y, 'og', xG,yG,'g',xG, y2, '-r',x, y3, 'ro')
- pl.legend(['train target', 'net output'])
- pl.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement