【发布时间】:2019-12-25 00:28:54
【问题描述】:
我想计算两个 2D 阵列(这些不是图像)之间的 Earth Mover 距离。
现在我浏览了两个库:scipy (https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.wasserstein_distance.html) 和 pyemd (https://pypi.org/project/pyemd/)。
#define a sampeling method
def sampeling2D(n, mu1, std1, mu2, std2):
#sample from N(0, 1) in the 2D hyperspace
x = np.random.randn(n, 2)
#scale N(0, 1) -> N(mu, std)
x[:,0] = (x[:,0]*std1) + mu1
x[:,1] = (x[:,1]*std2) + mu2
return x
#generate two sets
Y1 = sampeling2D(1000, 0, 1, 0, 1)
Y2 = sampeling2D(1000, -1, 1, -1, 1)
#compute the distance
distance = pyemd.emd_samples(Y1, Y2)
虽然 scipy 版本不接受 2D 数组并返回错误,但 pyemd 方法返回一个值。如果您从文档中看到,它说它只接受一维数组,所以我认为输出是错误的。在这种情况下如何计算这个距离?
【问题讨论】:
标签: python scipy statistics distribution earth-movers-distance