1
$\begingroup$

I have been experimenting with random vectors in $d$ dimensions, where each coordinate is independently generated from a uniform distribution between 0 and 1. This is

$$ X = (x_1, x_2, ..., x_d) \\ Y = (y_1, y_2, ..., y_d) $$

where $x_i, y_j \sim U(0, 1)$.

Upon numerically computing the cosine similarity between two such vectors, I consistently observe an approximation of

$$\text{cos sim}(X, Y) = \frac{X \cdot Y}{ \left \| X\right \| \left \| Y \right \|} \approx 0.75$$

I am intrigued by this numerical result and am seeking a mathematical explanation or derivation for this specific value. Moreover, I've noticed that the result doesn't change too much as $d$ changes. It's worth noting that the vectors are not uniformly distributed on the $d$-dimensional sphere (if this was the case I know the angle between the vectors goes to $0$ as $d\to \infty$).

Can someone shed light on why this particular value emerges and provide insights into the underlying mathematical reasoning?

$\endgroup$

1 Answer 1

2
$\begingroup$

For large $d$, this value will be close to the value you get if you substitute the expected value for each factor.

The expected value of $X\cdot Y$ and of $\|X\|^2$ is in each case $n$ times the expected value of each of the $n$ summands. For $X\cdot Y$, that’s

$$\int_0^1\mathrm dx\int_0^1\mathrm dy xy=\frac12\cdot\frac12=\frac14\;.$$

For $\|X\|^2$, it’s

$$ \int_0^1\mathrm dxx^2=\frac13\;. $$

Thus, for large $d$ the quotient goes to

$$ \frac{\frac14}{\frac13}=\frac34\;. $$

$\endgroup$
1
  • $\begingroup$ Are you using something like law of large numbers to actually pass to the limit here? $\endgroup$
    – Milten
    Jan 30 at 13:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .