biosppy.metrics¶
biosppy.metrics¶
This module provides pairwise distance computation methods.
- copyright:
2015-2026 by Instituto de Telecomunicacoes
- license:
BSD 3-clause, see LICENSE for more details.
Functions
|
Computes distance between each pair of the two collections of inputs. |
|
Computes the Cosine distance (positive space) between 1-D arrays. |
|
Pairwise distances between observations in n-dimensional space. |
|
Converts a vector-form distance vector to a square-form distance matrix, and vice-versa. |
- biosppy.metrics.cdist(XA, XB, metric='euclidean', **kwargs)[source]¶
Computes distance between each pair of the two collections of inputs.
Wraps scipy.spatial.distance.cdist.
- Parameters:
XA (array) – An
by
array of
original observations
in an
-dimensional space.XB (array) – An
by
array of
original observations
in an
-dimensional space.metric (str, function, optional) – The distance metric to use; the distance can be ‘braycurtis’, ‘canberra’, ‘chebyshev’, ‘cityblock’, ‘correlation’, ‘cosine’, ‘dice’, ‘euclidean’, ‘hamming’, ‘jaccard’, ‘kulsinski’, ‘mahalanobis’, ‘matching’, ‘minkowski’, ‘pcosine’, ‘rogerstanimoto’, ‘russellrao’, ‘seuclidean’, ‘sokalmichener’, ‘sokalsneath’, ‘sqeuclidean’, ‘yule’.
kwargs (Possible) –
- pfloat
The p-norm to apply (for Minkowski, weighted and unweighted).
- warray
The weight vector (for weighted Minkowski).
- Varray
The variance vector (for standardized Euclidean).
- VIarray
The inverse of the covariance matrix (for Mahalanobis).
- Returns:
Y (array) – An
by
distance matrix is returned. For each
and
, the metric dist(u=XA[i], v=XB[j])is computed and stored in the
th entry.
- biosppy.metrics.pcosine(u, v)[source]¶
Computes the Cosine distance (positive space) between 1-D arrays.
The Cosine distance (positive space) between u and v is defined as

where
is the dot product of
and
.- Parameters:
u (array) – Input array.
v (array) – Input array.
- Returns:
cosine (float) – Cosine distance between u and v.
- biosppy.metrics.pdist(X, metric='euclidean', **kwargs)[source]¶
Pairwise distances between observations in n-dimensional space.
Wraps scipy.spatial.distance.pdist.
- Parameters:
X (array) – An m by n array of m original observations in an n-dimensional space.
metric (str, function, optional) – The distance metric to use; the distance can be ‘braycurtis’, ‘canberra’, ‘chebyshev’, ‘cityblock’, ‘correlation’, ‘cosine’, ‘dice’, ‘euclidean’, ‘hamming’, ‘jaccard’, ‘kulsinski’, ‘mahalanobis’, ‘matching’, ‘minkowski’, ‘pcosine’, ‘rogerstanimoto’, ‘russellrao’, ‘seuclidean’, ‘sokalmichener’, ‘sokalsneath’, ‘sqeuclidean’, ‘yule’.
kwargs (Possible) –
- pfloat
The p-norm to apply (for Minkowski, weighted and unweighted).
- warray
The weight vector (for weighted Minkowski).
- Varray
The variance vector (for standardized Euclidean).
- VIarray
The inverse of the covariance matrix (for Mahalanobis).
- Returns:
Y (array) – Returns a condensed distance matrix Y. For each
and
(where
), the metric dist(u=X[i], v=X[j])is computed and stored in entryij.
- biosppy.metrics.squareform(X, force='no', checks=True)[source]¶
Converts a vector-form distance vector to a square-form distance matrix, and vice-versa.
Wraps scipy.spatial.distance.squareform.
- Parameters:
X (array) – Either a condensed or redundant distance matrix.
force (str, optional) – As with MATLAB(TM), if force is equal to ‘tovector’ or ‘tomatrix’, the input will be treated as a distance matrix or distance vector respectively.
checks (bool, optional) – If checks is set to False, no checks will be made for matrix symmetry nor zero diagonals. This is useful if it is known that
X - X.T1is small anddiag(X)is close to zero. These values are ignored any way so they do not disrupt the squareform transformation.
- Returns:
Y (array) – If a condensed distance matrix is passed, a redundant one is returned, or if a redundant one is passed, a condensed distance matrix is returned.