Advertisement
Guest User

gigiduru

a guest
Mar 29th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. import neurolab as nl
  2. import numpy as np
  3.  
  4. # Create train samples
  5. x = np.linspace(-7, 7, 20)
  6. y = np.sin(x)
  7.  
  8. xG = np.linspace(-7, 7, 200)
  9. yG = np.sin(xG)
  10.  
  11. size = len(x)
  12.  
  13. inp = x.reshape(size,1)
  14. tar = y.reshape(size,1)
  15.  
  16. # Create network with 2 layers and random initialized
  17. net = nl.net.newff([[-7, 7]],[5, 1])
  18.  
  19. # Train network
  20. error = net.train(inp, tar, epochs=500, show=100, goal=0.00001)
  21.  
  22. # Simulate network
  23. out = net.sim(inp)
  24.  
  25. # Plot result
  26. import pylab as pl
  27. pl.subplot(211)
  28. pl.plot(error)
  29. pl.xlabel('Epoch number')
  30. pl.ylabel('error (default SSE)')
  31.  
  32.  
  33. y2 = net.sim(xG.reshape(xG.size,1)).reshape(xG.size)
  34.  
  35. y3 = out.reshape(size)
  36.  
  37. pl.subplot(212)
  38. pl.plot(x , y, 'og', xG,yG,'g',xG, y2, '-r',x, y3, 'ro')
  39. pl.legend(['train target', 'net output'])
  40. pl.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement