[eigen] What is the most reliable way to check if a symmetric matrix is positive semi-definite

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


In some function parameter input validation code, I was using
SelfAdjointEigenSolver to compute eigenvalues and verify all have real
part >= 0 (i.e., the matrix is positive semi-definite).  When calling
the function with a Matrix A = B * B.transpose(), my test was failing
with one of the eigenvalues very close to zero but slightly negative
(-7.707116279041277e-17).  The check I was dong was like:

evals_A = AselfadjointView<Eigen::Lower>().eigenvalues();
if ((evals_A.real().array() < 0).any())
  throw std::invalid_argument("A must be positive semi-definite.");

I can imaging going through each eigenvalue and checking more
carefully and letting things pass if the eigenvalues is within some
tolerance of 0, but I was wondering if perhaps I am doing things in a
bad way.

Does anybody have any recommendations for a robust and clean way to
check for positive-semi-definiteness using Eigen?

Luke


--
“People call me a perfectionist, but I'm not. I'm a rightist. I do
something until it's right, and then I move on to the next thing.”
― James Cameron



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