#阶跃函数,与门电路
import torch
X = torch.tensor([[1,0,0],[1,1,0],[1,0,1,],[1,1,1]] ,dtype = torch.float32)
andgate = torch.tensor([[0],[0],[0],[1]],dtype = torch.float32)
w = torch.tensor([-0.2,0.15,0.15] ,dtype = torch.float32) # b,w1,w2
def LinearRwithsign(X,w):
zhat = torch.mv(X,w)
andhat = torch.tensor([int(x) for x in zhat>=0],dtype = torch.float32) #int(True)=1,int(False)=0
return zhat,andgate
zhat,andgate = LinearRwithsign(X,w)
print(andgate)
print(andhat)