diff --git a/epiworld.hpp b/epiworld.hpp index 9a258db8..68d1ad9d 100644 --- a/epiworld.hpp +++ b/epiworld.hpp @@ -19,7 +19,7 @@ /* Versioning */ #define EPIWORLD_VERSION_MAJOR 0 #define EPIWORLD_VERSION_MINOR 6 -#define EPIWORLD_VERSION_PATCH 0 +#define EPIWORLD_VERSION_PATCH 1 static const int epiworld_version_major = EPIWORLD_VERSION_MAJOR; static const int epiworld_version_minor = EPIWORLD_VERSION_MINOR; @@ -2243,7 +2243,16 @@ inline void LFMCMC::print(size_t burnin) const for (auto & n : summ_params) { - int tmp_nchar = std::floor(std::log10(std::abs(n))); + int tmp_nchar; + + if (std::abs(n) < 1) { + // std::log10(<1) will return negative number + // std::log10(0) will return -inf and throw a runtime error + tmp_nchar = 0; + } else { + tmp_nchar = std::floor(std::log10(std::abs(n))); + } + if (nchar_par_num < tmp_nchar) nchar_par_num = tmp_nchar; } @@ -2311,7 +2320,15 @@ inline void LFMCMC::print(size_t burnin) const int nchar = 0; for (auto & s : summ_stats) { - int tmp_nchar = std::floor(std::log10(std::abs(s))); + int tmp_nchar; + if (std::abs(s) < 1) { + // std::log10(<1) will return negative number + // std::log10(0) will return -inf and throw a runtime error + tmp_nchar = 0; + } else { + tmp_nchar = std::floor(std::log10(std::abs(s))); + } + if (nchar < tmp_nchar) nchar = tmp_nchar; } diff --git a/include/epiworld/epiworld.hpp b/include/epiworld/epiworld.hpp index 6483465a..52e4c148 100644 --- a/include/epiworld/epiworld.hpp +++ b/include/epiworld/epiworld.hpp @@ -19,7 +19,7 @@ /* Versioning */ #define EPIWORLD_VERSION_MAJOR 0 #define EPIWORLD_VERSION_MINOR 6 -#define EPIWORLD_VERSION_PATCH 0 +#define EPIWORLD_VERSION_PATCH 1 static const int epiworld_version_major = EPIWORLD_VERSION_MAJOR; static const int epiworld_version_minor = EPIWORLD_VERSION_MINOR; diff --git a/include/epiworld/math/lfmcmc/lfmcmc-meat-print.hpp b/include/epiworld/math/lfmcmc/lfmcmc-meat-print.hpp index 6a658ab5..c526a6c5 100755 --- a/include/epiworld/math/lfmcmc/lfmcmc-meat-print.hpp +++ b/include/epiworld/math/lfmcmc/lfmcmc-meat-print.hpp @@ -93,7 +93,16 @@ inline void LFMCMC::print(size_t burnin) const for (auto & n : summ_params) { - int tmp_nchar = std::floor(std::log10(std::abs(n))); + int tmp_nchar; + + if (std::abs(n) < 1) { + // std::log10(<1) will return negative number + // std::log10(0) will return -inf and throw a runtime error + tmp_nchar = 0; + } else { + tmp_nchar = std::floor(std::log10(std::abs(n))); + } + if (nchar_par_num < tmp_nchar) nchar_par_num = tmp_nchar; } @@ -161,7 +170,15 @@ inline void LFMCMC::print(size_t burnin) const int nchar = 0; for (auto & s : summ_stats) { - int tmp_nchar = std::floor(std::log10(std::abs(s))); + int tmp_nchar; + if (std::abs(s) < 1) { + // std::log10(<1) will return negative number + // std::log10(0) will return -inf and throw a runtime error + tmp_nchar = 0; + } else { + tmp_nchar = std::floor(std::log10(std::abs(s))); + } + if (nchar < tmp_nchar) nchar = tmp_nchar; } diff --git a/tests/00-lfmcmc.cpp b/tests/00-lfmcmc.cpp index 58d50df9..d8a6233d 100644 --- a/tests/00-lfmcmc.cpp +++ b/tests/00-lfmcmc.cpp @@ -77,6 +77,29 @@ EPIWORLD_TEST_CASE("LFMCMC", "[Basic example]") { REQUIRE_NOTHROW(model.print(50000)); #endif + // Add test of summary stats between [0, 1] + std::normal_distribution rnorm2(0.5, 0.5); + + vec_double obsdata2; + for (size_t i = 0u; i < 50000; ++i) + obsdata2.push_back(rnorm2(*rand)); + + LFMCMC< vec_double > model2(obsdata2); + model2.set_rand_engine(rand); + + model2.set_simulation_fun(simfun); + model2.set_summary_fun(summary_fun); + model2.set_proposal_fun(make_proposal_norm_reflective(.05, .0000001, 10)); + model2.set_kernel_fun(kernel_fun_gaussian); + + model2.run({1,1}, 100000, .125); + model2.print(); + + #ifdef CATCH_CONFIG_MAIN + REQUIRE_NOTHROW(model2.print()); + #endif + + #ifndef CATCH_CONFIG_MAIN return 0; #endif