AND Gate
# w1, w2는 가중치(weight)를 의미하는 변수입니다.
def AND(x1, x2):
w1, w2, theta = 0.5, 0.5, 0.7
tmp = x1*w1 + x2*w2
if tmp <= theta:
return 0
elif tmp > theta:
return 1
NAND Gate
def NAND(x1, x2):
w1, w2, theta = 0.5, 0.5, 0.7
tmp = x1*w1 + x2*w2
if tmp <= theta:
return 1 ## only change here
elif tmp > theta:
return 0 ## only change here
OR Gate
def OR(x1, x2):
w1, w2, theta = 0.5, 0.5, 0.3 ## only change here
tmp = x1*w1 + x2*w2
if tmp <= theta:
return 0
elif tmp > theta:
return 1
XOR Gate
import pandas as pd
index = 0
xor_df = pd.DataFrame()
for i in range(2):
for j in range(2):
add_df = pd.DataFrame({'x1' : [i], 'x2' : [j], 'XOR(x1,x2)' : [AND(int(NAND(i, j)), int(OR(i,j)))]}, index = [index])
xor_df = xor_df.append(add_df)
index += 1
xor_df