def XOR(x1, x2): # 第1層 s1 = NAND(x1, x2) s2 = OR(x1, x2) # 第2層 y = AND(s1, s2) # 出力 return y
def XOR(x1, x2): """ x1 x2 | y ---------- 0 0 | 0 0 1 | 1 1 0 | 1 1 1 | 0 """ s1 = NAND(x1, x2) s2 = OR(x1, x2) y = AND(s1, s2) return y
def XOR(x1, x2): s1 = NOR(x1, x2) s2 = AND(x1, x2) y = OR(s1, s2) return y
def XOR(x1, x2): s1 = NAND(x1, x2) s2 = OR(x1, x2) return AND(s1, s2)
import numpy as np 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 if __name__ == '__main__': for xs in [(0, 0), (1, 0), (0, 1), (1, 1)]: y = OR(xs[0], xs[1]) print(str(xs) + " -> " + str(y)) ########################################################### # coding: utf-8 from and_gate import AND from or_gate import OR from nand_gate import NAND def XOR(x1, x2): s1 = NAND(x1, x2) s2 = OR(x1, x2)
def XOR(x1, x2): s1 = NAND(x1, x2) s2 = OR(x1, x2) y = AND(s1, s2)##至少有一个,且不相同,就是异或 return y
def XOR(x1, x2): s1 = OR(x1, x2) s2 = NAND(x1, x2) y = AND(s1, s2) return y
def XOR(x, y): bynary = [0, 1] if not (x in bynary and y in bynary): raise ValueError('Invalid arguments. x and y must be 0 or 1.') return OR(AND(x, NOT(y)), AND(NOT(x), y))
def XOR(x1, x2): """returns x1 XOR x2""" s1 = NAND(x1, x2) s2 = OR(x1, x2) return AND(s1, s2)
def XOR(x1, x2): # multi-layer perceptron s1 = NAND(x1, x2) # layer 1 s2 = OR(x1, x2) # layer 1 y = AND(s1, s2) # layer 2 return y