Distance metrics#

thetan.metrics

Distance functions shared by every Thetan algorithm. Every metric is oriented so that a smaller value means two rows are closer. Compiled with Cython.

thetan.metrics.distance_matrix(X1, X2, metric='norm_ssd')#

Compute the metric between every row of X1 and every row of X2.

Parameters:
X1ndarray, shape (n1, n_features)

First set of vectors, as a C-contiguous float64 array.

X2ndarray, shape (n2, n_features)

Second set of vectors, as a C-contiguous float64 array with the same number of columns as X1.

metricstr, optional

One of ‘euclidean’, ‘ssd’, ‘norm_ssd’, ‘norm_ssd_un’, ‘dot_prod’, ‘l1_norm’, ‘inf_norm’, ‘cosine’ or ‘arccos’. Default is ‘norm_ssd’, not ‘euclidean’. ‘dot_prod’ gives the negative dot product, so that for every metric a smaller value means the rows are more alike.

Returns:
np.asarray(distance_matrix)ndarray, shape (n1, n2)

Value of the metric for each pair of rows. With ‘dot_prod’ these are the dot products with their sign flipped.

Raises:
TypeError

If metric is not a str.

ValueError

If X1 and X2 have different numbers of columns, or metric is not a known name.