Skip to content

Commit

Permalink
Update with latest from C++ library
Browse files Browse the repository at this point in the history
  • Loading branch information
apulsipher committed Dec 12, 2024
1 parent 6c6568d commit 167895e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
7 changes: 7 additions & 0 deletions inst/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 inst/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

0 comments on commit 167895e

Please sign in to comment.