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.

The first formula is related to dot product $$\mathbf u\cdot \mathbf v = \|\mathbf u\|\ \|\mathbf v\|\cos \theta$$
One property (compared with Euclidean distance) is that the cosine has a upper bound. Also does not depend so much on the length of the text, because each vector is normalised to unit length in the denominator.
