-
Notifications
You must be signed in to change notification settings - Fork 0
/
tm3.py
43 lines (33 loc) · 971 Bytes
/
tm3.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# -*- coding: utf-8 -*-
"""tm3.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1lTUuTpfdi_V_zQFG0lD7zXHhcMw389dP
"""
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 = 0.5, w2 = 0.5, b = -0.3
def OR_logicFunction(x):
w = np.array([0.5, 0.5])
b = -0.3
return perceptronModel(x, w, b)
# testing the Perceptron Model
test1 = np.array([0, 0])
test2 = np.array([0, 1])
test3 = np.array([1, 0])
test4 = np.array([1, 1])
print("OR({}, {}) = {}".format(0, 0, OR_logicFunction(test1)))
print("OR({}, {}) = {}".format(0, 1, OR_logicFunction(test2)))
print("OR({}, {}) = {}".format(1, 0, OR_logicFunction(test3)))
print("OR({}, {}) = {}".format(1, 1, OR_logicFunction(test4)))