New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MAINT:lstsq: Switch to tranposed problem if the array is tall #12206
Conversation
pinging @sturlamolden and others. It is a relatively simple fix but a second pair of eyes won't hurt. |
Looks good |
It needs a testcase. |
Hmm I don't know how to test this actually since behavior is not changed. Any ideas anyone? |
Just compute the pinv for two arrays. Let they be above and below the threshold for transposition. Then compare with some other means of computing pinv, like cho_solve(cho_factor(A.T@A),np.eye(p))@A.T |
And since you are returning a transpose, it might also be possible to see if this happened by looking at the .flags and .strides for the returned pinv array. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Thanks @ilayn fot this PR
LGTM |
Reviews are positive here, CI is green, no old tests were modified, just a new test added, so merging. Thanks @ilayn and reviewers. |
Reference issue
Closes #12196
What does this implement/fix?
The pseudo-inverse solution via scipy.linalg.pinv is through forming a least-squares problem AX=B where X is the pseudo-inverse of A and B is identity. When A is tall, necessarily B assumes the row number of A and is equally tall. However due to the properties of pseudo-inverse, one can also solve for A.T X.T = B and in this case B will be substantially smaller if A is substantially taller. This PR enables this behavior via an internal trans flag.
The switching point for assuming tallness is when row number is higher than column number by 10 percent. It is kind of arbitrary but derived from some numerical experiments. I would appreciate a more rigorous derivation of the switch point.