Beispiel #1
0
fig = plt.figure()
ax = fig.add_subplot(111)

X = np.linspace(-1, 1, 20)
T = np.array(list(map(f, X)))
ax.plot(X, T, 'b', label=u'função logística')
#plt.show()
X = np.asmatrix(X)
T = np.asmatrix(T)
t_set = np.concatenate((X, T), axis=0).T
train = []
for i in range(len(t_set)):
    train += [np.array(t_set)[i].tolist()]

import pyRecog
r = pyRecog.RBF(3, 1)
r.train(train, 0.0, 10000, 0.1, 0.5)

X = np.linspace(-1, 1, 20)
Y = []
for i in X:
    Y += [r([i])[0]]

ax.plot(X, Y, 'r', label=u'RBF')

title = ax.set_title("\n".join(
    wrap(
        u'Aproximando função logística com 3 neurônios RBF e variância 0.5 (10mil épocas)',
        60)))
title.set_y(1.05)
fig.subplots_adjust(top=0.8)
Beispiel #2
0
fig = plt.figure()
ax = fig.add_subplot(111)

X = np.arange(0,4*pi,0.2)
T = np.sin(X)
ax.scatter(X,T,s=80,c='green',marker='+', label=u'dados de treinamento')
X = np.asmatrix(X)
T = np.asmatrix(T)
t_set = np.concatenate((X,T), axis=0).T
train = []
for i in range(len(t_set)):
	train += [np.array(t_set)[i].tolist()]

import pyRecog
r = pyRecog.RBF(45,1)
r.train(train, 0.0, 1000000, 0.1, 1.0)

X = np.linspace(0,4*pi,800)
T = np.sin(X)
Y = []
for i in X:
	Y += [r([i])[0]]

ax.plot(X,T,'b', label=u'função seno')
ax.plot(X,Y,'r', label='RBF')

title = ax.set_title("\n".join(wrap(u'Aproximando função seno com 45 neurônios RBF e variância 1.0 (1milhão épocas)', 60)))
title.set_y(1.05)
fig.subplots_adjust(top=0.8)
plt.xlabel('x')
Beispiel #3
0
ax.legend(bbox_to_anchor=[1, 0.3])
fig.savefig("f_5v1_train_data_paper.png")

fig = plt.figure()
ax = fig.add_subplot(111)
ax.scatter(X3, T3, s=80, c='green', marker='+', label=u'dados de treinamento')
X4 = np.asmatrix(X3)
T4 = np.asmatrix(T3)
t_set = np.concatenate((X4, T4), axis=0).T
train = []
for i in range(len(t_set)):
    train += [np.array(t_set)[i].tolist()]

import pyRecog

r = pyRecog.RBF(5, 1)
r.train(train, 0.0, 10000, 0.1, 1.0)

Y = []
for i in X2:
    Y += [r([i])[0]]

ax.plot(X2, Y, 'r', label=u'RBF')

title = ax.set_title("\n".join(
    wrap(
        u'Aproximando função logística com 5 neurônios RBF e variância 1.0 (10mil épocas)',
        60)))
title.set_y(1.05)
fig.subplots_adjust(top=0.8)
plt.xlabel('x')
Beispiel #4
0
plt.ylabel('f(x)')
ax.legend()
fig.savefig("f_4v1_train_data_paper.png")

fig = plt.figure()
ax = fig.add_subplot(111)
ax.scatter(X, T, s=80, c='green', marker='+', label=u'dados de treinamento')
X = np.asmatrix(X)
T = np.asmatrix(T)
t_set = np.concatenate((X, T), axis=0).T
train = []
for i in range(len(t_set)):
    train += [np.array(t_set)[i].tolist()]

import pyRecog
r = pyRecog.RBF(4, 1)
r.train(train, 0.0, 10000, 0.1, 1.0)

X = np.linspace(-1, 1, 400)
Y = []
for i in X:
    Y += [r([i])[0]]

ax.plot(X, Y, 'r', label='RBF')

title = ax.set_title("\n".join(
    wrap(
        u'Aproximando função logística com 4 neurônios RBF e variância 1.0 (10mil épocas)',
        60)))
title.set_y(1.05)
fig.subplots_adjust(top=0.8)
Beispiel #5
0
fig = plt.figure()
ax = fig.add_subplot(111)

X2 = np.linspace(0, 2 * pi, 400)
T2 = np.sin(X2)
X3 = np.linspace(0, 2 * pi, 50)
noise = np.random.normal(0.0, 0.1, len(X3))
T3 = np.sin(X3) + noise

X4 = np.asmatrix(X3)
T4 = np.asmatrix(T3)
t_set = np.concatenate((X4, T4), axis=0).T
train = []
for i in range(len(t_set)):
    train += [np.array(t_set)[i].tolist()]

import pyRecog

r = pyRecog.RBF(10, 1)
r.train(train, 0.0, 10000, 0.1, 1.0)

Y = []
sum1 = 0
for i in range(len(X2)):
    y = r([X2[i]])[0]
    Y += [y]
    sum1 += 0.5 * ((T2[i] - y)**2)
errm = sum1 / float(len(X2))

print("\n", errm)