0
3桁のバイナリ入力を認識するためのニューラルネットワークを作成しようとしています。私のコードは次のとおりです。ターミナルディスプレイが表示されない理由
import numpy as np
#setting the data note that I skipped [0,1,1] for the test
x = np.array([[0,0,0],
[0,0,1],
[0,1,0],
[1,0,0],
[1,0,1],
[1,1,0],
[1,1,1]])
y = np.array([[0,1,2,4,5,6,7]]).T #note I also skipped 3 for testing
#setting the weight
w = np.random.randn()
#setting the unknown
un_x = np.array([[0,1,1]])
class nn:
#defining back_prop
def back_prop(input, weight):
for i in range(1000000):
output = 1/(1 + np.exp(-(np.dot(input, weight))))
weight += np.dot(input.T, (y - output) * output * (1 - output))
w = weight
#defining the sigmoid function
def sigmoid(input, weight):
1/(1 + np.exp(-(np.dot(input, weight))))
#training
nn.back_prop(x, w)
#testing the neural network
print (nn.sigmoid(un_x, w))
端末でプログラムを実行したときに、私は残念でした。 The
最後の行は、3に近い数値を出力するはずでしたが、端末からの応答がありませんでした。このニューラルネットワークは複雑すぎるかもしれないので、私はこのプログラムのために隠れた層が必要かもしれません。しかし、なぜ端末がNoneを表示するのかの応答が得られるまで、私は気にしません。どんな助けでも大歓迎です。
'sigmoid'には' return'文がありません。 – user2357112
'back_prop'と' sigmoid'はインスタンスメソッドではなく静的メソッドでなければなりませんが、 'nn'は全く定義する必要はありません。 2つの方法は単に関数として定義できます。 – chepner