Learn R Programming

FDOTT (version 0.1.0)

is_metric_cost_mat: Check metric properties of cost matrices

Description

Check if a cost matrix satisfies symmetry, positive definiteness and the triangle inequality.

Usage

is_metric_cost_mat(x, tol.sym = 1e-08, tol.pd = 0, tol.ti = 1e-08)

Value

A list containing logical entries metric, semi.metric, sym, pos.def

and tri.ineq that indicate whether the corresponding property is satisfied.

Arguments

x

numeric square matrix.

tol.sym

tolerance used to check symmetry.

tol.pd

tolerance used to check positive definiteness.

tol.ti

tolerance used to check the triangle inequality.

Details

The following three properties of a square matrix \(x \in \mathbb{R}^{N \times N}\) are checked:

  • symmetry; if \(x_{ij} = x_{ji}\),

  • positive definiteness; if \(x_{ii} = 0\) and \(x_{ij} > 0\) for all \(i \neq j\),

  • triangle inequality; if \(x_{ij} \leq x_{ik} + x_{kj}\).

If symmetry and positive definiteness are satisfied, then \(x\) is called a semi-metric cost matrix. If additionally also the triangle inequality holds, then \(x\) is a metric cost matrix.

See Also

cost_matrix_lp

Examples

Run this code
x <- cost_matrix_lp(1:5)
res <- is_metric_cost_mat(x)
res2 <- is_metric_cost_mat(x^2)
# x is a metric cost matrix
print(res$metric)
# x^2 is only a semi-metric cost matrix,
# because the triangle inequality is not satisfied
print(res2$semi.metric)
print(res2$tri.ineq)

Run the code above in your browser using DataLab