dual1d {gridOT} | R Documentation |
Dual Solution of one-dimensional Optimal Transport
Description
Calculate an optimal dual pair for the optimal transport between discrete one-dimensional measures.
Usage
dual1d(a, b, wa, wb, p = 1, right.margin = 1e-15, sorted = FALSE)
Arguments
a |
first vector of points. |
b |
second vector of points. |
wa |
weight vector of the first vector of points. |
wb |
weight vector of the second vector of points. |
p |
the power |
right.margin |
small amount the points are moved by. |
sorted |
logical value indicating whether or not |
Details
The pair f, g
is an optimal dual pair if the optimal transport distance between the two distributions
with respect to the cost function c(x, y) = | x - y |^p
is given by
\langle f, w_a \rangle + \langle g, w_b \rangle
and the condition f_i + g_j \leq | a_i - b_j |^p
holds.
Value
a list containing the dual vectors pot.a
and pot.b
.
Examples
set.seed(1)
a <- 1:5
wa <- rep(1/5, 5)
b <- 1:6
wb <- runif(6)
wb <- wb / sum(wb)
d <- dual1d(a, b, wa, wb, p = 1)
dc <- sum(d$pot.a * wa) + sum(d$pot.b * wb)
print(all.equal(dc, transport_cost(a, b, wa, wb, p = 1)))
[Package gridOT version 1.0.1 Index]