Created
December 20, 2018 02:34
-
-
Save vikene/5ef38e48551b9dd1d87aec2f6d9eea69 to your computer and use it in GitHub Desktop.
Implementation of OR gate using perceptron
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 | |
input1 = [0,0,1,1] | |
input2 = [1,0,1,0] | |
truth = [0,1,0,1] | |
weight1 = 0 | |
weight2 = -1 | |
bias = 0 | |
def perceptron(input1, input2): | |
score = (input1* weight1) + (input2 * weight2) + bias | |
if score >= 0: | |
return 1 | |
else: | |
return 0 | |
def test_perceptron(): | |
assert perceptron(input1[0],input2[0]) == truth[0] | |
assert perceptron(input1[1],input2[1]) == truth[1] | |
assert perceptron(input1[2],input2[2]) == truth[2] | |
assert perceptron(input1[3],input2[3]) == truth[3] |
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 | |
input1 = [0,0,1,1] | |
input2 = [1,0,1,0] | |
truth = [1,0,1,1] | |
weight1 = 1 | |
weight2 = 1 | |
bias = -1 | |
def perceptron(input1, input2): | |
score = (input1* weight1) + (input2 * weight2) + bias | |
if score >= 0: | |
return 1 | |
else: | |
return 0 | |
def test_perceptron(): | |
assert perceptron(input1[0],input2[0]) == truth[0] | |
assert perceptron(input1[1],input2[1]) == truth[1] | |
assert perceptron(input1[2],input2[2]) == truth[2] | |
assert perceptron(input1[3],input2[3]) == truth[3] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment