Skip to content

Instantly share code, notes, and snippets.

@soundmasteraj
Forked from miloharper/short_version.py
Last active March 13, 2018 15:55
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 soundmasteraj/1abde249b59a1246e399ef3287efc7a7 to your computer and use it in GitHub Desktop.
Save soundmasteraj/1abde249b59a1246e399ef3287efc7a7 to your computer and use it in GitHub Desktop.
A neural network in 9 lines of Python code.
from numpy import exp, array, random, dot
training_set_inputs = array([[0, 0, 1], [1, 1, 1], [1, 0, 1], [0, 1, 1]])
training_set_outputs = array([[0, 1, 1, 0]]).T
random.seed(1)
synaptic_weights = 2 * random.random((3, 1)) - 1
for iteration in xrange(10000):
output = 1 / (1 + exp(-(dot(training_set_inputs, synaptic_weights))))
synaptic_weights += dot(training_set_inputs.T, (training_set_outputs - output) * output * (1 - output))
print 1 / (1 + exp(-(dot(array([1, 0, 0]), synaptic_weights))))
@soundmasteraj
Copy link
Author

Milo Spencer-Harper wrote this article in 2015 on medium.com

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment