Skip to content

Instantly share code, notes, and snippets.

@imjacobclark
Last active April 23, 2017 14:40
Show Gist options
  • Save imjacobclark/a23e29fa11d51b547eef76644f729d37 to your computer and use it in GitHub Desktop.
Save imjacobclark/a23e29fa11d51b547eef76644f729d37 to your computer and use it in GitHub Desktop.
A single layer neural network to determine AND boolean logic
def nn(input1, input2):
bias = 1
weight0 = -1
weight1 = 0.5
weight2 = 0.5
net = (bias*weight0)+(input1*weight1)+(input2*weight2)
return "1" if net >= 0 else "0"
print "X | Y | O "
print "0 | 0 | " + nn(0, 0)
print "1 | 0 | " + nn(1, 0)
print "0 | 1 | " + nn(0, 1)
print "1 | 1 | " + nn(1, 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment