2パーセプトロンネットワークを使用してXORゲートを作成しようとしていますが、何らかの理由でネットワークが学習していないため、グラフのエラーの変化をプロットするとエラーが静的レベルその領域で振動する。ニューラルネットワークXORゲートが学習していない
私は現時点でネットワークにいかなるバイアスも加えていませんでした。
import numpy as np
def S(x):
return 1/(1+np.exp(-x))
win = np.random.randn(2,2)
wout = np.random.randn(2,1)
eta = 0.15
# win = [[1,1], [2,2]]
# wout = [[1],[2]]
obj = [[0,0],[1,0],[0,1],[1,1]]
target = [0,1,1,0]
epoch = int(10000)
emajor = ""
for r in range(0,epoch):
for xy in range(len(target)):
tar = target[xy]
fdata = obj[xy]
fdata = S(np.dot(1,fdata))
hnw = np.dot(fdata,win)
hnw = S(np.dot(fdata,win))
out = np.dot(hnw,wout)
out = S(out)
diff = tar-out
E = 0.5 * np.power(diff,2)
emajor += str(E[0]) + ",\n"
delta_out = (out-tar)*(out*(1-out))
nindelta_out = delta_out * eta
wout_change = np.dot(nindelta_out[0], hnw)
for x in range(len(wout_change)):
change = wout_change[x]
wout[x] -= change
delta_in = np.dot(hnw,(1-hnw)) * np.dot(delta_out[0], wout)
nindelta_in = eta * delta_in
for x in range(len(nindelta_in)):
midway = np.dot(nindelta_in[x][0], fdata)
for y in range(len(win)):
win[y][x] -= midway[y]
f = open('xor.csv','w')
f.write(emajor) # python will convert \n to os.linesep
f.close() # you can omit in most cases as the destructor will call it
これはラーニングラウンド数によって変化するエラーです。これは正しいです?赤い色の線は、エラーがどのように変化するかを予想していた線です。
私はコードでやっている何か?私は何が原因でエラーが発生しているのか分からないようです。大いに感謝します。各エポックで計算誤差は、すべての和の合計でなければなりません
あなたは私のブログ記事「TensorFlowを使ったXORチュートリアル」(https:// martin-thoma)に興味があるかもしれません。 .com/tf-xor-tutorial /) –