BUG: orthogonal_procrustes returns the transpose/inverse
See original GitHub issueDescribe your issue.
The scipy.linalg.orthogonal_procrustes
function will return the transpose (or inverse) of the desired orthogonal matrix instead of the correct one on some occasions.
If the code below is run a few times, it will print True
sometimes and False
other times. At the times when it prints False
, I find that R_hat
is the transpose of R
and not R
itself. However, if I uncomment the line
# R = np.linalg.qr(np.random.randn(2,2))[0]
and comment the line
R = scipy.stats.ortho_group.rvs(2)
I will always get True
as expected. It seems that the way that the random orthogonal matrix R
is sampled affects the result of orthogonal_procrustes
. Sampling using scipy.stats.ortho_group.rvs(2)
seems to be causing the problem,
Reproducing Code Example
import numpy as np
import scipy.linalg
import scipy.stats
X = np.random.randn(2,3)
# sample random orthogonal matrix
# R = np.linalg.qr(np.random.randn(2,2))[0]
R = scipy.stats.ortho_group.rvs(2)
# rotate/reflect each column vector in X using R
Y = R @ X
# estimate R using orthogonal procrustes
R_hat = scipy.linalg.orthogonal_procrustes(X.T,Y.T)[0]
print(np.allclose(R,R_hat))
Error message
No error message.
SciPy/NumPy/Python version information
1.5.4 1.19.2 sys.version_info(major=3, minor=8, micro=11, releaselevel=‘final’, serial=0)
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Why is the inverse of an orthogonal matrix equal to its ...
Let A be an n×n matrix with real entries. The matrix A is orthogonal if the column and row vectors are orthonormal vectors....
Read more >Orthogonal Procrustes problem - Wikipedia
The orthogonal Procrustes problem is a matrix approximation problem in linear algebra. In its classical form, one is given two matrices A {\displaystyle...
Read more >Lab | Matrix transpose-square-root
Orthonormalization turns a set of vectors into an orthonormal basis (2.404), and amounts to computing the transpose-square-root of a Gramian.
Read more >Orthogonal Sparse PCA and Covariance Estimation via ... - arXiv
Index Terms—Sparse PCA, Procrustes, Stiefel manifold, ... while we should replace the transpose operation (i.e., (·)T ).
Read more >Finding optimal rotation and translation between ... - Nghia Ho
If the data is noisy it will minimize the least squares error ... Using the inverse as above will return a general 3×3...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Here is the solution to my problem above in case anyone needs it. According to the documentation for the
scipy.linalg.orthogonal_procrustes
function:I initially thought that this function solves the problem
(R @ A) - B
and not(A @ R) - B
, which was the source of my confusion. The following code works fineNote that each row of the matrix
X
is a separate vector and not each column as before.Ah what @melissawm said. My apologies, I missed the page refresh