问题描述
我有一个矩阵,表示到一组点的k个近邻的距离,并且有一个最近邻居的类别标签矩阵. (都是N-k矩阵)
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)
在theano中构建(N-by-#classes)矩阵的最佳方法是什么,该矩阵的(i,j)元素将是从第i个点到其带有类标签的k-NN个点的距离之和'j'?
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'?
示例:
# 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]]
这个任务在theano吗?
this task in theano?
K = theano.tensor.matrix()
l = theano.tensor.matrix()
result = <..some code..>
f = theano.function(inputs=[K,l], outputs=result)
推荐答案
看看这个仓库可能会很有趣: https://github.com/erogol/KLP_KMEANS/blob/master/klp_kmeans.py
You might be interesting in having a look to this repo: https://github.com/erogol/KLP_KMEANS/blob/master/klp_kmeans.py
是使用theano(func kpl_kmeans
)的K-Means实现.我相信您想要的是函数find_bmu
中使用的矩阵W
.
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
.
希望您发现它有用.
这篇关于theano:按类标签求和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!