Skip to content

Commit

Permalink
Add progress bar and verbose flag to lfmcmc
Browse files Browse the repository at this point in the history
  • Loading branch information
apulsipher committed Dec 12, 2024
1 parent 2062297 commit 70f0948
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
24 changes: 24 additions & 0 deletions epiworld.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1232,6 +1232,7 @@ class LFMCMC {
std::chrono::time_point<std::chrono::steady_clock> m_start_time;
std::chrono::time_point<std::chrono::steady_clock> m_end_time;

// Timing
// std::chrono::milliseconds
std::chrono::duration<epiworld_double,std::micro> m_elapsed_time =
std::chrono::duration<epiworld_double,std::micro>::zero();
Expand All @@ -1245,6 +1246,10 @@ class LFMCMC {

void chrono_start();
void chrono_end();

// Progress
bool verbose = true;
Progress progress_bar;

public:

Expand Down Expand Up @@ -1316,6 +1321,8 @@ class LFMCMC {
std::vector< epiworld_double > get_mean_stats();

// Printing
void verbose_off() { verbose = false; };
void verbose_on() { verbose = true; };
void print(size_t burnin = 0u) const;

};
Expand Down Expand Up @@ -1523,6 +1530,7 @@ class LFMCMC {
std::chrono::time_point<std::chrono::steady_clock> m_start_time;
std::chrono::time_point<std::chrono::steady_clock> m_end_time;

// Timing
// std::chrono::milliseconds
std::chrono::duration<epiworld_double,std::micro> m_elapsed_time =
std::chrono::duration<epiworld_double,std::micro>::zero();
Expand All @@ -1536,6 +1544,10 @@ class LFMCMC {

void chrono_start();
void chrono_end();

// Progress
bool verbose = true;
Progress progress_bar;

public:

Expand Down Expand Up @@ -1607,6 +1619,8 @@ class LFMCMC {
std::vector< epiworld_double > get_mean_stats();

// Printing
void verbose_off() { verbose = false; };
void verbose_on() { verbose = true; };
void print(size_t burnin = 0u) const;

};
Expand Down Expand Up @@ -1882,6 +1896,13 @@ inline void LFMCMC<TData>::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
Expand Down Expand Up @@ -1938,6 +1959,9 @@ inline void LFMCMC<TData>::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
Expand Down
7 changes: 7 additions & 0 deletions include/epiworld/math/lfmcmc/lfmcmc-bones.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ class LFMCMC {
std::chrono::time_point<std::chrono::steady_clock> m_start_time;
std::chrono::time_point<std::chrono::steady_clock> m_end_time;

// Timing
// std::chrono::milliseconds
std::chrono::duration<epiworld_double,std::micro> m_elapsed_time =
std::chrono::duration<epiworld_double,std::micro>::zero();
Expand All @@ -183,6 +184,10 @@ class LFMCMC {

void chrono_start();
void chrono_end();

// Progress
bool verbose = true;
Progress progress_bar;

public:

Expand Down Expand Up @@ -254,6 +259,8 @@ class LFMCMC {
std::vector< epiworld_double > get_mean_stats();

// Printing
void verbose_off() { verbose = false; };
void verbose_on() { verbose = true; };
void print(size_t burnin = 0u) const;

};
Expand Down
10 changes: 10 additions & 0 deletions include/epiworld/math/lfmcmc/lfmcmc-meat.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,13 @@ inline void LFMCMC<TData>::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
Expand Down Expand Up @@ -319,6 +326,9 @@ inline void LFMCMC<TData>::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
Expand Down

0 comments on commit 70f0948

Please sign in to comment.