aboutsummaryrefslogtreecommitdiff
path: root/src/debug.cpp
diff options
context:
space:
mode:
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);
}
}