问题
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