get_cost_matrix_function

get_cost_matrix_function(metric: str) Callable[[ndarray, ndarray, Any], ndarray][source]

Get the cost matrix function for a given metric string or callable.

metric

Distance Function

‘dtw’

distances.dtw_cost_matrix

‘shape_dtw’

distances.shape_dtw_cost_matrix

‘ddtw’

distances.ddtw_cost_matrix

‘wdtw’

distances.wdtw_cost_matrix

‘wddtw’

distances.wddtw_cost_matrix

‘adtw’

distances.adtw_cost_matrix

‘erp’

distances.erp_cost_matrix

‘edr’

distances.edr_cost_matrix

‘msm’

distances.msm_cost_matrix

‘twe’

distances.twe_cost_matrix

‘lcss’

distances.lcss_cost_matrix

Parameters:
metricstr or Callable

The metric string to resolve to a cost matrix function.

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

The cost matrix function for the given metric.

Raises:
ValueError

If metric is not one of the supported strings or a callable. If the metric doesn’t have a cost matrix function.

Examples

>>> from aeon.distances import get_cost_matrix_function
>>> import numpy as np
>>> x = np.array([[1, 2, 3, 4, 5]])
>>> y = np.array([[11, 12, 13, 14, 15]])
>>> dtw_cost_matrix_func = get_cost_matrix_function("dtw")
>>> dtw_cost_matrix_func(x, y, window=0.2)
array([[100., 221.,  inf,  inf,  inf],
       [181., 200., 321.,  inf,  inf],
       [ inf, 262., 300., 421.,  inf],
       [ inf,  inf, 343., 400., 521.],
       [ inf,  inf,  inf, 424., 500.]])