We are trying to calculate the distance between two discrete 1-d distributions. Our purpose is to compute a distance function that follows the intuition of optimal transport: Our distributions are masses at "points", i.e vectors, with importance to the order of elements in each vector. Given a matrix that describes the distances between any two points, we would like to find the minimal-cost transport in u, in order to make it v.
The simplest example is: Let u,v be the distributions: u=(0.5,0.2,0.3), v=(0.5,0.3,0.2)
Assume that the distances matrix is [[1,1,1],[1,1,1],[1,1,1]], which means it costs 1 to move unit of mass between any two points. obviously, the optimal way to make u look like v is to transport 0.1 from the third point to the second point. The cost in that case will be 1*0.1 which is 0.1.
Following this intuition we turned to the Wasserstein distance. We have tried both scipy.stats.wasserstein_1d and the POT package - in particular ot.emd2. However, none really computes what we want, regarding the example above, the first doesn't consider the order of elements in the vector, so the result is 0. The second algorithm returns 1
We would really appreciate any explanation we might have missed regarding to the operation of this two python functions, or any other references or suggestions.
- We are aware to the fact that given a non symmetric distance metric this notion of "distance" won't be symmetric.
For the case where all weights are 1, Wasserstein distance will yield the measurement you're looking by doing something like the following.
This code treats what you are calling "distributions" as weights over distributions with values
[0,1,2]
. In simple graphical terms, your example distributions look like this in my treatment.