quaterion.distances.euclidean module¶
- class Euclidean[source]¶
Bases:
BaseDistance
Compute Euclidean distances (and its interpretation as similarities).
Note
Interpretation of Euclidean distances as similarities is based on the trick in the book “Collective Intelligence” by Toby Segaran, and it’s in the range of 0 -> 1.
Note
The distance matrix computation is based on a trick explained by Samuel Albanie.
- static distance(x: Tensor, y: Tensor) Tensor [source]¶
Calculate distances, i.e., the lower the value, the more similar the samples.
- Parameters:
x – shape: (batch_size, embedding_dim)
y – shape: (batch_size, embedding_dim)
- Returns:
Distances - shape – (batch_size,)
- static distance_matrix(x: Tensor, y: Optional[Tensor] = None) Tensor [source]¶
Calculate a distance matrix, i.e., distances between all possible pairs in x and y.
- Parameters:
x – shape: (batch_size, embedding_dim)
y – shape: (batch_size, embedding_dim). If y is None, it assigns x to y.
- Returns:
Distance matrix - shape – (batch_size, batch_size)
- static similarity(x: Tensor, y: Tensor) Tensor [source]¶
Calculate similarities, i.e., the higher the value, the more similar the samples.
- Parameters:
x – shape: (batch_size, embedding_dim)
y – shape: (batch_size, embedding_dim)
- Returns:
Similarities - shape – (batch_size,)
- static similarity_matrix(x: Tensor, y: Optional[Tensor] = None) Tensor [source]¶
Calculate a similarity matrix, i.e., similarities between all possible pairs in x and y.
- Parameters:
x – shape: (batch_size, embedding_dim)
y – shape: (batch_size, embedding_dim). If y is None, it assigns x to y.
- Returns:
Similarity matrix - shape – (batch_size, batch_size)