minkowski_pairwise_distance#

minkowski_pairwise_distance(X: ndarray, y: ndarray = None, p: float = 2.0, w: ndarray = None) ndarray[source]#

Compute the Minkowski pairwise distance between a set of time series.

Parameters:
Xnp.ndarray

A collection of time series instances, of shape (n_instances, n_channels, n_timepoints) or (n_instances, n_timepoints) or (n_timepoints,).

ynp.ndarray, default=None

A second collection of time series instances, of shape (m_instances, m_channels, m_timepoints) or (m_instances, m_timepoints) or (m_timepoints,). If None, the pairwise distances are calculated within X.

pfloat, default=2.0

The order of the norm of the difference (default is 2.0, which represents the Euclidean distance).

wnp.ndarray, default=None

An array of weights, applied to each pairwise calculation. The weights should match the shape of the time series in X and y.

Returns:
np.ndarray

Minkowski pairwise distance matrix between the instances of X (and y if provided).

Raises:
ValueError

If X (and y if provided) are not 1D, 2D or 3D arrays. If p is less than 1. If w is provided and its shape does not match the instances in X and y.

Examples

>>> import numpy as np
>>> from aeon.distances import minkowski_pairwise_distance
>>> X = np.array([[[1, 2, 3, 4]],[[4, 5, 6, 3]], [[7, 8, 9, 3]]])
>>> minkowski_pairwise_distance(X, p=1)
array([[ 0., 10., 19.],
       [10.,  0.,  9.],
       [19.,  9.,  0.]])
>>> X = np.array([[[1, 2, 3]],[[4, 5, 6]], [[7, 8, 9]]])
>>> y = np.array([[[11, 12, 13]],[[14, 15, 16]], [[17, 18, 19]]])
>>> minkowski_pairwise_distance(X, y,p=2)
array([[17.32050808, 22.5166605 , 27.71281292],
       [12.12435565, 17.32050808, 22.5166605 ],
       [ 6.92820323, 12.12435565, 17.32050808]])
>>> X = np.array([[1, 2, 3], [4, 5, 6]])
>>> y = np.array([[11, 12, 13], [14, 15, 16]])
>>> w = np.array([[21, 22, 23], [24, 25, 26]])
>>> minkowski_pairwise_distance(X, y, p=2, w=w)
array([[ 81.24038405, 105.61249926],
       [ 60.62177826,  86.60254038]])
>>> X = np.array([[[1, 2, 3]],[[4, 5, 6]], [[7, 8, 9]]])
>>> y_univariate = np.array([[11, 12, 13],[14, 15, 16], [17, 18, 19]])
>>> minkowski_pairwise_distance(X, y, p=1)
array([[30.],
       [21.],
       [12.]])