Created
July 18, 2017 03:01
-
-
Save randcode-generator/63ee23c3cecf1d0977dccb9fa4afc96e 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
import numpy as np | |
inputLayerSize, hiddenLayerSize, outputLayerSize = 2, 3, 1 | |
L = 0.1 | |
X = np.array([[0,0], [0,1], [1,0], [1,1]]) | |
Y = np.array([[0], [1], [1], [0]]) | |
iterations = 50000 | |
#sigmoid function | |
def f(x): return 1/(1 + np.exp(-x)) | |
#derivative sigmoid | |
def f_(x): return x * (1 - x) | |
np.random.seed(1) | |
H1 = np.random.uniform(size=(inputLayerSize, hiddenLayerSize)) | |
H2 = np.random.uniform(size=(hiddenLayerSize, outputLayerSize)) | |
for i in range(iterations): | |
R0 = np.dot(X, H1) | |
R = f(R0) | |
Oc = np.dot(R, H2) | |
E = Y - Oc | |
dOc = E * L | |
dR = dOc.dot(H2.T) * f_(R) | |
H2 += R.T.dot(dOc) | |
H1 += X.T.dot(dR) | |
print f(np.dot(X, H1)).dot(H2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment