get_distance_function

get_distance_function(metric: str | Callable[[ndarray, ndarray, Any], float]) Callable[[ndarray, ndarray, Any], float][source]

Get the distance function for a given metric string or callable.

metric

Distance Function

‘dtw’

distances.dtw_distance

‘shape_dtw’

distances.shape_dtw_distance

‘ddtw’

distances.ddtw_distance

‘wdtw’

distances.wdtw_distance

‘wddtw’

distances.wddtw_distance

‘adtw’

distances.adtw_distance

‘erp’

distances.erp_distance

‘edr’

distances.edr_distance

‘msm’

distances.msm_distance

‘twe’

distances.twe_distance

‘lcss’

distances.lcss_distance

‘euclidean’

distances.euclidean_distance

‘squared’

distances.squared_distance

‘manhattan’

distances.manhattan_distance

‘minkowski’

distances.minkowski_distance

‘sbd’

distances.sbd_distance

Parameters:
metricstr or Callable

The distance metric to use. If string given then it will be resolved to a alignment path function. If a callable is given, the value must be a function that accepts two numpy arrays and **kwargs returns a float.

Returns:
Callable[[np.ndarray, np.ndarray, Any], float]

The distance function for the given metric.

Raises:
ValueError

If metric is not one of the supported strings or a callable.

Examples

>>> from aeon.distances import get_distance_function
>>> import numpy as np
>>> x = np.array([[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]])
>>> y = np.array([[11, 12, 13, 14, 15, 16, 17, 18, 19, 20]])
>>> dtw_dist_func = get_distance_function("dtw")
>>> dtw_dist_func(x, y, window=0.2)
874.0