Pytorch sigmoid函数,与门电路

#sigmoid函数,与门电路
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 LogisticR(X,w):
    zhat = torch.mv(X,w)
    sigam = torch.sigmoid(zhat)
    #sigam = 1/(1+torch.exp(-zhat))
    andhat = torch.tensor([int(x) for x in sigam>=0.5],dtype = torch.float32)  #int(True)=1,int(False)=0
    return sigam,andgate
sigam,andhat = LogisticR(X,w)
print(sigam)
print(andgate)
print(andhat)

你可能感兴趣的:(深度学习)