alignment_path

alignment_path(x: ndarray, y: ndarray, method: str | Callable[[ndarray, ndarray, Any], float] | None = None, **kwargs: Unpack[DistanceKwargs]) tuple[list[tuple[int, int]], float][source]

Compute the alignment path and distance between two time series.

Parameters:
xnp.ndarray, of shape (n_channels, n_timepoints) or (n_timepoints,)

First time series.

ynp.ndarray, of shape (m_channels, m_timepoints) or (m_timepoints,)

Second time series.

methodstr or Callable

The distance method to use. A list of valid distances can be found in the documentation for aeon.distances.get_distance_function or by calling the function aeon.distances.get_distance_function_names.

kwargsany

Arguments for distance. Refer to each distance documentation for a list of possible arguments.

Returns:
List[Tuple[int, int]]

The alignment path between the two time series where each element is a tuple of the index in x and the index in y that have the best alignment according to the cost matrix.

float

The dtw distance betweeen the two time series.

Raises:
ValueError

If x and y are not 1D, or 2D arrays. If distance is not one of the supported strings or a callable.

Examples

>>> import numpy as np
>>> from aeon.distances import alignment_path
>>> x = np.array([[1, 2, 3, 6]])
>>> y = np.array([[1, 2, 3, 4]])
>>> alignment_path(x, y, method='dtw')
([(0, 0), (1, 1), (2, 2), (3, 3)], 4.0)