Learn R Programming

FDOTT (version 0.1.0)

ot_barycenter: Compute optimal transport barycenters

Description

Compute the optimal transport (OT) barycenter of multiple probability vectors via linear programming.

Usage

ot_barycenter(
  mu,
  costm,
  w = NULL,
  solver = ot_test_lp_solver(),
  constr_mat = NULL
)

Value

A list containing the entries cost and barycenter.

Arguments

mu

matrix (row-wise) or list containing \(K\) probability vectors of length \(N\).

costm

cost matrix \(c \in \mathbb{R}^{N \times N}\).

w

weight vector \(w \in \mathbb{R}_+^K\). The default is \(w = (1 / K, \ldots, 1 / K)\).

solver

the LP solver to use, see ot_test_lp_solver.

constr_mat

the constraint matrix for the underlying LP.

Details

The OT barycenter is defined as the minimizer of the cost functional, $$ B_c^w(\mu^1, \ldots, \mu^K) := \min_{\nu} \sum_{k=1}^k w_k \, \mathrm{OT}_c(\mu^k, \nu)\,, $$ where the minimum is taken over all probability vectors \(\nu\). The OT barycenter is solved via linear programming (LP) and the underlying solver can be controlled via the parameter solver.

Examples

Run this code

K <- 3
N <- 2
costm <- cost_matrix_lp(1:N)
w <- rep(1 / K, K)

# all measures are equal
mu <- matrix(1 / N, K, N, TRUE)

# to run this, a LP solver must be available for ROI (ROI.plugin.glpk by default)
if (requireNamespace("ROI.plugin.glpk")) {
    solver <- ot_test_lp_solver("glpk")
    print(ot_barycenter(mu, costm, w = w, solver = solver))
}

# not all measures are equal
mu[2, ] <- 1:N / sum(1:N)
if (requireNamespace("ROI.plugin.glpk")) {
    solver <- ot_test_lp_solver("glpk")
    print(ot_barycenter(mu, costm, w = w, solver = solver))
}

Run the code above in your browser using DataLab