transport_df.numeric | R Documentation |
Calculate the optimal transport plan.
## 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, ...)
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 |
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 ≥q 1. In this case, the north-west-corner algorithm is used.
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"
.
pivot measure pivot_measure
## 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.