Created
November 9, 2019 18:39
-
-
Save TheBojda/d76d8e5d76f72bccaef4a071fcd6d28c to your computer and use it in GitHub Desktop.
This file contains 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
# Simple neural network with NumPy from 11 lines of code | |
# source: https://iamtrask.github.io/2015/07/12/basic-python-network/ | |
X = np.array([ [0,0,1],[0,1,1],[1,0,1],[1,1,1] ]) | |
y = np.array([[0,1,1,0]]).T | |
syn0 = 2*np.random.random((3,4)) - 1 | |
syn1 = 2*np.random.random((4,1)) - 1 | |
for j in xrange(60000): | |
l1 = 1/(1+np.exp(-(np.dot(X,syn0)))) | |
l2 = 1/(1+np.exp(-(np.dot(l1,syn1)))) | |
l2_delta = (y - l2)*(l2*(1-l2)) | |
l1_delta = l2_delta.dot(syn1.T) * (l1 * (1-l1)) | |
syn1 += l1.T.dot(l2_delta) | |
syn0 += X.T.dot(l1_delta) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment