From 99527865c00b74a3a48daa2e1e5eb7c71bd861b5 Mon Sep 17 00:00:00 2001 From: Pjotr Prins Date: Tue, 22 Aug 2017 07:56:07 +0000 Subject: Fixes matrix checks - looking saner now - Matrix checks as described in https://github.com/genetics-statistics/GEMMA/issues/72 - introduces -strict switch which will exit on certain conditions - zero small eigenvalues in EigenDecomp_Zeroed which also checks for negative values - commented out float versions of functions in lapack.cpp (pre-removal) - reverted on disabled regression tests (GEMMA shows its previous behaviour now) --- src/debug.cpp | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) (limited to 'src/debug.cpp') diff --git a/src/debug.cpp b/src/debug.cpp index 4e37538..da0d06f 100644 --- a/src/debug.cpp +++ b/src/debug.cpp @@ -19,12 +19,27 @@ #include "mathfunc.h" // Helper function called by macro validate_K(K, check) -void do_validate_K(const gsl_matrix *K, bool do_check, const char *__file, int __line) { +void do_validate_K(const gsl_matrix *K, bool do_check, bool strict, const char *__file, int __line) { if (do_check) { - debug_msg("Validating K"); - if (!checkMatrixEigen(K)) warning_at_msg(__file,__line,"K has small or negative eigenvalues!"); - if (!isMatrixIllConditioned(K)) warning_at_msg(__file,__line,"K is ill conditioned!") if (!isMatrixSymmetric(K)) fail_at_msg(__file,__line,"K is not symmetric!" ); - if (!isMatrixPositiveDefinite(K)) fail_at_msg(__file,__line,"K is not positive definite!"); -; + // debug_msg("Validating K"); + auto eigenvalues = getEigenValues(K); + uint count_small; + if (count_small = count_small_values(eigenvalues,EIGEN_MINVALUE)>1) { + std::string msg = "K has "; + msg += std::to_string(count_small); + msg += " eigenvalues close to zero"; + warning_at_msg(__file,__line,msg); + } + if (!isMatrixIllConditioned(eigenvalues)) + warning_at_msg(__file,__line,"K is ill conditioned!"); + if (!isMatrixSymmetric(K)) + fail_at_msg(strict,__file,__line,"K is not symmetric!" ); + bool negative_values; + if (negative_values = has_negative_values_but_one(eigenvalues)) { + warning_at_msg(__file,__line,"K has more than one negative eigenvalues!"); + } + if (count_small>=0 && negative_values && !isMatrixPositiveDefinite(K)) + fail_at_msg(strict,__file,__line,"K is not positive definite!"); + gsl_vector_free(eigenvalues); } } -- cgit v1.2.3