@@ -5,15 +5,18 @@ template<typename TData>
5
5
inline void LFMCMC<TData>::print(size_t burnin) const
6
6
{
7
7
8
+ // For each statistic or parameter in the model, we print three values:
9
+ // - mean, the 2.5% quantile, and the 97.5% quantile
8
10
std::vector< epiworld_double > summ_params (n_parameters * 3 , 0.0 );
9
11
std::vector< epiworld_double > summ_stats (n_statistics * 3 , 0.0 );
10
12
13
+ // Compute the number of samples to use based on burnin rate
11
14
size_t n_samples_print = n_samples;
12
15
if (burnin > 0 )
13
16
{
14
17
if (burnin >= n_samples)
15
18
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."
17
20
);
18
21
19
22
n_samples_print = n_samples - burnin;
@@ -24,15 +27,16 @@ inline void LFMCMC<TData>::print(size_t burnin) const
24
27
n_samples_print
25
28
);
26
29
30
+ // Compute parameter summary values
27
31
for (size_t k = 0u ; k < n_parameters; ++k)
28
32
{
29
33
30
34
// Retrieving the relevant parameter
31
35
std::vector< epiworld_double > par_i (n_samples_print);
32
36
for (size_t i = burnin; i < n_samples; ++i)
33
37
{
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;
36
40
}
37
41
38
42
// Computing the 95% Credible interval
@@ -45,20 +49,20 @@ inline void LFMCMC<TData>::print(size_t burnin) const
45
49
46
50
}
47
51
52
+ // Compute statistics summary values
48
53
for (size_t k = 0u ; k < n_statistics; ++k)
49
54
{
50
55
51
56
// Retrieving the relevant parameter
52
57
std::vector< epiworld_double > stat_k (n_samples_print);
53
58
for (size_t i = burnin; i < n_samples; ++i)
54
59
{
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;
57
62
}
58
63
59
64
// Computing the 95% Credible interval
60
65
std::sort (stat_k.begin (), stat_k.end ());
61
-
62
66
summ_stats[k * 3 + 1u ] =
63
67
stat_k[std::floor (.025 * n_samples_dbl)];
64
68
summ_stats[k * 3 + 2u ] =
0 commit comments