In my third week of coding, I made some changes to my previous code, added documentation in the form of comments, made a bunch of minor changes to my code, like fixing indentations and finalized my pull request for approval.
One of the major changes that I made included reusing code for an existing implementation to check for a positive semidefinite matrix. Although I require a positive definite matrix, reusing the code for checking for a positive semidefinite matrix is a wise choice because, firstly, it is faster and more useful and very similar to the original problem, and secondly, the sampling is performed from the interior of the correlation matrices.
The faster method is-
// Using LDLT decomposition to check membership
// Faster than computing the largest eigenvalue with Spectra
// more numerically stable for singular matrices
bool isPositiveSemidefinite(MT const &A) const {
Eigen::LDLT<MT> A_ldlt(A);
if (A_ldlt.info() != Eigen::NumericalIssue && A_ldlt.isPositive())
return true;
return false;
}
The LDLT decomposition checks membership of the matrices.
The LDLT decomposition is a matrix factorization method that breaks down a matrix into a lower triangular matrix (L), a diagonal matrix (D), and the transpose of L. This is computationally faster than computing the largest eigenvalue, and is also more numerically stable, especially for singular matrices.
To summarize it all, the function works by first decomposing the matrix using LDLT, and after ensuring that there are no numerical issues, it checks if the matrix is positive semidefinite by confirming that all the diagonal elements are non-negative.
I made use of the above computation by simply reusing the function.
using NT = double;
using MatrixType = Eigen::Matrix<NT, Eigen::Dynamic, Eigen::Dynamic>;
EigenvaluesProblems<NT, MatrixType, Eigen::Matrix<NT, Eigen::Dynamic, 1>> solver;
if(solver.isPositiveSemidefinite(matrix))
{
return true;
}
The link to my pull request is here