harris_lahey_binary_distance#
- skfp.distances.harris_lahey_binary_distance(vec_a: ndarray | csr_array, vec_b: ndarray | csr_array) float #
Harris-Lahey distance for vectors of binary values.
Computes the Harris-Lahey distance [1] [2] [3] for binary data between two input arrays or sparse matrices by subtracting the similarity from 1, using the formula:
\[dist(a, b) = 1 - sim(a, b)\]See also
harris_lahey_binary_similarity()
. It uses the normalized similarity, scaled to range [0, 1]. The calculated distance falls within the range \([0, 1]\). Passing all-zero or all-ones vectors to this function results in a distance of 0.- Parameters:
vec_a ({ndarray, sparse matrix}) – First binary input array or sparse matrix.
vec_b ({ndarray, sparse matrix}) – Second binary input array or sparse matrix.
- Returns:
distance – Harris-Lahey distance between
vec_a
andvec_b
.- Return type:
float
References
Examples
>>> from skfp.distances import harris_lahey_binary_distance >>> import numpy as np >>> vec_a = np.array([1, 0, 1]) >>> vec_b = np.array([1, 0, 1]) >>> dist = harris_lahey_binary_distance(vec_a, vec_b) >>> dist 0.0
>>> from scipy.sparse import csr_array >>> vec_a = csr_array([[1, 0, 1]]) >>> vec_b = csr_array([[1, 0, 1]]) >>> dist = harris_lahey_binary_distance(vec_a, vec_b) >>> dist 0.0