How to find a new equidistant vector, given 5 existing vectors?

683 Views Asked by At

Vectors v1, v2, v3, v4, V5, with 100 dim each, how to find a center vector, that will have equal distance with each?

preferably if there is a way done in Python or Numpy.

1

There are 1 best solutions below

2
On BEST ANSWER

First, note that if the distances are all equal, then the squares of the distances are also equal. This avoids needing to use square roots, making the handling more efficient & easier to deal with.

Consider a general case where you have $n$ vectors, each of $d$ dimensions, with $v_c$ being the center vector you want to determine. Notation wise, have $v_{ji}$ be the $i$'th component of vector $v_j$. The distance squared from the first vector to the center vector is to be the same as the distance squared from every other vector to the center vector, i.e.,

$$\sum_{i = 1}^d \left(v_{1i} - v_{ci}\right)^2 = \sum_{i = 1}^d \left(v_{ji} - v_{ci}\right)^2 \tag{1}\label{eq1}$$

for all $2 \le j \le n$. Expanding the squares inside the summations and moving various parts around gives

$$\sum_{i = 1}^d \left(v_{1i}^2 - 2v_{1i}v_{ci} + v_{ci}^2\right) = \sum_{i = 1}^d \left(v_{ji}^2 - 2v_{ji}v_{ci} + v_{ci}^2\right)$$ $$\sum_{i = 1}^d \left(v_{1i}^2 - v_{ji}^2 - 2v_{1i}v_{ci} + 2v_{ji}v_{ci}\right) = 0$$ $$\sum_{i = 1}^d \left(v_{1i}^2 - v_{ji}^2\right) - 2\sum_{i = 1}^d \left(v_{1i} - v_{ji}\right)v_{ci} = 0$$ $$2\sum_{i = 1}^d \left(v_{1i} - v_{ji}\right)v_{ci} = \sum_{i = 1}^d \left(v_{1i}^2 - v_{ji}^2\right) \tag{2}\label{eq2}$$

Since the $v_{1i}$ and $v_{ji}$ values are known, \eqref{eq2} is simply a linear equation in the $d$ unknowns of $v_{ci}$. Using $j$ from $2$ to $n$ gives you $n-1$ such equations to solve simultaneously. In your particular case, $d = 100$ and $n = 5$ means you have a very under-determined system of $4$ equations in $100$ unknowns, so there won't be a unique center vector. Regarding solving this in Python, there are several possible ways to do it using packages like numpy and sympy, such as described in Is there a python module to solve linear equations?.

Update: As pointed out in a comment by Théophile, with so many available degrees of freedom, you can reasonably impose some constraints, such as required or suggested by the problem, with the suggested option being to

find the solution with the smallest magnitude, i.e., closest to the origin.