def constructEucleadianGaussianKernelNoPca(self):
self.pwdis=pairwise_distances(self.allVectors)
maccs=[]
ks=[3,5,7,10,12,15,20,22,25,27,30,33,35,37,40,43,45,47,50,53,55,57,60,65]
for k in ks:
sigmas=[1,1.5,2,2.5,3,3.5]
accs=[]
for sigma in sigmas:
self.pwdis=-1*self.pwdis/(2*sigma*sigma)
self.pwdis=np.exp(self.pwdis)
self.D=np.zeros(self.pwdis.shape)
for i in range(0,self.pwdis.shape[0]):
l1=self.pwdis[i].tolist()
#print 'l1 is ',l1,'\n\n'
allnearestNeighbours=sorted(range(len(l1)),key=lambda i : l1[i])
#now set the all the weights except for k+1 to 0
self.pwdis[i,allnearestNeighbours[k:]]=0
self.D[i,i]=sum(self.pwdis[i])
#here we make no trnasformation on the dataset, as this is simply the
print 'accuracy for constructEucleadianGaussianKernel with k=',k,' and sigma =',sigma,' is \n'
accs.append(self.labelPropogation())
maccs.append(np.mean(accs))
plt.figure()
plt.plot(ks,maccs)
plt.title('Accuarcy vs k for Eucledian Gaussian Kernel')
plt.savefig(pp,format='pdf')
plt.close()
graphssl.py 文件源码
python
阅读 24
收藏 0
点赞 0
评论 0
评论列表
文章目录