Skip to content

Commit 15842ee

Browse files
committed
Add latest changes from C++ library
1 parent 73ae16b commit 15842ee

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

Diff for: inst/include/epiworld/math/lfmcmc/lfmcmc-meat-print.hpp

+10-6
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,18 @@ template<typename TData>
55
inline void LFMCMC<TData>::print(size_t burnin) const
66
{
77

8+
// For each statistic or parameter in the model, we print three values:
9+
// - mean, the 2.5% quantile, and the 97.5% quantile
810
std::vector< epiworld_double > summ_params(n_parameters * 3, 0.0);
911
std::vector< epiworld_double > summ_stats(n_statistics * 3, 0.0);
1012

13+
// Compute the number of samples to use based on burnin rate
1114
size_t n_samples_print = n_samples;
1215
if (burnin > 0)
1316
{
1417
if (burnin >= n_samples)
1518
throw std::length_error(
16-
"The burnin is greater than the number of samples."
19+
"The burnin is greater than or equal to the number of samples."
1720
);
1821

1922
n_samples_print = n_samples - burnin;
@@ -24,15 +27,16 @@ inline void LFMCMC<TData>::print(size_t burnin) const
2427
n_samples_print
2528
);
2629

30+
// Compute parameter summary values
2731
for (size_t k = 0u; k < n_parameters; ++k)
2832
{
2933

3034
// Retrieving the relevant parameter
3135
std::vector< epiworld_double > par_i(n_samples_print);
3236
for (size_t i = burnin; i < n_samples; ++i)
3337
{
34-
par_i[i] = accepted_params[i * n_parameters + k];
35-
summ_params[k * 3] += par_i[i]/n_samples_dbl;
38+
par_i[i-burnin] = accepted_params[i * n_parameters + k];
39+
summ_params[k * 3] += par_i[i-burnin]/n_samples_dbl;
3640
}
3741

3842
// Computing the 95% Credible interval
@@ -45,20 +49,20 @@ inline void LFMCMC<TData>::print(size_t burnin) const
4549

4650
}
4751

52+
// Compute statistics summary values
4853
for (size_t k = 0u; k < n_statistics; ++k)
4954
{
5055

5156
// Retrieving the relevant parameter
5257
std::vector< epiworld_double > stat_k(n_samples_print);
5358
for (size_t i = burnin; i < n_samples; ++i)
5459
{
55-
stat_k[i] = accepted_stats[i * n_statistics + k];
56-
summ_stats[k * 3] += stat_k[i]/n_samples_dbl;
60+
stat_k[i-burnin] = accepted_stats[i * n_statistics + k];
61+
summ_stats[k * 3] += stat_k[i-burnin]/n_samples_dbl;
5762
}
5863

5964
// Computing the 95% Credible interval
6065
std::sort(stat_k.begin(), stat_k.end());
61-
6266
summ_stats[k * 3 + 1u] =
6367
stat_k[std::floor(.025 * n_samples_dbl)];
6468
summ_stats[k * 3 + 2u] =

0 commit comments

Comments
 (0)