aboutsummaryrefslogtreecommitdiff
path: root/src/debug.cpp
diff options
context:
space:
mode:
authorPjotr Prins2017-08-22 07:56:07 +0000
committerPjotr Prins2017-08-22 08:01:50 +0000
commit99527865c00b74a3a48daa2e1e5eb7c71bd861b5 (patch)
tree313f36729cc5f0e860d4c73f26ddbee5cff0bf4f /src/debug.cpp
parentc7cbd8b2d5a06b7b86733719315f9da1638cb32e (diff)
downloadpangemma-99527865c00b74a3a48daa2e1e5eb7c71bd861b5.tar.gz
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)
Diffstat (limited to 'src/debug.cpp')
-rw-r--r--src/debug.cpp27
1 files changed, 21 insertions, 6 deletions
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);
}
}