I am trying to generate two vectors with a given cosine similarity. Input would be the degree of cosine similarity (or angle as it depends on it anyway) and the number of dimensions (D) in the vectors, and output would be two vectors of D dimensions with that given similarity between them Now, I know how to use the cosine similarity function to calculate the similarity but I'm lost when trying it the other way around. Is there such a procedure or algorithm and how is it called?
CodePudding user response:
For a given starting vector u
and cosine similarity c
:
- Generate 2 points in n-D space; call them
a
andb
- Project
b
onto the plane orthogonal tou
and containinga
- Subtract
a
from the result to obtain a vector orthogonal tou
; call ith
- Use
[u,h]
as a basis and basic trigonometry to generate the desired vectorv
The above method is dimension-agnostic as it only uses dot products. The resultant vectors {v}
are of unit length and uniformly distributed around u
.