The built-ins cover level and shape; anything else – dynamic time warping, a domain-specific dissimilarity, a precomputed matrix – is registered here and then usable by name everywhere in the package.

register_scale_distance(name, fn)

get_scale_distance(name)

list_scale_distances()

clear_scale_distances(names = NULL)

Arguments

name

Name to register under.

fn

A function of the unit-by-feature matrix returning a stats::dist object (or a square matrix) over its rows.

names

Distances to remove; NULL clears every registered one. Built-ins cannot be removed.

Value

Invisibly, name.

Examples

register_scale_distance("first_diff", function(m) {
  stats::dist(t(apply(m, 1, diff)))
})
"first_diff" %in% list_scale_distances()
#> [1] TRUE
clear_scale_distances("first_diff")