32 #ifndef MCKL_CORE_SAMPLER_HPP 33 #define MCKL_CORE_SAMPLER_HPP 45 template <
typename Derived>
55 for (
auto &est : estimator_) {
65 for (
auto &
eval : eval_) {
68 for (
auto &est : estimator_) {
76 for (
auto &est : estimator_) {
84 template <
typename T, MatrixLayout Layout>
87 const std::size_t nrow =
88 static_cast<const Derived *
>(
this)->num_iter();
91 for (
auto &est : estimator_) {
98 if (nrow * ncol == 0) {
103 for (std::size_t i = 0; i != nrow; ++i) {
105 for (
auto &est : estimator_) {
106 for (
auto &e : est) {
107 first = std::copy(e.row_begin(i), e.row_end(i), first);
113 for (
auto &est : estimator_) {
114 for (
auto &e : est) {
115 for (std::size_t j = 0; j != e.dim(); ++j) {
116 first = std::copy(e.col_begin(j), e.col_end(j), first);
129 template <
typename CharT,
typename Traits>
130 std::basic_ostream<CharT, Traits> &
print(
131 std::basic_ostream<CharT, Traits> &os,
char sepchar =
' ')
const 133 const auto mat = summary<double, RowMajor>();
134 const std::size_t n = mat.nrow();
135 const std::size_t m = mat.ncol();
137 if (!os || n * m == 0) {
142 for (std::size_t i = 0; i != n; ++i) {
143 for (std::size_t j = 0; j != m; ++j) {
144 os << *v++ << sepchar;
153 template <
typename CharT,
typename Traits>
157 return sampler.
print(os);
161 Sampler(std::size_t steps) : num_iter_(0), eval_(steps), estimator_(steps)
169 return eval_.at(step);
174 return estimator_.at(step);
179 return estimator_.at(step);
182 template <
typename Eval>
184 std::enable_if_t<!std::is_integral<Eval>::value> * =
nullptr)
186 eval_.at(step).push_back(std::forward<Eval>(
eval));
188 return eval_.at(step).size() - 1;
193 return eval_.at(step).at(k);
198 return eval_.at(step).at(k);
201 template <
typename Estimator>
203 std::enable_if_t<!std::is_integral<Estimator>::value> * =
nullptr)
205 estimator_.at(step).push_back(std::forward<Estimator>(
estimator));
207 return estimator_.at(step).size() - 1;
212 return estimator_.at(step).at(k);
217 return estimator_.at(step).at(k);
221 std::size_t num_iter_;
228 #endif // MCKL_CORE_SAMPLER_HPP
typename SamplerTrait< MCMCSampler< T, U > >::eval_type eval_type
std::vector< T, Alloc > Vector
std::vector with Allocator as the default allocator
Sampler for iterative Monte Carlo algorithms.
estimator_type & estimator(std::size_t step, std::size_t k)
Vector< eval_type > & eval(std::size_t step)
const eval_type & eval(std::size_t step, std::size_t k) const
Vector< estimator_type > & estimator(std::size_t step)
pointer row_data(size_type i)
Pointer to the first element of a row.
pointer col_data(size_type j)
Pointer to the beginning of a column.
void reset()
Remove all evaluation and estimation methods.
typename SamplerTrait< MCMCSampler< T, U > >::estimator_type estimator_type
friend std::basic_ostream< CharT, Traits > & operator<<(std::basic_ostream< CharT, Traits > &os, const Sampler< Derived > &sampler)
Output the summary mtrix through an output stream.
eval_type & eval(std::size_t step, std::size_t k)
Matrix< T, Layout > summary() const
Return a combined matrix of all estimates.
std::size_t eval(std::size_t step, Eval &&eval, std::enable_if_t<!std::is_integral< Eval >::value > *=nullptr)
void reserve(std::size_t n)
Reserve space for additional iterations.
void clear()
Clear all estimator histories.
const estimator_type & estimator(std::size_t step, std::size_t k) const
const Vector< estimator_type > & estimator(std::size_t step) const
Estimator for iterative Monte Carlo algorithms.
std::size_t estimator(std::size_t step, Estimator &&estimator, std::enable_if_t<!std::is_integral< Estimator >::value > *=nullptr)
Sampler(std::size_t steps)
const Vector< eval_type > & eval(std::size_t step) const
std::basic_ostream< CharT, Traits > & print(std::basic_ostream< CharT, Traits > &os, char sepchar=' ') const
Print the summary matrix in textual form.