Re:Interesting data structures: the BK-tree
by yorwba on Tuesday April 04, 2017 @03:56AM
(#14030448)
If you want to use the triangle inequality with cosine similarity, just use angles instead: https://en.wikipedia.org/wiki/Cosine_similarity#Angular_dist...
EDIT: Deleted calculation about approximating arccos(z) <= arccos(x) + arccos(y) by cos(arccos(z)) <= cos(arccos(x) + arccos(y)) <= xy - (1-x^2)(1-y^2), completely disregarding that cos is a decreasing function in the relevant interval.
I feel like the poster-child for the frequency illusion. There was an article on 538 a few weeks ago that caught my interest which used cosine similarity (a non-metric distance function). I dove in, and started wondering if there were any ways to find nearest neighbors using cosine similarity efficiently. A week later, Facebook's Faiss implements something of a general purpose toolkit for indexing metric and not metric spaces to minimize storage. And now this. It's like the world is trying to tell me something!
[0] http://scikit-learn.org/stable/modules/neighbors.html#k-d-tr...