| transport_df.numeric {gridOT} | R Documentation |
Optimal Transport Plan
Description
Calculate the optimal transport plan.
Usage
## S3 method for class 'numeric'
transport_df(x, y, threshold = 1e-15, ...)
transport_df(x, ...)
## S3 method for class 'otgridtransport'
transport_df(x, ...)
## S3 method for class 'otgrid'
transport_df(x, ...)
Arguments
x |
a vector of weights, an object of class |
y |
second weight vector. |
threshold |
small value that indicates when a value is considered to be zero. |
... |
further arguments (for |
Details
In case of two-dimensional grids, the pivot measure is used to calculate the optimal transport plan.
For one-dimensional optimal transport, we assume that the optimal transport plan is the monotone plan. For example, this is the case
for costs of the form c(x, y) = | x - y |^p for some p \geq 1.
In this case, the north-west-corner algorithm is used.
Value
a data frame representing the optimal transport plan. It has columns from, to and mass that specify
between which points of the two grids how much mass is transported.
In the two-dimensional case, a point is given by the index in column-mayor format and the data frame is actually stored in the element
df of an object of class "otgridtransport".
See Also
pivot measure pivot_measure
Examples
## one-dimensional example
set.seed(1)
wa <- rep(1/5, 5)
wb <- runif(6)
wb <- wb / sum(wb)
transport_df(wa, wb)
## two-dimensional example
x <- otgrid(cbind(0:1, 1:0))
y <- otgrid(cbind(1:0, 0:1))
# first calculate pivot manually
pm <- pivot_measure(x, y)
pm <- transport_df(pm)
# or just
pm2 <- transport_df(x, y)