Created
June 30, 2017 09:45
-
-
Save llSourcell/aa7a04914d47c02aefa7141e8af71a6d 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
| import numpy as np | |
| # input data | |
| X = np.array([ [0,0,1], | |
| [0,1,1], | |
| [1,0,1], | |
| [1,1,1] ]) | |
| # output labels | |
| y = np.array([[0,0,1,1]]).T | |
| # initialize weights randomly with mean 0 | |
| weights = 2*np.random.random((3,1)) - 1 | |
| #update weights (training/backpropagation) | |
| for iter in xrange(10000): | |
| # forward propagation | |
| l0 = X | |
| l1 = nonlin(np.dot(l0,weights)) | |
| # how much did we miss? | |
| l1_error = y - l1 | |
| # multiply how much we missed by the | |
| # slope of the sigmoid at the values in l1 | |
| l1_delta = l1_error * nonlin(l1,True) | |
| # update weights | |
| weights += np.dot(l0.T,l1_delta) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment