Re: [eigen] Positive Definitenes? |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
- To: eigen@xxxxxxxxxxxxxxxxxxx
- Subject: Re: [eigen] Positive Definitenes?
- From: Manuel Yguel <manuel.yguel@xxxxxxxxx>
- Date: Tue, 2 Mar 2010 20:45:46 +0100
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :from:date:message-id:subject:to:content-type; bh=Vj7vevQhpnjTVi0CbE+QUut6lxNBYFDUCkrbzeqoJMM=; b=dQ21yZBFSPhDZI70EFoZ7kY2vwcNmXGukqbAwWUVMgoYGkSkm55TThXiGHN8HM/LoN 2J3Szv7YagZ5Ae0ZF+Qg8lJWrn8UHGryXjjq9fiy8pajDwi4pznR2DqqBYq2YoX/BwxR jwybU3e91Qk5CjlC4ugUI01BcUskwro5jkfDE=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; b=LNMER6yeHUCBXqdFgToxY0rHNxjuISeBHQlnu8hGjiO14CBvtVaj50NWEzdGhP5Lpg ektJRz+9pzMZDKNn0hv/3vy3zTWHcsuBVdrJKSqFUPve12VKTrD8zbvRt0PlAbljK23p 0k7YSmmJtQadp2SD9YNuwKNlTwVRpoy/Cpk3g=
Fun, I had to write a code to check that today, it is probably not
optimal, but it works so I copy paste here for you:
template< class MATRIX >
bool testSymmetry( const MATRIX& m )
{
if( m.rows() != m.cols() ){ return false; }
bool sym = true;
for( int i=0; i<m.rows()&&sym; ++i )
{
for( int j=i+1; j<m.cols()&&sym; ++j )
{
sym = Eigen::ei_isApprox( m(i,j), m(j,i) );
}
}
return sym;
}
template<class MATRIX>
bool testSDP( const MATRIX& mat )
{
//Symmetry
if( !testSymmetry( mat ) ){ return false; }
//Positiveness
SelfAdjointEigenSolver<MATRIX> egs( mat );
//EigenSolver<MATRIX> egs( mat );
typedef Eigen::Matrix<typename MATRIX::Scalar,
MATRIX::RowsAtCompileTime, 1 > Vector_t;
return (egs.eigenvalues().array().real() >
Vector_t::Zero(mat.rows()).array() ).all();
}
I had to write the testSymmetry helper function since the code below:
m.template triangularView<Eigen::StrictlyLower>().isApprox( m.transpose() )
does not work yet (I have to make a patch to add this functionnality).
I hope it helps you.
- best regards,
Manuel
On Tue, Mar 2, 2010 at 7:27 PM, Benoit Jacob <jacob.benoit.1@xxxxxxxxx> wrote:
> 2010/3/2 Cyril Flaig <cflaig@xxxxxxxxxxx>:
>> Hello
>>
>> On 2010-03-02 18:12, Benoit Jacob wrote:
>>> Then it might be possible to do something more efficient with LDLt but
>>> i don't know how numerically stable that would be: this is not, in
>>> principle, a rank-revealing decomposition, and while it allows to get
>>> the determinant, the determinant is not always the right invertibility
>>> check for all situations.
>>
>> The Cholesky decomposition works only if the matrix is positive
>> definite. If the decomposition fails then eigen sets a
>> m_isPositiveDefinite to false, doesn't it?
>>
>> Or is this deprecated and not used in the new version?
>
> This is deprecated indeed.
>
>>
>> -cyril
>>
>>
>>
>
>
>