In [1]:
# -*- coding: utf-8 -*-
import neurolab as nl
import numpy as np
import matplotlib.pyplot as plt
In [34]:
# Create train samples
x = np.linspace(-7, 7, 100)
y = np.sin(x) * 0.5
size = len(x)
inp = x.reshape(size,1)
tar = y.reshape(size,1)
In [2]:
x = np.array([ -55.55314636, -65.10617065, -70.06878662, -73.85668945,
-75.45127869, -79.01815033, -61.11135483, 39.18991089,
240.60343933, 443.12762451, 565.97528076, 721.25946045,
688.79193115, 747.73071289, 521.52142334, 162.62878418,
67.57603455, 114.57978058, 56.45625305, -39.98975372,
-90.85538483, -96.85674286, -105.04946899, -104.99243164,
-104.94757843, -102.07447052, -105.10523224, -110.2276535 ,
-111.37414551, -103.603302 , -84.02243042, 26.85051537,
265.19674683, 242.63238525, 603.84710693, 693.66717529,
708.67352295, 826.24505615, 475.85739136, 673.72344971,
339.55862427, 194.75097656, 20.10501289, -53.2533989 ,
-83.5115509 , -77.96046448, -78.35413361, -87.11660004,
-94.29645538])
y = np.array([ -27.77657318, -32.55308533, -35.03439331, -36.92834473,
-37.72563934, -39.50907516, -30.55567741, 19.59495544,
120.30171967, 221.56381226, 282.98764038, 360.62973022,
344.39596558, 373.86535645, 260.76071167, 81.31439209,
33.78801727, 57.28989029, 28.22812653, -19.99487686,
-45.42769241, -48.42837143, -52.5247345 , -52.49621582,
-52.47378922, -51.03723526, -52.55261612, -55.11382675,
-55.68707275, -51.801651 , -42.01121521, 13.42525768,
132.59837341, 121.31619263, 301.92355347, 346.83358765,
354.33676147, 413.12252808, 237.92869568, 336.86172485,
169.77931213, 97.37548828, 10.05250645, -26.62669945,
-41.75577545, -38.98023224, -39.1770668 , -43.55830002,
-47.14822769])
size = len(x)
inp = x.reshape(size,1)
tar = y.reshape(size,1)
In [3]:
inp_min = np.min(inp)
inp_max = np.max(inp)
print inp_min,inp_max
In [6]:
# first try that worked, used newelm
#net = nl.net.newelm([[inp_min, inp_max]],[5, 1],[nl.trans.TanSig(), nl.trans.PureLin()])
#net.trainf = nl.train.train_rprop
# second try
#net = nl.net.newff([[inp_min, inp_max]],[5, 1],[nl.trans.TanSig(), nl.trans.PureLin()])
#net.trainf = nl.train.train_rprop
# third try
net = nl.net.newff([[inp_min, inp_max]],[5, 1],[nl.trans.PureLin(), nl.trans.PureLin()])
net.trainf = nl.train.train_rprop
In [7]:
error = net.train(inp, tar, epochs=1000, show=100, goal=0.00002)
In [8]:
fig=plt.figure()
plt.plot(error)
plt.show()
In [9]:
out = net.sim(inp)
In [10]:
fig=plt.figure()
plt.plot(tar,'b.')
plt.plot(out,'r-')
plt.show()
In [ ]: