Does the distance matric come from a metric

is_distance_matrix(mat, tolerance = .Machine$double.eps^0.5)

triangle_inequality(mat, tolerance = .Machine$double.eps^0.5)

Arguments

mat

The matrix to evaluate

tolerance

Differences smaller than tolerance are not reported.

Examples

data <- matrix(rnorm(20), ncol = 2) dm <- pdist(data) is_distance_matrix(dm)
#> [1] TRUE
triangle_inequality(dm)
#> [1] TRUE
dm[1, 2] <- 1.1 * dm[1, 2] is_distance_matrix(dm)
#> Matrix is not symmetric.
#> [1] FALSE