Python中的内核方法(kernel methods in Python)
from scipy.spatial.distance import pdist, squareform
X = loaddata() # this is an NxD matrix, where N is number of items and D its dimensions
pairwise_dists = squareform(pdist(X, 'euclidean'))
K = scip.exp(pairwise_dists / s**2)
如果输入是有向图的加权邻接矩阵,那么如何实现上面的Guassin内核?
from scipy.spatial.distance import pdist, squareform
X = loaddata() # this is an NxD matrix, where N is number of items and D its dimensions
pairwise_dists = squareform(pdist(X, 'euclidean'))
K = scip.exp(pairwise_dists / s**2)
How one can implement the above Guassin kernel, if the input is a weighted adjacency matrix for a directed graph?
原文:https://stackoverflow.com/questions/19256082
2019-12-24 05:01
满意答案
如果您已经有距离矩阵,则可以简单地申请
K = scip.exp(YOUR_DISTANCE_HERE / s**2)
但是,它可能不再是内核 。 并非所有“相似性得分”都是有效的内核。 如果您的距离是有效的Mahalanobis距离,那么您有一个保证,一切都会好的。 如果是“任何”距离 - 任何事情都可能发生。
Usinig无效内核可能导致:
优化过程崩溃
找到次优解决方案(不好的解决方案)
做任何事情 ,完全没有保证。
也许你应该考虑与高斯核和热扩散有一定密切相关的
If you already have your distance matrix, you could simply apply
K = scip.exp(YOUR_DISTANCE_HERE / s**2)
However, it may no longer be a kernel. Not all "similarity scores" are valid kernels. If your distances is a valid Mahalanobis distance then you have a guarantee, that everything will be ok. In case of "any" distance - anything can happen.
Usinig invalid kernel may lead to:
Optimization process crash
Finding suboptimal sol