rearth-movers-distance

transport unbalanced does not work when output="all"


I want to compute the transport costs to transport one distribution of mass to another (in the fashion of earth mover distance). I want to use an unbalanced transport. I use the transport library and it works when I want only the distance, however when I want to get the transport plan I get strange errors. Let me give you an example:

m1 <- matrix(c(1,0,0,0),nrow = 2,ncol = 2)
m2 <- matrix(c(0,0,0,1),nrow = 2,ncol = 2)
a <- transport::pgrid(m1)
b <- transport::pgrid(m2)
transport::unbalanced(a,b,output = "dist")
transport::unbalanced(a,b,output = "all")

The first call of unbalanced returns 0.7071068, so it seems to work. However the second call gives

Error in rowSums(temp[1:m, ]) : 
  'x' muss ein Array mit mindestens zwei Dimensionen sein
//english: 'x' has to be an array of at least two dimensions

What does this mean? How can I access the transport plan?


Solution

  • This is a bug in the transport package that occurs if all but a single entry of one of the pgrids is zero. It should be fixed in the new version 0.14-1 that is on its way to CRAN now.