Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect total EMD value but correct flow values #32

Open
adam-ah opened this issue Jul 3, 2018 · 3 comments
Open

Incorrect total EMD value but correct flow values #32

adam-ah opened this issue Jul 3, 2018 · 3 comments

Comments

@adam-ah
Copy link

adam-ah commented Jul 3, 2018

When calculating the optimal flow the algorithm is correct but seems like the EMD is a little off from what I would correctly get with flow_matrix * distance_matrix

Distance matrix:

[[2.2360679775e+00 8.7952156412e+03 3.1622776602e+00]
 [8.7964805272e+03 0.0000000000e+00 8.7921069089e+03]
 [0.0000000000e+00 8.7964805272e+03 5.0000000000e+00]]

arr1:

[0.5 0.5 0.0]

arr2:

[0.0 0.5 0.5]
emd =  pyemd.emd_with_flow(arr1, arr2, distance_matrix)
= (1.57896825463524, [[0.0, 0.0, 0.5], [0.0, 0.5, 0.0], [0.0, 0.0, 0.0]])

The final value should be

np.sum(np.multiply(emd[1], distance_matrix))
= 0.5 * 3.1622776602 = 1.5811388301 (=sqrt(2.5))

but instead it is 1.57896825463524 (err=0.002170575465)

Types (distance, arr1, arr2): {dtype} float64
System: Mac OS X, 10.13.4
PIP pyemd: 0.5.1

Seems like too big of an error to be explained by floating point precision. Also, for floating point precision error the calculated flow should be off as well, but that seems to be accurate.

@adam-ah
Copy link
Author

adam-ah commented Jul 3, 2018

@madras380 FYI

@wmayner
Copy link
Owner

wmayner commented Jul 13, 2018

I'm not sure of the cause, but my guess is that it has to do with the iterative min-cost flow algorithm in the underlying C++ library. Unfortunately I don't have time to look into this right now.

Repository owner deleted a comment from cuong369 Jan 14, 2019
@HaidYi
Copy link

HaidYi commented Sep 20, 2021

@adam-ah The value is slightly different is because the definition of emd given in Fast and Robust Earth Mover’s Distances is different from the standard emd distance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants