How to extract the distance and transport matrices from Scipy's wasserstein_distance?

戏子无情 提交于 2021-02-11 14:28:16

问题


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?


回答1:


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.

Then the distance matrix is an input of the EMD calculation, not an output.



来源:https://stackoverflow.com/questions/65131318/how-to-extract-the-distance-and-transport-matrices-from-scipys-wasserstein-dist

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