powered by
Compute cost matrices of \(\ell^p\)-form.
cost_matrix_lp(x, y = NULL, p = 2, q = 1)
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\).
p = Inf
matrix of size \(n \times d\) containing vectors \(x_1, \ldots, x_n \in \mathbb{R}^d\) (row-wise).
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\).
y = NULL
number \(p \in (0, \infty]\).
number \(q \in (0, \infty)\).
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