import torch
X = torch.tensor([[1,0,0],[1,1,0],[1,0,1,],[1,1,1]] ,dtype = torch.float32)
orgate = torch.tensor([[0],[1],[1],[1]],dtype = torch.float32)
w = torch.tensor([-0.5,1,1] ,dtype = torch.float32)
def orAdd(X,w):
zhat = torch.mv(X,w)
orhat = torch.tensor([int(x) for x in zhat>=0],dtype = torch.float32)
return zhat,nandhat
zhat,orhat = orAdd(X,w)
print(zhat)
print(orhat)
import matplotlib.pyplot as plt
import seaborn as sns
plt.style.use('seaborn-whitegrid')
sns.set_style("white")
plt.figure(figsize=(5,3))
plt.title("OR GATE",fontsize=16)
plt.scatter(X[:,1],X[:,2],c=orgate,cmap="rainbow")
plt.xlim(-1,3)
plt.ylim(-1,3)
plt.grid(alpha=.4,axis="y")
plt.gca().spines["top"].set_alpha(.0)
plt.gca().spines["right"].set_alpha(.0);
import numpy as np
x = np.arange(-1,3,0.5)
plt.plot(x,0.5-x ,color="k",linestyle="--");