Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add spectra routine for minPosLinearEigenvalue_EigenSymSolver #303

Merged
merged 6 commits into from
Jun 6, 2024
Merged

add spectra routine for minPosLinearEigenvalue_EigenSymSolver #303

merged 6 commits into from
Jun 6, 2024

Conversation

atrayees
Copy link
Contributor

I added the spectra routine for minPosLinearEigenvalue_EigenSymSolver in volesti/include/matrix_operations/EigenvaluesProblems.h

Spectra::DenseCholesky<NT> Bop(B);

//construct generalized eigen solver object, requesting the smallest eigenvalue
Spectra::SymGEigsSolver<NT, Spectra::SMALLEST_ALGE, Spectra::DenseSymMatProd<NT>, Spectra::DenseCholesky<NT>, Spectra::GEIGS_CHOLESKY>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need the largest eigenvalue here, i.e., Spectra::LARGEST_ALGE.

eigvec = geigs.eigenvectors().col(0);
}

lambdaMinPositive = evalues(0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we compute the largest eigenvalue here we need lambdaMinPositive = NT(1) / evalues(0); to obtain the smallest positive eigenvalue.

Comment on lines 446 to 447
Spectra::DenseSymMatProd<NT> op(A);
Spectra::DenseCholesky<NT> Bop(B);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The matrix A is the correlation matrix (the positive definite matrix). So, I guess the correct operations are:
Spectra::DenseSymMatProd op(B);
Spectra::DenseCholesky Bop(A);

We initially want to compute the smallest positive eigenvalue of the GEP, A = tB. So, here we need to compute the largest eigenvalue of the GEP, tA = B and invert it. That's why the operations has to be as above.


//check if all the diagonal elements are ones
for(int i=0 ; i<matrix.rows() ; i++){
if(matrix(i,i) != 1.0){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you do an epsilon-equality check here?
For example if (std::abs(matrix(i,i) - 1.0) > tol)
where const tol = 1e-08.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I can, thanks for this! I will make the changes.

if(eigen_solver.info() != Eigen::Success) return false;

//the matrix is positive definite if all eigenvalues are positive
return eigen_solver.eigenvalues().minCoeff() > 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here as above.

if(eigen_solver.info() != Eigen::Success) return false;

//the matrix is positive definite if all eigenvalues are positive
return eigen_solver.eigenvalues().minCoeff() > tol;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's better to check return eigen_solver.eigenvalues().minCoeff() > -tol;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay yes, that sounds better! I'll incorporate this change

write_to_file<PointMT>(walkname + "_matrices_MT.txt", randPoints);

//write_to_file<PointMT>(walkname + "_matrices_MT.txt", randPoints);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we delete this line?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we should delete this line

@@ -12,7 +12,7 @@
#define RANDOM_WALKS_UNIFORM_BILLIARD_WALK_HPP

#include <Eigen/Eigen>

#include <iostream>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you maybe forget to delete it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I'm sorry for this- I deleted it just now

header not required.
@TolisChal TolisChal merged commit 9a6676a into GeomScale:develop Jun 6, 2024
25 of 27 checks passed
vissarion added a commit that referenced this pull request Jun 7, 2024
vissarion added a commit that referenced this pull request Jun 7, 2024
@vissarion
Copy link
Member

Sorry for reverting this, but I would like to ask for one more review before merging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants