Perceptron
- 퍼셉트론? 다수의 신호를 입력으로 받아 하나의 신호를 출력.
- 간단한 게이트들 : AND, NAND, OR, NOR
신호 => 강물, 전류, 바람 같이 "흐름"이 있는 것으로 생각! 가중치=weight(w), 편향=bias(b) 를 매개변수로 설정해 나타냄.
def AND(x1, x2):
x = np.array([x1,x2])
w = np.array([0.5, 0.5])
b = -0.7
tmp = np.sum(w*x) + b
if tmp <= 0:
return 0
else:
return 1
def NAND(x1, x2):
x = np.array([x1,x2])
w = np.array([-0.5, -0.5])
b = 0.7
tmp = np.sum(w*x) + b
if tmp <= 0:
return 0
else:
return 1
def OR(x1, x2):
x = np.array([x1,x2])
w = np.array([0.5, 0.5])
b = -0.2
tmp = np.sum(w*x) + b
if tmp <= 0:
return 0
else:
return 1
def NOR(x1, x2):
x = np.array([x1,x2])
w = np.array([-0.5, -0.5])
b = 0.2
tmp = np.sum(w*x) + b
if tmp <= 0:
return 0
else:
return 1
def XOR(x1,x2):
""" USING ONLY NAND 1"""
s1 = NAND(x1,x1)
s2 = NAND(x2,x2)
t1 = NAND(s1,x2)
t2 = NAND(x1,s2)
return NAND(t1,t2)
""" USING ONLY NAND 2"""
nand = NAND(x1,x2)
s1 = NAND(x1,nand)
s2 = NAND(x2,nand)
return NAND(s1,s2)
""" USING AND, OR, NAND """
s1 = NAND(x1,x2)
s2 = OR(x1,x2)
return AND(s1,s2)
댓글
댓글 쓰기