How close apart are two message - "Document Distance" algorithm I was looking at this algorithm that computes how close apart are two texts from one another and the formula seems a bit weird to me.
The basic steps are:


*

*For each word encountered in a text you let a vector hold its frequency. For $n$ different words our vectors would then be $R^n$. You can assume that the word of row $i$ of vector $1$ equals row $j$ of vector $2$. For example row $0$ of vector $1$ has the value $4$ and row $0$ of vector $2$ has a value of $3$, both referring to the word Dog but one text having $4$ occurrences of the word Dog while the other text having only $3$ occurrences of the word Dog. If a word appears in one text but not in the other text then the vector that corresponds to the text not having that word will have a value of $0$.

*Compute the distance between the two vectors using the formula:
$$\arccos\left(\frac{L1\cdot L2}{\sqrt{(L1\cdot L1)(L2\cdot L2)}}\right)\tag1$$
Why use the above equation when we could use Euclidean distance instead?
$$d(p,q) = \sqrt{(p_1-q_1)^2 + (p_2-q_2)^2 + \cdots + (p_i-q_i)^2 + \cdots + (p_n-q_n)^2}.$$
It seems like a simpler way to go about finding the distance between two vectors. I don't really understand the equation (1) too well so i am not sure if it is more appropriate in finding how close apart are two texts.

$L_1\cdot L_2 = \cos(\theta)\|L_1\|\|L_2\|$ where $\theta$ is the value that makes the equation true (which for euclidean space and dotproduct coincides with our definition of angle in the usual geometric sense).
Furthermore, $\|L_1\| = \sqrt{L_1\cdot L_1}$
Combining these pieces of information, we get $\frac{L_1\cdot L_2}{\sqrt{(L_1\cdot L_1)(L_2\cdot L_2)}}=\cos(\theta)$
And so, $\arccos (\frac{L_1\cdot L_2}{\sqrt{(L_1\cdot L_1)(L_2\cdot L_2)}}) = \theta$
The first formula isn't "distance" in the sense of from one point to the other so much as it is "angle" between the two as mentioned by other responders.
It should be mentioned that the two formulas will give quite different answers.
