theano: summation by class label

你离开我真会死。 提交于 2019-12-13 06:13:13

问题


I have a matrix which represents a distances to the k-nearest neighbour of a set of points, and there is a matrix of class labels of the nearest neighbours. (both N-by-k matrix)

What is the best way in theano to build a (N-by-#classes) matrix whose (i,j) element will be the sum of distances from i-th point to its k-NN points with the class label 'j'?

Example:

# N = 2
# k = 5
# number of classes = 3

K_val  = [[1,2,3,4,6],
          [2,4,5,5,7]]

l_val  = [[0,1,2,0,1],
          [2,0,1,2,0]]

result = [[5,8,3],
          [11,5,7]]

this task in theano?

K = theano.tensor.matrix()
l = theano.tensor.matrix()
result = <..some code..>

f = theano.function(inputs=[K,l], outputs=result)

回答1:


You might be interesting in having a look to this repo: https://github.com/erogol/KLP_KMEANS/blob/master/klp_kmeans.py

Is a K-Means implementation using theano (func kpl_kmeans). I believe what you want is the matrix W used in the function find_bmu.

Hope you find it useful.



来源:https://stackoverflow.com/questions/27600893/theano-summation-by-class-label

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!