0

I have been trying to find a fast algorithm of calculating all the angle between n vectors that are of length x. For example if x=3 and n=4, my data would look something like this:

A: [1,2,3]
B: [2,3,4]
C: [...]
D: [...]

I was wondering is it acceptable to find the the angle between all of be vectors (A,B,C,D) with respect to some fix vector (i.e. X:[100,100,100,100]) and then the subtract the angles of (A,B,C,D) found with respect to that fixed value, to find the angle between all of them. I want to do this because I would only have to compute the angle once and then I can subtract angles all of my vectors to find the different between them. In short, I want to know is it safe to make this assumption?

angle_between(A,B) == angle_between(A,X) - angle_between(B,X)

and the angle_between function is the Cosine similarity.

nerdPollution
  • 45
  • 1
  • 1
  • 4
  • In what language? There may be a simple library for your preferred language that offers this functionality, or you can easily vectorize this in the language of your choice. –  Nov 06 '15 at 05:48
  • I think your point is valid in the two dimensional case, but not for higher dimensions (e.g., your example gives 3D data points): the angle between a vector pointing North (from Earth's center) and a vector pointing towards 0 longitude on the equator is 90 degrees, which is the same as the angle between the first vector and a vector pointing towards 90 longitude on the equator. –  Nov 06 '15 at 05:52
  • Since, I am using the cosine similarity metric for my angle_between function, wouldn't the angle between the Vector pointing north and the vector pointing south be 0? Because the angle between two vectors cannot be greater than 90°. – nerdPollution Nov 06 '15 at 06:01
  • I never mentioned a vector pointing South; What do you mean by that? –  Nov 06 '15 at 06:06
  • in 3d you need 3 fixed non-coplanar (preferably orthogonal) axis to do this (eg x, y and z axis) so you can construct all angles using 3N cosines but the relationship in not straightforward and I fear that for small N direct approach would be faster – Azad Nov 06 '15 at 07:08

1 Answers1

0

That approach will only work for 2-D vectors. For higher dimensions any two vectors will define a hyperplane, and only if the third (reference) vector also lies within this hyperplane will your approach work. Unfortunately instead of only calculating n angles and subtracting, in order to determine the angles between each pair of vectors you would have to calculate all n choose 2 of them.