linear_similarity_from_dist_matrix#
- tangles.util.matrix_order.linear_similarity_from_dist_matrix(dist: ndarray, margin: float, eps: float = 1e-08, sparse_mat: bool = True)#
Turns a distance matrix into a similarity matrix by linearly inverting the distances up to some maximum distance (margin).
A matrix order function (quadratic form) based on the returned matrix behaves like a “margin order function”, i.e. only pairs of separated points close to a (fictitious optimal) boundary between the separation’s sides are taken into account.
Similarities range from 1, if they are equal, to 0, if they have a distance greater than margin.
Parameters#
- mnp.ndarray
distance matrix of data
- marginfloat
Size of the margin. In the distance matrix, all distances greater than this margin will be set to the margin.
- epsfloat
A threshold. Similarities below this value are set to 0.
- sparse_matbool
Whether to return a sparse.csr_matrix.
- distance_pfloat
Which Minkowski p-norm to use. Must take a value in \([1, \infty)\).
Returns#
- sparse.csr_matrix or np.ndarray
A matrix of similarities.