M.L code(p.53)
|
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 44 45 |
# p51 ~ p59 import numpy as np import matplotlib.pyplot as plt 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 elif tmp > 0: 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 elif tmp > 0: return 1 def OR(x1,x2): x = np.array([x1,x2]) w = np.array([0.5,0.5]) b = -0.3 tmp = np.sum(w*x) + b if tmp <= 0: return 0 elif tmp > 0: return 1 def XOR(x1,x2): s1 = NAND(x1,x2) s2 = OR(x1,x2) y = AND(s1,s2) return y print(XOR(0,0)) print(XOR(1,0)) print(XOR(0,1)) print(XOR(1,1)) |
단층 퍼셉트론과 다층 퍼셉트론 (XOR 연산자)