Note
This page is a reference documentation. It only explains the function signature, and not how to use it. Please refer to the user guide for the big picture.
nidl.metrics.kruskal_similarity¶
- nidl.metrics.kruskal_similarity(X, Y, spherical=False)[source]¶
Kruskal similarity between two point clouds / embeddings.
Computes the pairwise Euclidean distances or cosine similarities of both point clouds. Returns the R^2 score of the upper triangular portion of both matrices.
This is essentially a scaled version of Kruskal’s stress, generalized to account for either Euclidean distance or cosine similarity.
- Parameters:
- Xtorch.Tensor or array-like, shape (n_samples, d1)
- Ytorch.Tensor or array-like, shape (n_samples, d2)
- sphericalbool, default=False
If False, compare Euclidean distances If True, compare cosine similarities
- Returns:
- sim0-dim torch.Tensor or np.ndarray
R^2 score in (-∞, 1]. 1 means X and Y are identical (after normalization if
spherical == True) up to Euclidean isometry.
Notes
This metric is not symmetric, kruskal_similarity(X, Y) != kruskal_similarity(Y, X) in general.
References
https://en.wikipedia.org/wiki/Multidimensional_scaling#Non-metric_multidimensional_scaling_(NMDS)