def getAccRel(sim,dst):
# for how many is the most similar one also the one with the smallest dst
# relaxed formulation: of the most similar ones (if more than one is equally similar) one is among those with smallest dst (if more than one is equally far away)
maxSim = numpy.max(sim, axis=1)
minDst = numpy.min(dst, axis=1)
nSamp = sim.shape[0]
nCorrect = 0.
nCorrectClass = 0.
for i in xrange(nSamp):
maxSimIdx, = (sim[i,:] == maxSim[i]).nonzero()
minDstIdx, = (dst[i,:] == minDst[i]).nonzero()
if len(numpy.intersect1d(maxSimIdx,minDstIdx, assume_unique=True)) > 0:
nCorrect += 1.
if numpy.min(sim[i,minDstIdx]) > -2.:
nCorrectClass += 1.
acc = nCorrect / nSamp
# classification accuracy. for how many percent is the closest from the correct class
classAcc = nCorrectClass / nSamp
return (acc,classAcc)
评论列表
文章目录