Euclidean, Cosine and Angular Similarity and Distance
Versión 1.1.0 (5,22 KB) por
Hristo Zhivomirov
Calculation of the Euclidean, cosine and angular similarity and distance between two sets of data.
The present code is a set of three Matlab functions that provide calculation of six metrics:
- Euclidean distance, which vary in the range of [0 : Inf]. Larger values indicate high distance;
- Euclidean similarity, which vary in the range of [0 : 1]. Larger values indicate high similarity;
- cosine distance, which vary in the range of [0 : 2]. Larger values indicate high distance;
- cosine similarity, which vary in the range of [-1 : 1]. Larger values indicate high similarity;
- angular distance, which vary in the range of [0 : 1]. Larger values indicate high distance;
- angular similarity, which vary in the range of [0 : 1]. Larger values indicate high similarity.
The similarity and distance metrics are bound together – the smaller the distance is, the larger the similarity will get, and vice versa.
A few examples are given in order to clarify the usage of the functions. For convenience, the input and output arguments are given in the beginning of each function.
The code is based on the theory described in:
[1] T. Segaran. Programming Collective Intelligence, Ch. 2. Sebastopol, O’Reilly Media, 2007.
[2] E. Vezzetti, F. Marcolin. Similarity Measures for Face Recognition, Ch 5. Sharjah, Bentham Science Publishers, 2015.
[3] D. Cer, Y. Yang, S. Kong, N. Hua, N. Limtiaco, R. John, N. Constant, M. Guajardo-Céspedes, S. Yuan, C. Tar, Y. Sung, B. Strope and R. Kurzweil. Universal sentence encoder for English. Proceedings of the 2018 Conference on Empirical Methods in Natural Language Processing: System Demonstrations, pp. 169-174, 2018.
Citar como
Hristo Zhivomirov (2024). Euclidean, Cosine and Angular Similarity and Distance (https://www.mathworks.com/matlabcentral/fileexchange/98474-euclidean-cosine-and-angular-similarity-and-distance), MATLAB Central File Exchange. Recuperado .
Compatibilidad con la versión de MATLAB
Se creó con
R2017b
Compatible con cualquier versión
Compatibilidad con las plataformas
Windows macOS LinuxEtiquetas
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Descubra Live Editor
Cree scripts con código, salida y texto formateado en un documento ejecutable.