import numpy as np
import nnet as net
import matplotlib.pyplot as plt
x = np.array([[-1.0, -0.9, -0.8, -0.7, -0.6, -0.5]])
y_t = np.array([[-0.9602, -0.5770, -0.0729, 0.3771, 0.6405, 0.6600]])
L = x.shape[0]
K1 = y_t.shape[0]
w1, b1 = net.nwlog(K1, L)
max_epoch = 20000
err_goal = 0.01
disp_freq = 1000
lr = 0.1
SSE_vec = []
for epoch in range(1, max_epoch+1):
y1 = net.logsig(np.dot(w1, x), b1)
e = y_t - y1
SSE = net.sumsqr(e)
if np.isnan(SSE):
break
SSE_vec.append(SSE)
if SSE < err_goal:
break
d1 = net.deltalog(y1, e)
dw1, db1 = net.learnbp(x, d1, lr)
w1 += dw1
b1 += db1
if (epoch % disp_freq) == 0:
plt.clf()
print("Epoch: ] | SSE: %5.5f " % (epoch, SSE))
plt.plot(x[0], y_t[0], 'r', x[0], y1[0], 'g')
plt.grid()
plt.show()
plt.pause(1e-2)
plt.figure()
plt.plot(SSE_vec)
plt.ylabel('SSE')
plt.yscale('linear')
plt.title('epoch')
plt.grid(True)
plt.show()
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}