0
バックプロパゲーションアルゴリズムを記述しようとしていますが、行列乗算を実行しようとするとエラーが発生します。行列乗算型エラー
私は、私は次のエラーを取得する
# necessary functions for this example
def sigmoid(z):
return 1.0/(1.0+np.exp(-z))
def prime(z):
return sigmoid(z) * (1-sigmoid(z))
def cost_derivative(output_activations, y):
return (output_activations-y)
# Mock weight and bias matrices
weights = [np.array([[ 1, 0, 2],
[2, -1, 0],
[4, -1, 0],
[1, 3, -2],
[0, 0, -1]]),
np.array([2, 0, -1, -1, 2])]
biases = [np.array([-1, 2, 0, 0, 4]), np.array([-2])]
# The mock training example
q = [(np.array([1, -2, 3]), np.array([0])),
(np.array([2, -3, 5]), np.array([1])),
(np.array([3, 6, -1]), np.array([1])),
(np.array([4, -1, -1]), np.array([0]))]
for x, y in q:
activation = x
activations = [x]
zs = []
for w, b in zip(weights, biases):
z = np.dot(w, activation) + b
zs.append(z)
activation = sigmoid(z)
activations.append(activation)
delta = cost_derivative(activations[-1], y) * prime(zs[-1])
print(np.dot(np.transpose(weights[-1])), delta)
で作業するには、次の簡単な例を作成しました:
TypeError: Required argument 'b' (pos 2) not found
私は5X2である転置weights
の両方の出力を印刷しました行列であり、delta
は2x1です。出力は以下のとおりです。
np.transpose(weights[-1]) = [[ 2 -3]
[ 0 2]
[-1 0]
[-1 1]
[ 2 -1]]
と
delta = [-0.14342712 -0.03761959]
ので、乗算は5X1行列を仕事と生成しなければならない
の
すべきですか?それは輸入ですか? – mitoRibo
申し訳ありません、コードのその部分をコピーするのを忘れました – Lukasz