0

I want to calculate the cosine distance $$\text{cos}(x_i, x_j) := 1- \frac{x_i \cdot x_j}{\|x_i\|_2 \cdot \|x_j\|_2}$$ between arbitrary pairs of points $x_i, x_j \in \mathbb{R}^n \setminus 0$.

What I can calculate quickly is the euclidean distance

$$d(x_i, x_j) := \|x_i - x_j\|_2$$

Is there a transformation $f: \mathbb{R}^n \setminus 0 \rightarrow \mathbb{R}^k$ so that $\text{cos}(x_i, x_j) = d \left (f(x_i), f(x_j) \right )$?

What I tried

First, I could project all points on a unit sphere:

$$g(x) := \frac{x}{\|x\|_2}$$

This projection should not change any cosine distance. But even with this simplified representation, I'm uncertain if such a function $f$ exists at all and how it would look like.

Martin Thoma
  • 9,821

1 Answers1

1

If $y_i = g(x_i),y_j = g(x_j)$ are on the unit sphere, then we find that $$ d(y_i,y_j)^2 = (y_i - y_j)\cdot (y_i - y_j) = y_i\cdot y_i + y_j \cdot y_j - 2 y_i \cdot y_j = 2(1 - y_i \cdot y_j). $$ On the other hand, we find that $$ \cos(y_i,y_j) = 1 - y_i \cdot y_j. $$ That is, we have $d(y_i,y_j)^2 = 2\cos(y_i,y_j)$, so that $$ \cos(x_i,x_j) = \cos(y_i,y_j) = \frac{d(y_i,y_j)^2}{2}. $$

Ben Grossmann
  • 225,327