【无标题】

单层的神经网络

import torch
import numpy as np


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)
def LogisticR(X,w):
    
    zhat = torch.mv(X,w)
    sigma = 1/(1+torch.exp(-zhat))
    #sigma = torch.sigmoid(zhat) #等效于上一行代码
    andhat = torch.tensor([int(x) for x in sigma >=0.5],dtype = torch.float32)
    return sigma,andhat

sigma,andhat = LogisticR(X,w)
  
print(sigma)
print(andhat)

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