-
파이썬 날코딩: XOR 문제ML 2023. 1. 21. 23:13반응형
논리 연산으로..
def AND(x1, x2): return x1 and x2 def NAND(x1, x2): return not (x1 and x2) def OR(x1, x2): return x1 or x2 def XOR(x1, x2): return AND(NAND(x1, x2), OR(x1, x2)) for each in ((False, False), (True, False), (False, True), (True, True)): print(each, XOR(*each))
가중치와 바이어스를 이용해..
def MLP(x1, x2, w, b): if w * x1 + w * x2 + b > 0: return 1 return 0 def AND(x1, x2): return MLP(x1, x2, 1, -1) def NAND(x1, x2): return MLP(x1, x2, -2, 3) def OR(x1, x2): return MLP(x1, x2, 2, -1) def XOR(x1, x2): return AND(NAND(x1, x2), OR(x1, x2)) for each in ((0, 0), (1, 0), (0, 1), (1, 1)): print(each, XOR(*each))
반응형