This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Inconsistent behaviour of LDLT?

Tags: None
(comma "," separated)
alexggmatthews
Registered Member
Posts
2
Karma
0

Inconsistent behaviour of LDLT?

Wed Jul 18, 2012 11:26 am
Hi,
I'm working with V3 of Eigen.

I'm looking at the test case of the matrix.
[1,0]
[0,-1]

This matrix isn't semi-positive definite. Nor is it semi-negative definite.
Running it through LDLT I get the following results:

reconstructedMatrix ;
[1,0]
[0,-1]
isPositive : True (Which is wrong!)
isNegative : False
info : Success

If you contrast this to the same input for LLT I get a failure code from info(), which is what I would expect since LLT only works on SPD matrices.
In the docs it says that we can use LDLT on semi-positive definite or semi-negative matrices. If the input isn't one of these, as in the above case, it seems it should either fail or give a correct output. Is it possible to have this behaviour, please? Or is it not easy to do with this algo? Certainly it would help in the sense I that I wouldn't need an independent check on the correctness of the input in my code.

Thanks very much. Really impressed with Eigen by the way.
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
Hi,

your matrix is a special case because it is diagonal. Therefore, the factorization went well, and it assumed the matrix was positive because the first pivot was 1. In a more general case, the factorization would have failed. I'm not sure we want to abort the factorization if it can really be done. So I propose the following simple fix: line 284 add:
Code: Select all
      else if(sign)
      {
        // LDLT does not support non positive or non negative matrices, except if the matrix is diagonal.
        int newSign = real(mat.diagonal().coeff(index_of_biggest_in_corner)) > 0;
        if(newSign!=*sign)
          m_sign = 0;
      }
alexggmatthews
Registered Member
Posts
2
Karma
0

Re: Inconsistent behaviour of LDLT?

Fri Jul 20, 2012 9:41 am
Thanks very much for clearing this up.
jitseniesen
Registered Member
Posts
204
Karma
2

Re: Inconsistent behaviour of LDLT?

Sun Jul 22, 2012 8:40 pm
ggael wrote:your matrix is a special case because it is diagonal. Therefore, the factorization went well, and it assumed the matrix was positive because the first pivot was 1. In a more general case, the factorization would have failed.
In what sense would it fail? I tried a couple of indefinite matrices, and the LDLT class seems to work fine. Perhaps you mean that the algorithm can be unstable if the matrix is close to singular?

I'm not sure we want to abort the factorization if it can really be done. So I propose the following simple fix: line 284 add: [...]
I cannot see anything wrong with that, so I committed your fix to the development branch.


Bookmarks



Who is online

Registered users: Baidu [Spider], Bing [Bot], Google [Bot]