dual1d | R Documentation |
Calculate an optimal dual pair for the optimal transport between discrete one-dimensional measures.
dual1d(a, b, wa, wb, p = 1, right.margin = 1e-15, sorted = FALSE)
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 ≥q 1 of the cost function. |
right.margin |
small amount the points are moved by. |
sorted |
logical value indicating whether or not |
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 ≤q | a_i - b_j |^p holds.
a list containing the dual vectors pot.a
and pot.b
.
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)))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.