#囚徒 4.0_12
import numpy as np
def AND(x1,x2):
x=np.array([x1,x2])
w=np.array([0.5,0.5])
b=-0.7
temp=np.sum(x*w)+b
if temp>0:
return 1
else:
return 0
def OR(x1,x2):
x=np.array([x1,x2])
w=np.array([1,1])
b=-0.5
temp=np.sum(x*w)+b
if temp>0:
return 1
else:
return 0
def NAND(x1,x2):
x=np.array([x1,x2])
w=np.array([-0.5,-0.5])
b=0.7
temp=np.sum(x*w)+b
if temp>0:
return 1
else:
return 0
def XOR(x1,x2):
x=np.array([x1,x2])
w1=np.array([-0.5,-0.5])
w2=np.array([1,1])
w3=np.array([0.5,0.5])
b1=0.7
b2=-0.7
b3=-0.7
s1=np.sum(x*w1)+b1
s2=np.sum(x*w2)+b2
print("S1(0,1) {} : S2(1,0) {}".format(s1,s2))
if s1>0:
s1=1
else:
s1=0
if s2>0:
s2=1
else:
s2=0
X=np.array([s1,s2])
temp=np.sum(X*w3)+b3
if temp>0:
return 1
else:
return 0
def XOR_info(x1,x2):
s1=NAND(x1,x2)
s2=OR(x1,x2)
return AND(s1,s2)
x1=0
x2=0
y=XOR(x1,x2)
y_info=XOR_info(x1,x2)
print("y {}: f_info {}".format(y,y_info))
标签:12,return,4.0,0.5,x2,np,array,x1,囚徒
From: https://www.cnblogs.com/qt-pyq/p/17841001.html