X OR problem using DNN
X OR problem using DNN
for j in range(m):
sys.stdout.write("\rIteration: {} and {}".format(i + 1, j + 1))
# Forward Propagation
a0 = X[j].reshape(X[j].shape[0], 1) # 2x1
z1 = _W1.dot(a0) + _B1 # 2x2 * 2x1 + 2x1 = 2x1
a1 = sigmoid(z1) # 2x1
z2 = _W2.dot(a1) + _B2 # 1x2 * 2x1 + 1x1 = 1x1
a2 = sigmoid(z2) # 1x1
# Backpropagation
dz2 = a2 - y[j] # 1x1
dW2 += dz2 * a1.T # 1x1 .* 1x2 = 1x2
dz1 = np.multiply(_W2.T.dot(dz2), sigmoid(a1, derv=True)) # Corrected: matrix
multiplication with .dot()
dW1 += dz1.dot(a0.T) # 2x1 * 1x2 = 2x2
dB1 += dz1 # 2x1
dB2 += dz2 # 1x1
# Cost function
c += (-(y[j] * np.log(a2)) - ((1 - y[j]) * np.log(1 - a2)))