Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add progress bar and verbose flag to lfmcmc #43

Merged
merged 2 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 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
LFMCMC<TData> & verbose_off();
LFMCMC<TData> & verbose_on();
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
LFMCMC<TData> & verbose_off();
LFMCMC<TData> & verbose_on();
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 Expand Up @@ -2412,6 +2436,20 @@ inline std::vector< epiworld_double > LFMCMC<TData>::get_mean_stats()

}

template<typename TData>
inline LFMCMC<TData> & LFMCMC<TData>::verbose_off()
{
verbose = false;
return *this;
}

template<typename TData>
inline LFMCMC<TData> & LFMCMC<TData>::verbose_on()
{
verbose = true;
return *this;
}

#endif
/*//////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
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
LFMCMC<TData> & verbose_off();
LFMCMC<TData> & verbose_on();
void print(size_t burnin = 0u) const;

};
Expand Down
24 changes: 24 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 Expand Up @@ -544,4 +554,18 @@ inline std::vector< epiworld_double > LFMCMC<TData>::get_mean_stats()

}

template<typename TData>
inline LFMCMC<TData> & LFMCMC<TData>::verbose_off()
{
verbose = false;
return *this;
}

template<typename TData>
inline LFMCMC<TData> & LFMCMC<TData>::verbose_on()
{
verbose = true;
return *this;
}

#endif
Loading