[SciPy-user] most negative eigenvalue

Anne Archibald peridot.faceted@gmail....
Tue Aug 28 11:23:16 CDT 2007


On 28/08/07, dmitrey <openopt@ukr.net> wrote:
> Yes, I already use
> try:
>   cholesky(A)
> except:
>   ...
> but it makes impossible to use debugger, that is very bad.

This is a general python question. You should almost never use a bare
"except", for the reason you discovered. What you should do is find
out what exception cholesky (or cho_factor) throws (it's not in the
documentation, though it really should be, but a quick test shows it
throws LinAlgError) and catch only that one:

try:
    cholesky(A)
except LinAlgError:
    # something went wrong.

You can go a step further and check the extra information returned by
the exception, but in this case you want to investigate further
anyway, so I recommend simply using eigvalsh() and looking at the
eigenvalues. If any of them are too close to zero (say 10**-14 times
the largest) the matrix is indefinite, at least numerically.

For more on dealing with exceptions, see
http://docs.python.org/tut/node10.html and maybe also
http://www.diveintopython.org/file_handling/index.html

Anne


More information about the SciPy-user mailing list