linear_similarity_from_distances#

tangles.util.matrix_order.linear_similarity_from_distances(m: ndarray, margin: float, eps: float = 1e-08, sparse_mat: bool = True, distance_p: float = 2)#

Turns a matrix of positions into a matrix of similarities (simply based on distances).

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

Matrix of positions.

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.