Created
September 24, 2019 20:30
-
-
Save aballah-chamakh/8ec69c86391e10c5b0f3119566a8b0f4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def train(x,y,w1,w2,w3,b1,b2,b3) : | |
| # feed forward | |
| inp_l = x | |
| l1 = sigmoid(np.dot(inp_l,w1) + b1) | |
| l2 = sigmoid(np.dot(l1,w2) + b2) | |
| l3 = sigmoid(np.dot(l2,w3) + b3) | |
| #backpropagation | |
| delta_l3 = (y - l3)*sigmoid_prime(l3) | |
| delta_l2 = delta_l3.dot(w3.T)*sigmoid_prime(l2) | |
| delta_l1 = delta_l2.dot(w2.T)*sigmoid_prime(l1) | |
| #update weights | |
| w3 += (np.dot(l2.T,delta_l3)) | |
| w2 += (np.dot(l1.T,delta_l2)) | |
| w1 += (np.dot(inp_l.T,delta_l1)) | |
| # update biases | |
| b3 = b3 + (np.sum(delta_l3,axis=0)) | |
| b2 = b2 + (np.sum(delta_l2,axis=0)) | |
| b1 = b1 + (np.sum(delta_l1,axis=0)) | |
| #print(b1.shape) | |
| return w1,w2,w3,b1,b2,b3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment