0 | 0 | 0 |
0 | 1 | 1 |
1 | 0 | 1 |
1 | 1 | 1 |
# importing Python library import numpy as np
# define Unit Step Function def unitStep(v):
if v > = 0 :
return 1
else :
return 0
# design Perceptron Model def perceptronModel(x, w, b):
v = np.dot(w, x) + b
y = unitStep(v)
return y
# OR Logic Function # w1 = 1, w2 = 1, b = -0.5 def OR_logicFunction(x):
w = np.array([ 1 , 1 ])
b = - 0.5
return perceptronModel(x, w, b)
# testing the Perceptron Model test1 = np.array([ 0 , 1 ])
test2 = np.array([ 1 , 1 ])
test3 = np.array([ 0 , 0 ])
test4 = np.array([ 1 , 0 ])
print ( "OR({}, {}) = {}" . format ( 0 , 1 , OR_logicFunction(test1)))
print ( "OR({}, {}) = {}" . format ( 1 , 1 , OR_logicFunction(test2)))
print ( "OR({}, {}) = {}" . format ( 0 , 0 , OR_logicFunction(test3)))
print ( "OR({}, {}) = {}" . format ( 1 , 0 , OR_logicFunction(test4)))
|
Output:
Here, the model predicted output (OR(0, 1) = 1 OR(1, 1) = 1 OR(0, 0) = 0 OR(1, 0) = 1