Chebyshev (L-infinity) distance function.
Functions
chebyshev_distance(x1: np.ndarray, x2: np.ndarray) -> float
Compute Chebyshev (L-infinity) distance between two points.
The Chebyshev distance is the maximum absolute difference across all dimensions. Also known as chessboard distance or L-infinity norm.
Theory
d(x, y) = \max_i |x_i - y_i|
This is the limiting case of the Minkowski distance as p \to \infty.
Parameters
x1
np.ndarray of shape (n_features,)
First point.
x2
np.ndarray of shape (n_features,)
Second point.
Returns
dist
float
Chebyshev distance.
Notes
Complexity:
- Time: O(n) where n is the number of features.
Compute distance between two 2D points:
python
>>> import numpy as np
>>> from tuiml.algorithms.clustering.distance import chebyshev_distance
>>> x1 = np.array([0, 0])
>>> x2 = np.array([3, 4])
>>> chebyshev_distance(x1, x2)
4.0
chebyshev_pairwise(X: np.ndarray, Y: np.ndarray=None) -> np.ndarray
Compute pairwise Chebyshev distances.
Parameters
X
np.ndarray of shape (n_samples_X, n_features)
First set of samples.
Y
np.ndarray of shape (n_samples_Y, n_features)
= None
Second set of samples. Defaults to X.
Returns
dist_matrix
np.ndarray of shape (n_samples_X, n_samples_Y)
Distance matrix.