From 167895ed55c44253001654ff14997ba6caae6630 Mon Sep 17 00:00:00 2001 From: Andrew Pulsipher Date: Thu, 12 Dec 2024 10:27:36 -0700 Subject: [PATCH] Update with latest from C++ library --- .../epiworld/math/lfmcmc/lfmcmc-bones.hpp | 7 ++++++ .../epiworld/math/lfmcmc/lfmcmc-meat.hpp | 24 +++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/inst/include/epiworld/math/lfmcmc/lfmcmc-bones.hpp b/inst/include/epiworld/math/lfmcmc/lfmcmc-bones.hpp index 4ec81cc..ace7b63 100755 --- a/inst/include/epiworld/math/lfmcmc/lfmcmc-bones.hpp +++ b/inst/include/epiworld/math/lfmcmc/lfmcmc-bones.hpp @@ -170,6 +170,7 @@ class LFMCMC { std::chrono::time_point m_start_time; std::chrono::time_point m_end_time; + // Timing // std::chrono::milliseconds std::chrono::duration m_elapsed_time = std::chrono::duration::zero(); @@ -183,6 +184,10 @@ class LFMCMC { void chrono_start(); void chrono_end(); + + // Progress + bool verbose = true; + Progress progress_bar; public: @@ -254,6 +259,8 @@ class LFMCMC { std::vector< epiworld_double > get_mean_stats(); // Printing + LFMCMC & verbose_off(); + LFMCMC & verbose_on(); void print(size_t burnin = 0u) const; }; diff --git a/inst/include/epiworld/math/lfmcmc/lfmcmc-meat.hpp b/inst/include/epiworld/math/lfmcmc/lfmcmc-meat.hpp index a44b6f0..c4f68f4 100755 --- a/inst/include/epiworld/math/lfmcmc/lfmcmc-meat.hpp +++ b/inst/include/epiworld/math/lfmcmc/lfmcmc-meat.hpp @@ -263,6 +263,13 @@ inline void LFMCMC::run( for (size_t k = 0u; k < m_n_params; ++k) m_accepted_params[k] = m_initial_params[k]; + // Init progress bar + progress_bar = Progress(m_n_samples, 80); + if (verbose) { + progress_bar.next(); + } + + // Run LFMCMC for (size_t i = 1u; i < m_n_samples; ++i) { // Step 1: Generate a proposal and store it in m_current_params @@ -319,6 +326,9 @@ inline void LFMCMC::run( for (size_t k = 0u; k < m_n_params; ++k) m_accepted_params[i * m_n_params + k] = m_previous_params[k]; + if (verbose) { + progress_bar.next(); + } } // End timing @@ -544,4 +554,18 @@ inline std::vector< epiworld_double > LFMCMC::get_mean_stats() } +template +inline LFMCMC & LFMCMC::verbose_off() +{ + verbose = false; + return *this; +} + +template +inline LFMCMC & LFMCMC::verbose_on() +{ + verbose = true; + return *this; +} + #endif \ No newline at end of file