minkowski_distance

minkowski_distance(x: ndarray, y: ndarray, p: float = 2.0, w: ndarray | None = None) float[source]

Compute the Minkowski distance between two time series.

The Minkowski distance between two time series of length m with a given parameter p is defined as: .. math:

md(x, y, p) = \left( \sum_{i=1}^{n} |x_i - y_i|^p \right)^{\frac{1}{p}}

Optionally, a weight vector w can be provided to give different weights to the elements: .. math:

md_w(x, y, p, w) = \left( \sum_{i=1}^{n} w_i \cdot |x_i - y_i|^p \right)^{\frac{1}{p}} # noqa: E501
Parameters:
xnp.ndarray

First time series, either univariate, shape (n_timepoints,), or multivariate, shape (n_channels, n_timepoints).

ynp.ndarray

Second time series, either univariate, shape (n_timepoints,), or multivariate, shape (n_channels, n_timepoints).

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, of the same shape as x and y (default is None, which implies equal weights).

Returns:
float

Minkowski distance between x and y.

Raises:
ValueError

If x and y are not 1D or 2D arrays. If p is less than 1. If w is provided and its shape does not match x and y.

Examples

>>> import numpy as np
>>> from aeon.distances import minkowski_distance
>>> 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]])
>>> minkowski_distance(x, y, p=1)
100.0
>>> x = np.array([1, 0, 0])
>>> y = np.array([0, 1, 0])
>>> w = np.array([2,2,2])
>>> minkowski_distance(x, y, p=2, w=w) 
2.0