如何从 Scipy 的 wasserstein_distance 中提取距离和传输矩阵? [英] How to extract the distance and transport matrices from Scipy's wasserstein_distance?
问题描述
scipy.stats.wasserstein_distance
函数只返回两个输入分布之间的最小距离(解),p
和 q
.但该距离是距离矩阵和必须在同一函数内计算的最佳传输矩阵的乘积的结果.
The scipy.stats.wasserstein_distance
function only returns the minimum distance (the solution) between two input distributions, p
and q
. But that distance is the result of the product of a distance matrix and an optimal transport matrix that must have been computed inside the same function.
如何提取与解决方案对应的距离矩阵和最优传输矩阵作为第二和第三个输出参数?
How can I extract the distance matrix and optimal transport matrix that correspond to the solution as 2nd and 3rd output arguments?
推荐答案
似乎无法从 scipy 的 wasserstein_distance 中获得计算出的传输矩阵.不过,您可以通过其他软件包获取它,例如 https://github.com/wmayner/pyemd.我已经使用这个包有一段时间了,它工作得很好,同时执行速度也非常快.查看用法部分中的函数 emd_with_flow().
It does not seem that you can get the calculated transport matrix from scipy's wasserstein_distance. You can get it via other packages though, like https://github.com/wmayner/pyemd. I have been using this package for a while and it works pretty fine, while also executing very quickly. Look into the function emd_with_flow() within section Usage.
那么距离矩阵是 EMD 计算的输入,而不是输出.
Then the distance matrix is an input of the EMD calculation, not an output.
这篇关于如何从 Scipy 的 wasserstein_distance 中提取距离和传输矩阵?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!