Learn R Programming

gridOT (version 1.0.2)

dual1d: 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)

Value

a list containing the dual vectors pot.a and pot.b.

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 \(\geq 1\) of the cost function.

right.margin

small amount the points are moved by.

sorted

logical value indicating whether or not a and b are sorted.

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.

Examples

Run this code
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)))

Run the code above in your browser using DataLab