32 #ifndef VSMC_CORE_MONITOR_HPP 33 #define VSMC_CORE_MONITOR_HPP 37 #define VSMC_RUNTIME_ASSERT_CORE_MONITOR_ID(func) \ 38 VSMC_RUNTIME_ASSERT( \ 39 (id < dim()), "**Monitor::" #func "** INVALID ID NUMBER ARGUMENT") 41 #define VSMC_RUNTIME_ASSERT_CORE_MONITOR_ITER(func) \ 42 VSMC_RUNTIME_ASSERT((iter < iter_size()), \ 43 "**Monitor::" #func "** INVALID ITERATION NUMBER ARGUMENT") 45 #define VSMC_RUNTIME_ASSERT_CORE_MONITOR_EVAL \ 46 VSMC_RUNTIME_ASSERT(static_cast<bool>(eval_), \ 47 "**Monitor::eval** INVALID EVALUATION OBJECT") 68 std::function<void(std::size_t, std::size_t, Particle<T> &,
double *)>;
82 std::size_t
dim()
const {
return dim_; }
91 std::size_t
iter_size()
const {
return index_.size(); }
97 record_.reserve(dim_ * num);
101 bool empty()
const {
return !
static_cast<bool>(eval_); }
110 std::string &
name(std::size_t
id)
118 const std::string &
name(std::size_t
id)
const 134 std::size_t
index(std::size_t iter)
const 152 return record_[iter * dim_ + id];
160 double record(std::size_t
id, std::size_t iter)
const 165 return record_[iter * dim_ + id];
169 template <
typename OutputIter>
172 std::copy(index_.begin(), index_.end(), first);
176 const std::size_t *
index_data()
const {
return index_.data(); }
186 return record_.data() + iter * dim_;
191 template <
typename OutputIter>
195 const double *riter = record_.data() + id;
196 for (std::size_t i = 0; i != N; ++i, ++first, riter += dim_)
204 template <
typename OutputIterIter>
207 for (std::size_t d = 0; d != dim_; ++d, ++first)
221 template <MatrixOrder Order,
typename OutputIter>
226 for (std::size_t d = 0; d != dim_; ++d) {
227 const double *riter = record_.data() + d;
228 for (std::size_t i = 0; i != N; ++i, ++first, riter += dim_)
234 std::copy(record_.begin(), record_.end(), first);
252 result_.resize(dim_);
254 eval_(iter, dim_, particle, result_.data());
260 const std::size_t N =
static_cast<std::size_t
>(particle.
size());
261 buffer_.resize(N * dim_);
262 eval_(iter, dim_, particle, buffer_.data());
264 particle.
weight().data(), 1, 0.0, result_.data(), 1);
296 void push_back(std::size_t iter)
298 index_.push_back(iter);
299 record_.insert(record_.end(), result_.begin(), result_.end());
305 #endif // VSMC_CORE_MONITOR_HPP bool empty() const
Whether the evaluation object is valid.
#define VSMC_RUNTIME_ASSERT_CORE_MONITOR_EVAL
void read_record(std::size_t id, OutputIter first) const
Read the record history for a given variable through an output iterator.
Particle class representing the whole particle set.
bool record_only() const
If this is a record only Monitor.
MonitorStage
Monitor stage.
void read_index(OutputIter first) const
Read the index history through an output iterator.
void clear()
Clear all records of the index and integrations.
typename std::conditional< std::is_scalar< T >::value, std::vector< T, AlignedAllocator< T >>, std::vector< T >>::type Vector
AlignedVector for scalar type and std::vector for others.
weight_type & weight()
Read and write access to the weight collection object.
void eval(std::size_t iter, Particle< T > &particle, MonitorStage stage)
Perform the evaluation for a given iteration and a Particle<T> object.
void reserve(std::size_t num)
Reserve space for a specified number of iterations.
void turn_off()
Turn off the recording.
Monitor evaluated after moves.
void turn_on()
Turn on the recording.
#define VSMC_RUNTIME_ASSERT_CORE_MONITOR_ITER(func)
void copy(std::size_t n, const T *x, std::size_t incx, T *y, std::size_t incy)
Copies vector to another vector.
Data are stored column by column in memory.
Monitor(std::size_t dim, const eval_type &eval, bool record_only=false, MonitorStage stage=MonitorMCMC)
std::size_t dim() const
The dimension of the Monitor.
void set_eval(const eval_type &new_eval)
Set a new evaluation object of type eval_type.
const std::size_t * index_data() const
Read only access to the raw data of the index vector.
void read_record_matrix(OutputIter first) const
Read the record history of all variables through an output iterator.
std::size_t iter_size() const
The number of iterations has been recorded.
const double * record_data() const
Read only access to the raw data of records (a row major matrix)
Data are stored row by row in memory.
std::string & name(std::size_t id)
Read and write access to the names of variables.
const std::string & name(std::size_t id) const
Read only access to the names of variables.
const double * record_data(std::size_t iter) const
Read only access to the raw data of records for a given Monitor iteration.
std::size_t index(std::size_t iter) const
Get the iteration index of the sampler of a given Monitor iteration.
MonitorStage stage() const
The stage of the Montior.
double record(std::size_t id) const
Get the latest Monte Carlo integration record of a given variable.
Monitor evaluated after MCMC moves.
Monitor for Monte Carlo integration.
#define VSMC_RUNTIME_ASSERT_CORE_MONITOR_ID(func)
void read_record_matrix(OutputIterIter first) const
Read the record history of all variables through an array of output iterators.
bool recording() const
Whether the Monitor is actively recording results.
size_type size() const
Number of particles.
std::function< void(std::size_t, std::size_t, Particle< T > &, double *)> eval_type
double record(std::size_t id, std::size_t iter) const
Get the Monte Carlo integration record of a given variable and the Monitor iteration.
void gemv(MatrixOrder order, MatrixTrans trans, std::size_t m, std::size_t n, T alpha, const T *A, std::size_t lda, const T *x, std::size_t incx, T beta, T *y, std::size_t incy)
Computes a matrix-vector product using a general matrix.
The matrix shall not be transposed.
Monitor evaluated after resampling.