How can I simplify this distance matrix calculation?

62 Views Asked by At

I am trying to calculate a distance matrix. The distance between a $v$ vector and an $a$ axis is the norm of the difference between the vector and its orthogonal projection on the axis:

$$||a - v * (v^T * v)^{-1} * v^T * a||$$

Both $v$ and $a$ are in an $n$ dimensional space.

My first question is whether I can simplify this equation itself?

My overall aim is to solve this computationally for ~2000 axes and vectors, but, in this form, this is either very slow or cannot fit into memory. I only interested in the distances. So my second question is how is it the best to solve this in matrix form?

Updates

  • I can do the computation with a low number of the vectors and axes but not in their matrix form (i.e. with all the ~$2000^2$ combinations)
  • Chunking would be my computational solution but I am interested in whether I can solve it with symbolic manipulation (this is why I posted here, although, indeed, this is not a clear-cut case).
  • Both vectors have 2000 elements and there are 2025 $v$ vectors and 2000 $a$ vectors. So the $V$ and $A$ respective matrices are of 2025x2000 and 2000x2000 shape.