Skip to content

Commit

Permalink
create simple neural network
Browse files Browse the repository at this point in the history
  • Loading branch information
carlodavid012 committed Jul 15, 2018
1 parent 4dd810a commit 56a10f2
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions Day 9 - simple neural network/neural_network.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import numpy as np

#sigmoid function
def nonlin(x, deriv=False):
if(deriv==True):
return x*(1-x)
return 1/(1+np.exp(-x))

#input dataset
X = np.array([ [0,0,1],
[0,1,1],
[1,0,1],
[1,1,1] ])

#output dataset
y = np.array([[0,0,1,1]]).T

#seed random numbers to make calculation
# deterministic (just a good practice)
np.random.seed(1)

# initialize weights randomly with mean 0
syn0 = 2*np.random.random((3,1)) - 1

for iter in range(10000):

#forward propagation
l0 = X
l1 = nonlin(np.dot(l0, syn0))

#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
syn0 += np.dot(l0.T, l1_delta)

print("Output After Training:")
print(l1)













0 comments on commit 56a10f2

Please sign in to comment.