[Math] Cosine similarity between complex vectors

linear algebravector analysis

Having a pair of vectors where its elements are complex, is that possible to calculate the cosine similarity between these two vectors to see how similar they are?, and if the result of this calculation is another complex number, What should i do with this result?, I have applied the norm, is that correct?.

Tnaks for your comments!

Best Answer

It sounds like you want to take the dot product such that a vector dotted with itself gives the magnitude squared norm. For real vectors $\mathbf{x}$ and $\mathbf{y}$ this is $$\langle\mathbf{x},\mathbf{y}\rangle := \mathbf{x}^\top \mathbf{y}$$

Note that a norm should always return a non-negative real value so that $$\langle\mathbf{x},\mathbf{x}\rangle \ge 0$$

Note also that if $\mathbf{x}$ has complex values this definition fails to be a norm. To see this consider $\mathbf{x}^\top = (i,0,0,\dots)$ giving $$\mathbf{x}^\top \mathbf{x} = -1$$

Thus for complex numbers the norm is slightly different. To be a norm in the complex field, define the norm as $$\langle\mathbf{x},\mathbf{y}\rangle := \mathbf{x}^\dagger \mathbf{y}$$ Where the difference is that instead of the transpose, it is the transpose and complex conjugate. In that case for the example $\mathbf{x}^\top = (i,0,0,\dots)$ \begin{align} \mathbf{x}^\dagger \mathbf{x} &= (-i,0,0,\dots) (i,0,0,\dots)^\top\\ & = -ii \\ &= -(-1)\\ & = 1 \\ \end{align}

In terms of your desire to measure their "similarity", I am supposing you want the angle between them, which (for reals) requires solving the formula $$\cos\theta = \frac{\mathbf{x}^\top \mathbf{y}}{(\mathbf{x}^\top\mathbf{x})(\mathbf{y}^\top\mathbf{y})}$$

Or more simply for $\vert \mathbf{x} \vert = 1$ and $\vert \mathbf{y} \vert = 1$

$$\cos\theta = \mathbf{x}^\top \mathbf{y}$$

The magnitude on the right will be between zero and one. Zero means that the two vectors are orthogonal (90 degrees or $\pi\over 2$). One means they are scalar multiples of each other.

For complex, the magnitude still gives the "similarity" between them, where the complex angle gives the complex phase factor required to fully reach that similarity. In other words, if your result is $\cos\theta=-i$, then $i\mathbf{x}$ is a real scalar multiple of $\mathbf{y}$.

Related Question