vSMC  v3.0.0
Scalable Monte Carlo
Public Types | Public Member Functions | List of all members
vsmc::Monitor< T > Class Template Reference

Monitor for Monte Carlo integration. More...

#include <vsmc/core/monitor.hpp>

Public Types

using eval_type = std::function< void(std::size_t, std::size_t, Particle< T > &, double *)>
 

Public Member Functions

 Monitor (std::size_t dim, const eval_type &eval, bool record_only=false, MonitorStage stage=MonitorMCMC)
 
void clear ()
 Clear all records of the index and integrations. More...
 
std::size_t dim () const
 The dimension of the Monitor. More...
 
bool empty () const
 Whether the evaluation object is valid. More...
 
void eval (const eval_type &new_eval, bool record_only=false, MonitorStage stage=MonitorMCMC)
 Set a new evaluation object of type eval_type. More...
 
std::size_t index () const
 Get the latest iteration index of the sampler. More...
 
std::size_t index (std::size_t iter) const
 Get the iteration index of the sampler of a given Monitor iteration. More...
 
std::size_t iter_size () const
 The number of iterations has been recorded. More...
 
std::string & name (std::size_t id)
 Read and write access to the names of variables. More...
 
const std::string & name (std::size_t id) const
 Read only access to the names of variables. More...
 
void operator() (std::size_t iter, Particle< T > &particle, MonitorStage stage)
 Perform the evaluation for a given iteration and a Particle<T> object. More...
 
template<typename OutputIter >
OutputIter read_index (OutputIter first) const
 Read the index history through an output iterator. More...
 
template<typename OutputIter >
OutputIter read_record (std::size_t id, OutputIter first) const
 Read the record history for a given variable through an output iterator. More...
 
template<typename OutputIter >
OutputIter read_record_matrix (MatrixLayout layout, OutputIter first) const
 Read the record history of all variables as a matrix through an output iterator. More...
 
double record (std::size_t id) const
 Get the latest Monte Carlo integration record of a given variable. More...
 
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. More...
 
bool record_only () const
 If this is a record only Monitor. More...
 
void reserve (std::size_t num)
 Reserve space for a specified number of iterations. More...
 
MonitorStage stage () const
 The stage of the Montior. More...
 
std::map< std::string, Vector< double > > summary () const
 Summary of monitor history. More...
 

Detailed Description

template<typename T>
class vsmc::Monitor< T >

Monitor for Monte Carlo integration.

Definition at line 62 of file monitor.hpp.

Member Typedef Documentation

template<typename T>
using vsmc::Monitor< T >::eval_type = std::function<void(std::size_t, std::size_t, Particle<T> &, double *)>

Definition at line 66 of file monitor.hpp.

Constructor & Destructor Documentation

template<typename T>
vsmc::Monitor< T >::Monitor ( std::size_t  dim,
const eval_type eval,
bool  record_only = false,
MonitorStage  stage = MonitorMCMC 
)
inline

Definition at line 68 of file monitor.hpp.

Member Function Documentation

template<typename T>
void vsmc::Monitor< T >::clear ( )
inline

Clear all records of the index and integrations.

Definition at line 269 of file monitor.hpp.

template<typename T>
std::size_t vsmc::Monitor< T >::dim ( ) const
inline

The dimension of the Monitor.

Definition at line 80 of file monitor.hpp.

template<typename T>
bool vsmc::Monitor< T >::empty ( ) const
inline

Whether the evaluation object is valid.

Definition at line 99 of file monitor.hpp.

template<typename T>
void vsmc::Monitor< T >::eval ( const eval_type new_eval,
bool  record_only = false,
MonitorStage  stage = MonitorMCMC 
)
inline

Set a new evaluation object of type eval_type.

Definition at line 230 of file monitor.hpp.

template<typename T>
std::size_t vsmc::Monitor< T >::index ( ) const
inline

Get the latest iteration index of the sampler.

Definition at line 124 of file monitor.hpp.

template<typename T>
std::size_t vsmc::Monitor< T >::index ( std::size_t  iter) const
inline

Get the iteration index of the sampler of a given Monitor iteration.

For example, if a Monitor is only added to the sampler at the sampler's iteration siter. Then index(0) will be siter and so on. If the Monitor is added before the sampler's initialization and continued to be evaluated during the iterations without calling turnoff(), then iter(iter) shall just be iter.

Definition at line 141 of file monitor.hpp.

template<typename T>
std::size_t vsmc::Monitor< T >::iter_size ( ) const
inline

The number of iterations has been recorded.

Definition at line 89 of file monitor.hpp.

template<typename T>
std::string& vsmc::Monitor< T >::name ( std::size_t  id)
inline

Read and write access to the names of variables.

By default, each variable of a Monitor is unnamed and the returned string is empty. However, the user can selectively set the names of each variable. This effect how Sampler will print the headers of the summary table.

Definition at line 108 of file monitor.hpp.

template<typename T>
const std::string& vsmc::Monitor< T >::name ( std::size_t  id) const
inline

Read only access to the names of variables.

Definition at line 116 of file monitor.hpp.

template<typename T>
void vsmc::Monitor< T >::operator() ( std::size_t  iter,
Particle< T > &  particle,
MonitorStage  stage 
)
inline

Perform the evaluation for a given iteration and a Particle<T> object.

Definition at line 240 of file monitor.hpp.

template<typename T>
template<typename OutputIter >
OutputIter vsmc::Monitor< T >::read_index ( OutputIter  first) const
inline

Read the index history through an output iterator.

Definition at line 150 of file monitor.hpp.

template<typename T>
template<typename OutputIter >
OutputIter vsmc::Monitor< T >::read_record ( std::size_t  id,
OutputIter  first 
) const
inline

Read the record history for a given variable through an output iterator.

Definition at line 179 of file monitor.hpp.

template<typename T>
template<typename OutputIter >
OutputIter vsmc::Monitor< T >::read_record_matrix ( MatrixLayout  layout,
OutputIter  first 
) const
inline

Read the record history of all variables as a matrix through an output iterator.

Definition at line 194 of file monitor.hpp.

template<typename T>
double vsmc::Monitor< T >::record ( std::size_t  id) const
inline

Get the latest Monte Carlo integration record of a given variable.

Definition at line 157 of file monitor.hpp.

template<typename T>
double vsmc::Monitor< T >::record ( std::size_t  id,
std::size_t  iter 
) const
inline

Get the Monte Carlo integration record of a given variable and the Monitor iteration.

Definition at line 168 of file monitor.hpp.

template<typename T>
bool vsmc::Monitor< T >::record_only ( ) const
inline

If this is a record only Monitor.

Definition at line 83 of file monitor.hpp.

template<typename T>
void vsmc::Monitor< T >::reserve ( std::size_t  num)
inline

Reserve space for a specified number of iterations.

Definition at line 92 of file monitor.hpp.

template<typename T>
MonitorStage vsmc::Monitor< T >::stage ( ) const
inline

The stage of the Montior.

Definition at line 86 of file monitor.hpp.

template<typename T>
std::map<std::string, Vector<double> > vsmc::Monitor< T >::summary ( ) const
inline

Summary of monitor history.

Definition at line 209 of file monitor.hpp.