論理ゲートをPythonで

ANDゲート、NANDゲート、ORゲートをpythonのクラスで書いてみた〜(XORゲートは、うまく行かず。出力エラーになってしまう)

import numpy as np

class Logic_gate:
    def __init__(self,x1,x2):
        self.x1=x1
        self.x2=x2
        
    def AND(self):
        x=np.array([self.x1,self.x2])
        w=np.array([0.5,0.5])
        b=-0.5
        y=np.sum(x*w)+b
        if y<=0:
            return 0
        else:
            return 1
    
    def NAND(self):
        x=np.array([self.x1,self.x2])
        w=np.array([-0.6,-0.6])
        b=0.8
        y=np.sum(x*w)+b
        if y<=0:
            return 0
        else:
            return 1
    
    def OR(self):
        x=np.array([self.x1,self.x2])
        w=np.array([0.5,0.5])
        b=-0.3
        y=np.sum(x*w)+b
        if y<=0:
            return 0
        else:
            return 1
    
    def XOR(self):
        s1=NAND(self.x1,self.x2)
        s2= OR(self.x1,self.x2)
        y=AND(s1,s2)
        return y
#AND回路の出力

resAND= Logic_gate(0,0)
resAND.AND()
0

resAND= Logic_gate(1,0)
resAND.AND()
0

resAND= Logic_gate(0,1)
resAND.AND()
0

resAND= Logic_gate(1,1)
resAND.AND()
1
#NAND回路の出力

resNAND= Logic_gate(0,0)
resNAND.NAND()
1

resNAND= Logic_gate(1,0)
resNAND.NAND()
1

resNAND= Logic_gate(0,1)
resNAND.NAND()
1

resNAND= Logic_gate(1,1)
resNAND.NAND()
0
#OR回路の出力

resOR=Logic_gate(0,0)
resOR.OR()
0

resOR=Logic_gate(1,0)
resOR.OR()
1

resOR=Logic_gate(0,1)
resOR.OR()
1

resOR=Logic_gate(1,1)
resOR.OR()
1

参考:「ゼロから作るDeepLearning」(斎藤康毅/オライリー・ジャパン)