Hi all,
Can I use pytorch or numpy or anything, either by off-the-shelf method, script or library…
Given random d-1 d-dimensional vectors (specifically a random d-1xd matrix), get an d-dimensional vector (specifically (d,) shape tensor) that is perpendicular to every vector mentioned above ?
Not sure if this functionality already exists, but you could try writing a custom function to do this perhaps.
Let’s say that the given matrix is called A. You figure out the eigenvalues of A and if the smallest (ordered by absolute values) is 0, then the corresponding (right) eigenvector is your desired vector. If not, you can calculate something like Gram-Schmidt process. Basically, start from some random vector and keep subtracting the component of each eigenvector from it iteratively. That should give you the vector that is perpendicular to all rows of A.
Hope this helps.
Note that if A (vectors) is degenerate (that is, that some linear
combination of its rows is zero), then perpendicular_vector
will no longer be (in essence) unique. In such a case A will have
a multi-dimensional null space (sometimes calls its kernel), and
any vector lying in A’s null space will be (by definition) perpendicular
to A’s rows.
You are absolutely right @KFrank ! Thanks for pointing out that singular values, and not eigenvalues, are what’s needed here.
A small suggestion: It’s probably worth clarifying the in the code that you used the last right eigenvector, perhaps changing it to torch.linalg.svd(vectors).Vh[-1] adds a little more insight into the entire solution?