Skip to content

Commit

Permalink
Merge branch 'develop' into develop_rounding_method_based_on_volumetr…
Browse files Browse the repository at this point in the history
…ic_barrier
  • Loading branch information
TolisChal committed Jul 7, 2024
2 parents 259ddc8 + f1abc36 commit ee97799
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
7 changes: 4 additions & 3 deletions examples/correlation_matrices/sampler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,11 @@ void correlation_matrix_uniform_sampling_MT(const unsigned int n, const unsigned
std::cout << "Elapsed time : " << time << " (ms)" << std::endl;

int valid_points = 0;
EigenvaluesProblems<NT, MT, Eigen::Matrix<NT, Eigen::Dynamic, 1>> solver;
for(const auto& points : randPoints){
if(is_correlation_matrix(points.mat)){
valid_points++;
}
if(solver.is_correlation_matrix(points.mat)){
valid_points++;
}
}
std::cout << "Number of valid points = " << valid_points << std::endl;

Expand Down
18 changes: 18 additions & 0 deletions include/matrix_operations/EigenvaluesProblems.h
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,24 @@ class EigenvaluesProblems<NT, Eigen::Matrix<NT,Eigen::Dynamic,Eigen::Dynamic>, E
return false;
}

/// Check if a matrix is indeed a correlation matrix
/// return true if input matrix is found to be a correlation matrix
/// |param[in] matrix
bool is_correlation_matrix(const MT& matrix, const double tol = 1e-8){

//check if all the diagonal elements are ones
for (int i=0 ; i<matrix.rows() ; i++){
if (std::abs(matrix(i, i)-1.0) > tol){
return false;
}
}

//check if the matrix is positive definite
if (isPositiveSemidefinite(matrix)) return true;

return false;
}

/// Minimum positive eigenvalue of the generalized eigenvalue problem A - lB
/// Use Eigen::GeneralizedSelfAdjointEigenSolver<MT> ges(B,A) (faster)
/// \param[in] A: symmetric positive definite matrix
Expand Down

0 comments on commit ee97799

Please sign in to comment.