The code I contributed in my second week of GSoC mainly consisted of
- Tweaking my previous implementation
- Making additions to an example that sampled correlation matrices
- A minor change- I changed a parameter- the ncv parameter to an empirical value.
My code uses the Spectra implementation to solve the same problem in this way-
- Setting up the problem
int matrixDim = A.rows();
NT lambdaMinPositive;
Spectra::DenseSymMatProd<NT> op(B);
Spectra::DenseCholesky<NT> Bop(A);
- Creating the Spectra solver
int ncv = std::min(std::max(10, matrixDim / 20), matrixDim);
Spectra::SymGEigsSolver<NT, Spectra::LARGEST_ALGE, Spectra::DenseSymMatProd<NT>, Spectra::DenseCholesky<NT>, Spectra::GEIGS_CHOLESKY> geigs(&op, &Bop, 1, ncv);
Computation and retrieval of the eigenvalues and the eigenvectors
geigs.init();
int nconv = geigs.compute();
if (geigs.info() == Spectra::SUCCESSFUL) {
VT evalues = geigs.eigenvalues();
eigvec = geigs.eigenvectors().col(0);
lambdaMinPositive = NT(1) / evalues(0);
}
Next, I wrote a function that took a matrix as an input and checked if it is indeed a correlation matrix. This check is crucial because it makes sure that the matrices do not move out of the boundary, and remain within the constraints. The check is quite straightforward; a correlation matrix is one that satisfies the following conditions-
- All its diagonal elements are 1
- All its eigenvalues are positive- here I made use of Eigen::SelfAdjointEigenSolver In an example C++ implementation that samples correlation matrices, I increased the dimensions of the matrices that were to be sampled from 10 to 100, in increasing steps of 10. The computation time was much larger than desirable- this brought another issue into the picture: tweaking with the parameters of the solver to reduce the computation time.
I made changes to one of the parameters- I changed it to an empirical value as given my my mentor, Apostolos Chalkis, and this led us to another TODO that I will be doing in the upcoming weeks: tuning the implementation by tuning parameters like ncv here.