similarity
- fgvc.special.similarity.batch_cosine_similarity(a: Tensor | ndarray, b: Tensor | ndarray, eps: float = 1e-08) Tensor | ndarray
Compute batch-wise cosine similarity between a vector and a vector or matrix.
- Parameters:
a – A batch of vectors represented as numpy array or pytorch tensor.
b – A batch of vectors or matrices represented as numpy array or pytorch tensor.
eps – Epsilon small constant to prevent division by 0.
- Returns:
Cosine similarity vector or matrix.
- Return type:
cos_sim
- fgvc.special.similarity.cosine_similarity(a: Tensor | ndarray, b: Tensor | ndarray, eps: float = 1e-08) Tensor | ndarray | float
Compute cosine similarity between a vector and a vector or matrix.
- Parameters:
a – A vector represented as numpy array or pytorch tensor.
b – A vector or a matrix represented as numpy array or pytorch tensor.
eps – Epsilon small constant to prevent division by 0.
- Returns:
Cosine similarity number or vector.
- Return type:
cos_sim
- fgvc.special.similarity.pairwise_cosine_similarity(mat: Tensor | ndarray, eps: float = 1e-08, progress: bool = False) Tensor | ndarray
Compute pair-wise cosine similarity between all elements in the input matrix.
- Parameters:
mat – A matrix represented as numpy array or pytorch tensor.
eps – Epsilon small constant to prevent division by 0.
progress – If true use tqdm progress bar.
- Returns:
A similarity matrix.
- Return type:
sim_mat