Given two objects
b that specify distributions of mass and an object that specifies (a way to compute) costs,
find the transport plan for going from
b that minimizes the total cost.
1 2 3 4 5 6 7 8 9 10 11 12 13
transport(a, b, ...) ## Default S3 method: transport(a, b, costm, method = c("shortsimplex", "revsimplex", "primaldual"), control = list(), ...) ## S3 method for class 'pgrid' transport(a, b, p = NULL, method = c("auto", "revsimplex", "shortsimplex", "shielding", "aha", "primaldual"), control = list(), ...) ## S3 method for class 'pp' transport(a, b, p = 1, method = c("auction", "auctionbf", "shortsimplex", "revsimplex", "primaldual"), control = list(), ...) ## S3 method for class 'wpp' transport(a, b, p = 1, method = c("revsimplex", "shortsimplex", "primaldual"), control = list(), ...)
two objects that describe mass distributions, between which the optimal transport map is to be computed. For the default
method these are vectors of non-negative values. For the other three methods these are objects of the respective classes.
It is also possible to have
for the default method a
for the three specialized methods the power >=1 to which the Euclidean distance between points is taken in order to compute costs.
the name of the algorithm to use. See details below.
a named list of parameters for the chosen method or the result of a call to
currently without effect.
There is a number of algorithms that are currently implemented and more will be added in future versions of the package. The following is a brief description of each key word used. Much more details can be found in the cited references and in a forthcoming package vignette.
aha: The Aurenhammer–Hoffmann–Aronov (1998) method with the multiscale approach presented in Mérigot (2011).
auction: The auction algorithm by Bertsekas (1988) with epsilon-scaling, see Bertsekas (1992).
auctionbf: A refined auction algorithm that combines forward and revers auction, see Bertsekas (1992).
primaldual: The primal-dual algorithm as described in Luenberger (2003, Section 5.9).
revsimplex: The revised simplex algorithm as described in Luenberger and Ye (2008, Section 6.4) with various speed improvements, including a multiscale approach.
shielding: The shielding (or shortcut) method, as described in Schmitzer (2016).
shortsimplex: The shortlist method based an a revised simplex algorithm, as described in Gottschlich and Schuhmacher (2014).
The order of the default key words specified for the argument
method gives a rough idea of the relative efficiency of the algorithms for the corresponding class of objects. For a given
b the actual computation times may deviate significantly from this order.
pgrid the default method is
"auto", which resolves to
p is not 2 or the problem is very small, and to
The following table gives information about the applicability of the various algorithms (or sometimes rather their current implementations).
where: + recommended, * applicable (may be slow), - no implementation planned or combination does not make sense; @ indicates that the aha algorithm is available in the special combination where
a is a
pgrid object and
b is a
wpp object (and
p is 2). For more details on this combination see the function
Each algorithm has certain parameters supplied by the
control argument. The following table gives an overview of parameter names and
| ||multiscale||individual parameters|
start specifies the algorithm for computing a starting solution (if needed). Currently the Modified Row Minimum Rule
start="modrowmin"), the North-West Corner Rule (
start="nwcorner") and the method by Russell (1969) (
are implemented. When
start="auto" (the default) the ModRowMin Rule is chosen. However,
p larger than 1, there are two cases where an automatic multiscale procedure is also performed, i.e. the optimal transport is first computed on coarser grids and information from these solutions is then used for the finer girds.
This happens for
method = "revsimplex", where a single coarsening at factor
scmult=2 is performed, and for
method = "shielding", where a number of coarsenings adapted to the dimensions of the array is performed.
method="revsimplex", as well as
method="aha" there are multiscale versions of
the corresponding algorithms that allows for finer control via the parameters
returncoarse. The default value of
the multiscale version. For larger problems it is advisable to use the multiscale version, which currently is only implemented for
square pgrids in two dimensions. The algorithm proceeds then by coarsening the pgrid
nscales-1 times, summarizing
scmult^2 pixels into one larger pixels, and then solving the various transport problems starting from the coarsest and
using each previous problem to compute a starting solution to the next finer problem. If
TRUE, the coarser
problems and their solutions are returned as well (
maxit are the corresponding components of the
control argument in the
optim L-BFGS-B method.
epsfac are parameters used for epsilon scaling in the auction algortihm. The algorithm starts with a “transaction cost” per bid of
epsfac^k * lasteps for some reasonable
k generating finer and finer approximate solutions as the
k counts down to zero. Note that in order for the procedure to make sense,
epsfac should be larger than one (typically two- to three-digit) and in order for the final solution to be exact
lasteps should be smaller than
n is the total number of points in either of the point patterns.
psearched are the shortlist length, the number of pivot candidates needed, and the percentage of
shortlists searched, respectively.
A data frame with columns
mass that specifies from which element of
a to which element of
b what amount of mass is sent in the optimal transport plan. For class
pgrid elements are specified as vector indices in terms of the usual column major enumeration of the matrices
b$mass. There are
plot methods for the classes
pp, which can plot this solution.
TRUE for the
revsimplex method, a list with components
prob giving the solutions and problems on the various scales considered. The solution on the finest scale (i.e. the output we obtain when setting
FALSE) is in
a is of class
b of class
p=2), an object of class
power_diagram as described in the help for the function
plot method for class
pgrid can plot this solution.
The combination of the shielding-method with the CPLEX numerical solver outperforms the other algorithms by an order of magnitude for large problems (only applicable for
p=2 and objects of class
"pgrid"). If a local installation of CPLEX is available, the transport package can be linked against it during installation. See the file src/Makevars in the source package for instructions.
Dominic Schuhmacher [email protected]
Björn Bähre [email protected]
Carsten Gottschlich [email protected]
(original java code for
Bernhard Schmitzer [email protected]
F. Aurenhammer, F. Hoffmann and B. Aronov (1998). Minkowski-type theorems and least-squares clustering. Algorithmica 20(1), 61–76.
D. P. Bertsekas (1988). The auction algorithm: a distributed relaxation method for the assignment problem. Annals of Operations Research 14(1), 105–123.
D. P. Bertsekas (1992). Auction algorithms for network flow problems: a tutorial introduction. Computational Optimization and Applications 1, 7–66.
C. Gottschlich and D. Schuhmacher (2014). The shortlist method for fast computation of the earth mover's distance and finding optimal solutions to transportation problems. PLOS ONE 9(10), e110214. doi:10.1371/journal.pone.0110214
D.G. Luenberger (2003). Linear and nonlinear programming, 2nd ed. Kluwer.
D.G. Luenberger and Y. Ye (2008). Linear and nonlinear programming, 3rd ed. Springer.
Q. Mérigot (2011). A multiscale approach to optimal transport. Computer Graphics Forum 30(5), 1583–1592. doi:10.1111/j.1467-8659.2011.02032.x
B. Schmitzer (2016). A sparse multiscale algorithm for dense optimal transport. J. Math. Imaging Vision 56(2), 238–259. https://arxiv.org/abs/1510.05466
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
# # example for the default method # a <- c(100, 200, 80, 150, 50, 140, 170, 30, 10, 70) b <- c(60, 120, 150, 110, 40, 90, 160, 120, 70, 80) set.seed(24) costm <- matrix(sample(1:20, 100, replace=TRUE), 10, 10) res <- transport(a,b,costm) # pretty-print solution in matrix form for very small problems: transp <- matrix(0,10,10) transp[cbind(res$from,res$to)] <- res$mass rownames(transp) <- paste(ifelse(nchar(a)==2," ",""),a,sep="") colnames(transp) <- paste(ifelse(nchar(b)==2," ",""),b,sep="") print(transp) # # example for class 'pgrid' # dev.new(width=9, height=4.5) par(mfrow=c(1,2), mai=rep(0.1,4)) image(random32a$mass, col = grey(0:200/200), axes=FALSE) image(random32b$mass, col = grey(0:200/200), axes=FALSE) res <- transport(random32a,random32b) dev.new() par(mai=rep(0,4)) plot(random32a,random32b,res,lwd=1) # # example for class 'pp' # set.seed(27) x <- pp(matrix(runif(400),200,2)) y <- pp(matrix(runif(400),200,2)) res <- transport(x,y) dev.new() par(mai=rep(0.02,4)) plot(x,y,res) # # example for class 'wpp' # set.seed(30) m <- 30 n <- 60 massx <- rexp(m) massx <- massx/sum(massx) massy <- rexp(n) massy <- massy/sum(massy) x <- wpp(matrix(runif(2*m),m,2),massx) y <- wpp(matrix(runif(2*n),n,2),massy) res <- transport(x,y,method="revsimplex") plot(x,y,res) # # example for semidiscrete transport between class 'pgrid' and class 'wpp' # set.seed(33) n <- 100 massb <- rexp(n) massb <- massb/sum(massb)*1e5 b <- wpp(matrix(runif(2*n),n,2),massb) res <- transport(random32a,b,p=2) plot(random32a,b,res)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.