-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
Inverse of singular matrix. Should be error but in fact not. #10471
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
Comments
For what it's worth:
which as you correctly observe, is clearly singular. On my machine with
In general I wouldn't expect precise results from a floating point inversion algorithm though.
If you use a float matrix rather than an integer matrix in |
The condition number ( |
R raise error for float numbers too. Workaround is checking every matrix via |
@noob-saibot This isn't a numpy problem, this is a general problem for anyone doing numerical linear algebra on a computer. You will see the same thing in R, depending on the exact matrices you use and depending on how your R was built. In fact in general numpy and R use the same code to perform a matrix inversion like this. For computational purposes, there's no meaningful difference between a matrix that's not invertible (condition number is infinite), and one where the condition number is merely very large. |
As I see at code def inv(a): developers check matrix on rank and squareness. Cant they add Also for my understanding. Problem in lapack dgesv function, is it? The LU decomposition return correct output, so we dont detect singularity. Thank for answers:) |
@noob-saibot You could use >>> import numpy as np
>>> import scipy.linalg as spla
>>> b = np.array([[1,1,0], [1,0,1], [1,1,0]])
>>> spla.solve(b.T.dot(b), np.eye(3))
8000
/some/long/path/scipy/linalg/basic.py:40: RuntimeWarning: scipy.linalg.solve
Ill-conditioned matrix detected. Result is not guaranteed to be accurate.
Reciprocal condition number/precision: 1.2335811384723961e-17 / 1.1102230246251565e-16
RuntimeWarning)
array([[ 4.50359963e+15, -4.50359963e+15, -4.50359963e+15],
[-4.50359963e+15, 4.50359963e+15, 4.50359963e+15],
[-4.50359963e+15, 4.50359963e+15, 4.50359963e+15]]) The issue in >>> P, L, U = spla.lu(b.T.dot(b))
>>> U
array([[ 3.00000000e+00, 2.00000000e+00, 1.00000000e+00],
[ 0.00000000e+00, 6.66666667e-01, -6.66666667e-01],
[ 0.00000000e+00, 0.00000000e+00, 2.22044605e-16]]) Since all diagonal elements in But, do you really need |
Thank you for detailed answer. Yes for OLS calculating. I'll read about another methods. |
noob-saibot commented on 30 Jan 2018:
Actually, they don't check on rank, even though they call their function |
Different meaning of "rank". In old Numeric and NumPy, rank referred to the number of dimensions, not the number of independent row/columns. We have removed that usage most places and should probably rename the function. The |
Let's rename these functions to not use the word rank then: #14814 |
As shown in numpygh-10471, this naming was confusing. Also rename all the functions of this style to use snake case
Uh oh!
There was an error while loading. Please reload this page.
Hello.
I've got strange behavior for experiments. I'm working with matrix (for example b) that in result of multiplying b.T * b should be singular matrix and for inverse method should be arisen error like numpy.linalg.linalg.LinAlgError: Singular matrix. But result was high/low values.
Code below:
How can be avoided this behavior?
Tests on:
win10, Python 3.5.4, numpy version '1.14.0'.
ubuntu 16.04, Python 3.5.2, numpy version '1.13.3' and '1.14.0'.
PS. I've checked via wolfram and R it's real singular matrix.
The text was updated successfully, but these errors were encountered: