Skip to content

Instantly share code, notes, and snippets.

@amacgregor
Created May 22, 2016 22:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amacgregor/87e62dab1c21edde35cecd1f42a2cbe5 to your computer and use it in GitHub Desktop.
Save amacgregor/87e62dab1c21edde35cecd1f42a2cbe5 to your computer and use it in GitHub Desktop.
from numpy import exp, array, random, dot
ts_inputs = array([[0, 0, 0], [0, 0, 1], [0, 1, 1], [1, 0, 1], [1, 1, 1]])
ts_outputs = array([[0, 0, 0, 1, 1]]).T
#unknown input
un_input = array([1, 0, 0])
# initialize synapse_weights
random.seed(1)
sy_weights = 2 * random.random((3,1)) - 1
# Weights before training
print sy_weights
# train the network
for i in xrange(10000):
output = 1 / (1 + exp(-(dot(ts_inputs, sy_weights)))) # Calculate the value for the each of the examples
sy_weights += dot(ts_inputs.T, (ts_outputs - output) * output * (1 - output)) # Run the adjustments
# Weights after training
print sy_weights
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment