Closed yg42 closed 2 years ago
Softassign is a developmental feature (in a package under development itself) so it's far from bulletproof.
The (current) softassign in procrustes
is intended to only support one specific use case, as an implementation of the 2-sided permutation Procrustes problem with one transformation. Thus the input matrices must be square, and we need to (and will) update our documentation to indicate that the a
and b
matrices must be square. To use this, you could pad the matrices with zeros (and then remove the default option to eliminate zero rows/columns from softassign).
At a scientific level, the easiest way to find a permutation matrix from a orthogonal matrix is to find the closest permutation matrix to a given rotation matrix. This is just a one-sided permutation matrix with a = identity and b = target_rotation_matrix.
The following code will work with the current implementation, but the API of softassign
is changing to become consistent with other procrustes functions:
# add zero columns to make A and B square
n, m = a.shape
square_a = np.hstack((a, np.zeros((n, n - m))))
n, m = b.shape
square_b = np.hstack((b, np.zeros((n, n - m))))
# run softassign without removing the zero columns
res = softassign(square_a, square_b, remove_zero_col=False, remove_zero_row=False)
print("error = ", res.error)
print("permutation matrix = ")
print(res.t)
Thank you very much for this answer. We will test this solution in our problem.
Thank you for your interest in our package. I will close this issue for now. Please feel free to reopen it if needed. @yg42
Dear all, I do not know how to get the permutation matrix (like what I would get from the softassign function). I tried the following code, that works in the case of of a square matrix a (d=n), but not for a non square matrix. The error I get is
How could I get the permutation matrix directly from the orthogonal function ? Is this a bug ?
thank you very much for your time best regards
yann