Skip to main content
deleted 21 characters in body
Source Link
User1865345
  • 10.3k
  • 12
  • 23
  • 40

It seems that the Earth Mover's Distance does exactly what you want. It moves all data ("dirt") from the first vector into the second such that the amount of dirt moved times the dsitance is minimal.

Applying its R implementation on your data yields (the first column in the data represents the value, the second the spatial location, which is the index in your case):

> library(emdist)
> A <- cbind(c(1,5,0,0,0,0,1),1:7)
> B <- cbind(c(1,0,4,0,0,1,0),1:7)
> C <- cbind(c(1,0,0,1,5,0,0),1:7)
> emd(A,B)
[1] 0.8333333
> emd(A,C)
[1] 2.285714
> library(emdist)
> A <- cbind(c(1,5,0,0,0,0,1),1:7)
> B <- cbind(c(1,0,4,0,0,1,0),1:7)
> C <- cbind(c(1,0,0,1,5,0,0),1:7)
> emd(A,B)
[1] 0.8333333
> emd(A,C)
[1] 2.285714

It seems that the Earth Mover's Distance does exactly what you want. It moves all data ("dirt") from the first vector into the second such that the amount of dirt moved times the dsitance is minimal.

Applying its R implementation on your data yields (the first column in the data represents the value, the second the spatial location, which is the index in your case):

> library(emdist)
> A <- cbind(c(1,5,0,0,0,0,1),1:7)
> B <- cbind(c(1,0,4,0,0,1,0),1:7)
> C <- cbind(c(1,0,0,1,5,0,0),1:7)
> emd(A,B)
[1] 0.8333333
> emd(A,C)
[1] 2.285714

It seems that the Earth Mover's Distance does exactly what you want. It moves all data ("dirt") from the first vector into the second such that the amount of dirt moved times the dsitance is minimal.

Applying its R implementation on your data yields (the first column in the data represents the value, the second the spatial location, which is the index in your case):

> library(emdist)
> A <- cbind(c(1,5,0,0,0,0,1),1:7)
> B <- cbind(c(1,0,4,0,0,1,0),1:7)
> C <- cbind(c(1,0,0,1,5,0,0),1:7)
> emd(A,B)
[1] 0.8333333
> emd(A,C)
[1] 2.285714
Source Link
cdalitz
  • 5.7k
  • 2
  • 16
  • 31

It seems that the Earth Mover's Distance does exactly what you want. It moves all data ("dirt") from the first vector into the second such that the amount of dirt moved times the dsitance is minimal.

Applying its R implementation on your data yields (the first column in the data represents the value, the second the spatial location, which is the index in your case):

> library(emdist)
> A <- cbind(c(1,5,0,0,0,0,1),1:7)
> B <- cbind(c(1,0,4,0,0,1,0),1:7)
> C <- cbind(c(1,0,0,1,5,0,0),1:7)
> emd(A,B)
[1] 0.8333333
> emd(A,C)
[1] 2.285714