An error of matrix inversion using NumPy
lancered
wangday at gmail.com
Wed Apr 4 10:52:24 EDT 2007
Here is the eigenvalues of KK I obtained:
>>> linalg.eigvals(KK)
array([ 1.11748411e+05, 3.67154458e+04, 3.41580846e+04,
2.75272440e+04, 2.09790868e+04, 1.86242332e+04,
8.68628325e+03, 6.66127732e+03, 6.15547187e+03,
4.68626197e+03, 3.17838339e+03, 2.84888045e+03,
1.88279736e+03, 1.32427574e+03, 1.04946287e+03,
5.79303171e+02, 3.83111876e+02, 4.93826556e-12,
1.50263232e-12])
You are right. The ratio of max/min eigenvalues is 7.4368432669e+016
Maybe this exceed the of precision of my machine?
Is there any tricks for me to be able to deal with this matrix
correctly with
NumPy?
On Apr 4, 3:58 pm, Robin Becker <r... at reportlab.com> wrote:
> lancered wrote:
> > Hi dear all,
> ..........
> > matrices are correct.
>
> > So, can you tell me what goes wrong? Is this a bug in
> > Numpy.linalg? How to deal with this situation? If you need, I can
> > post the matrix I used below, but it is so long,so not at the moment.
>
> .......
>
> presumably the matrix KK is actually some kind of normal matrix obtained from
> the data. So you have say n variables and m observations the data matrix is than
> an n x m real valued thing say D then you want the inverse of something like D'D
> ie an n by n thing. Typically the data D is de-meaned and normalized by the
> column norms so that you end up with a fairly well scaled problem.
>
> A long time ago I used Numeric+python to do exactly this sort of calculation
> with excellent results and the matrices were as large or larger eg 100 x 100 and
> above. I don't think the underlying numeric routines have changed that much. If
> your matrix is symmetric then you should certainly be using
>
> Even if you can't post the matrix, perhaps you should indicate how you proceed
> from data to matrix. Another problem is that a large determinant is no guarantee
> of stability for the inversion. If the largest eigenvalue is 10**100 and the
> smallest 10**-200 I probably have an ill determined problem; surprisingly easy
> to achieve :(
> --
> Robin Becker
More information about the Python-list
mailing list