Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def relu(x): return (np.maximum(0, x))
- for i in range(20): # Do not change this, we will compare performance at 1000 epochs
- # Forward pass
- L1 = relu(W1.dot(X))
- L2 = relu(W2.dot(L1))
- L3 = sigmoid(W3.dot(L2))
- # Backward pass
- dW3 = (L3 - T) * L3*(1 - L3)
- dW2 = W3.T.dot(dW3)
- dW2[(W2.dot(L1) <= 0)] = 0
- dW1 = W2.T.dot(dW2)
- dW1[(W1.dot(X) <=0)] = 0
- # Update
- W3 -= lr*np.dot(dW3, L2.T)
- W2 -= lr*np.dot(dW2, L1.T)
- W1 -= lr*np.dot(dW1, X.T)
- loss = np.sum((L3 - T)**2)/len(T.T)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement