수업(국비지원)/Python
[Python] 딥러닝 - 인공신경망(ANN)
byeolsub
2023. 4. 27. 15:11
📌
# 퍼셉트론 AND 게이트 구현
import numpy as np
def AND(x1,x2) :
x = np.array([x1,x2]) # 입력값
w = np.array([0.5, 0.5]) # 가중치
b = -0.8 # 편향
tmp = np.sum(w*x) + b
if tmp <= 0 :
return 0
else :
return 1
for xs in [(0, 0), (0, 1), (1, 0), (1, 1)] :
y = AND(xs[0], xs[1])
print(xs, "=>", y)

# 퍼셉트론 OR 게이트 구현
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
for xs in [(0, 0), (0, 1), (1, 0), (1, 1)] :
y = OR(xs[0], xs[1])
print(xs, "=>", y)

# 퍼셉트론 NAND 게이트 구현
def NAND(x1,x2) :
x = np.array([x1,x2]) # 입력값
w = np.array([-0.5, -0.5]) # 가중치
b = 0.8 # 편향
tmp = np.sum(w*x) + b
if tmp <= 0 :
return 0
else :
return 1
for xs in [(0, 0), (0, 1), (1, 0), (1, 1)] :
y = NAND(xs[0], xs[1])
print(xs, "=>", y)
