Advertisement
Guest User

Untitled

a guest
Mar 24th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. X = np.asarray([[2.5, 2.5], [4, -1], [1, -4], [-3, 1.25], [-2, -4], [1, 5]]) #TOY DATASET
  2. Y = [1, 1, 1, 0, 0, 0]
  3.  
  4. my_cmap = matplotlib.colors.LinearSegmentedColormap.from_list("", ["red","yellow","green"]) #for the contourf plot
  5. sn=SigmoidNeuron() # object of class
  6.  
  7. def plot_sn(X,Y,sn,ax,wbb): # Creates contourf plot for the current value of "w" and "b"
  8. X1=np.linspace(-10,10,100)
  9. X2=np.linspace(-10,10,100)
  10. XX1,XX2=np.meshgrid(X1,X2)
  11. YY=np.zeros(XX1.shape)
  12. for i in range(X2.size):
  13. for j in range(X1.size):
  14. YY[i,j]=sn.sigmoid(sn.perceptron(np.asarray([X1[j],X2[i]])))
  15. ax.contourf(XX1,XX2,YY,cmap=my_cmap,alpha=0.6)
  16. ax.scatter(X[:,0],X[:,1],c=Y,cmap=my_cmap)
  17. ax.plot()
  18.  
  19.  
  20.  
  21.  
  22. plt.figure(figsize=(10,20*6*5)) # initialize plot size
  23. sn.fit([2.5,2.5],1,1,1,True,False)
  24. ci=0
  25. wbb=[]
  26. for i in range(20):
  27. #ci=0
  28. for (x,y) in zip(X,Y):
  29. ci+=1
  30. ax=plt.subplot(20*6,1,ci)
  31. sn.fit(x,y,1,0.7,False,False)
  32. plot_sn(X,Y,sn,ax,wbb)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement