Learn R Programming

FDOTT (version 0.1.0)

cost_matrix_lp: Cost Matrix of \(\ell^p\)-Form.

Description

Compute cost matrices of \(\ell^p\)-form.

Usage

cost_matrix_lp(x, y = NULL, p = 2, q = 1)

Value

A \(n \times m\) matrix with entry at \(i, j\) being equal to $$ \lVert x_i - y_j \rVert_p^q = \left[ \sum_{k=1}^d \lvert x_{i,k} - y_{j, k} \rvert^p \right]^{q/p} $$

For p = Inf, this is to be understood as the maximum norm to the power of \(q\).

Arguments

x

matrix of size \(n \times d\) containing vectors \(x_1, \ldots, x_n \in \mathbb{R}^d\) (row-wise).

y

matrix of size \(m \times d\) containing vectors \(y_1, \ldots, y_m \in \mathbb{R}^d\) (row-wise); y = NULL means that \(y_i = x_i\).

p

number \(p \in (0, \infty]\).

q

number \(q \in (0, \infty)\).

Examples

Run this code
n <- 3
m <- 4
d <- 5
x <- runif(n * d) |> matrix(n, d)
y <- runif(m * d) |> matrix(m, d)
costm <- cost_matrix_lp(x, y)
print(costm)

Run the code above in your browser using DataLab