Re: [eigen] Positive Definitenes?

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]


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
>>
>>
>>
>
>
>



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/