1
$\begingroup$

enter image description here

This is what i'm trying to implement in Python.

  • w0,...,w8 = vector w1 of shape (9,1)
  • w9,...,w11 = vector w2 of shape (3,1)
  • b0 (first bias) is of shape (3,1)
  • b1 is of shape (1,1)
  • vector X is of shape (99, 3)

I don't know where the problem resides because when I try to forward propagate, I get the not aligned error when doing the dot product since the multiplication is not possible... Is my neural network wrong ?

$\endgroup$
4
  • $\begingroup$ You have defined the shapes of your weights array incorrectly. Take for example your vector w1 of shape (9, 1), which would have to be multiplied with an input vector of shape (3, 1). You should changes your weight matrices to have shape (n_input, n_output), for w1 this would mean that it should have a shape of (3, 3). $\endgroup$
    – Oxbowerce
    Jun 20, 2021 at 11:52
  • $\begingroup$ I see thank you for clarifying. However after changing w1 to (3,3) I get this error when doing forward propagation: "Z1 = X.dot(W1) + b1 ValueError: operands could not be broadcast together with shapes (99,3) (3,1)". Does the issue reside in the shapes of the addition since they have to be exactly the same shape for an addition to work ? I also tried np.dot(X, W1) + b1 but I get the same error. $\endgroup$
    – user
    Jun 21, 2021 at 19:37
  • $\begingroup$ That is because the shape of your bias vector is not correct, either change it to (1, 3) when initializing it or change your formula to use the transpose of your current bias vector (b1.T). $\endgroup$
    – Oxbowerce
    Jun 22, 2021 at 10:22
  • $\begingroup$ Are you sure ? Now that I have changed it to (1, 3), I get an another error in backward propagation this time : "dW2 = 1 / m * np.dot(dZ2, A1.T) File "<__array_function__ internals>", line 5, in dot ValueError: shapes (99,1) and (3,99) not aligned: 1 (dim 1) != 3 (dim 0) ". With A1 = self.sigmoid(Z1), Z1 = np.dot(X, W1) + b1; dZ2 = 1/2 * (A2 - Y)**2; A2 = self.sigmoid(Z2) with Z2 = np.dot(A1, W2) + b2... $\endgroup$
    – user
    Jun 22, 2021 at 20:47

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.