Tomographer  v1.0a
Tomographer C++ Framework Documentation
Tomographer::MHRandomWalk< Rng_, MHWalker_, MHRWStatsCollector_, LoggerType_, CountIntType_ > Class Template Reference

A Metropolis-Hastings Random Walk. More...

#include <tomographer/mhrw.h>

Public Types

enum  
 
typedef Rng_ Rng
 Random number generator type (see C++ std::random)
 
typedef MHWalker_ MHWalker
 The random walker type which knows about the state space and jump function.
 
typedef MHRWStatsCollector_ MHRWStatsCollector
 The stats collector type (see MHRWStatsCollector Interface)
 
typedef LoggerType_ LoggerType
 The logger type (see Logging and Loggers)
 
typedef CountIntType_ CountIntType
 The type used for counting numbers of iterations (see, e.g. n_sweep())
 
typedef MHWalker::PointType PointType
 The type of a point in the random walk.
 
typedef MHWalker::RealScalar RealScalar
 The type of a step size of the random walk.
 
typedef _FnValueType FnValueType
 The type of the Metropolis-Hastings function value. (See class documentation)
 

Public Member Functions

 MHRandomWalk (CountIntType n_sweep, CountIntType n_therm, CountIntType n_run, RealScalar step_size, MHWalker &mhwalker, MHRWStatsCollector &stats, Rng &rng, LoggerType &logger_)
 Simple constructor, initializes the given fields.
 
CountIntType n_sweep () const
 Required for RandomWalk Interface. Number of iterations in a sweep.
 
CountIntType n_therm () const
 Required for RandomWalk Interface. Number of thermalizing sweeps.
 
CountIntType n_run () const
 Required for RandomWalk Interface. Number of live run sweeps.
 
RealScalar step_size () const
 Get the step size of the random walk.
 
void init ()
 Required for RandomWalk Interface. Resets counts and relays to the MHWalker and the MHRWStatsCollector.
 
void thermalizing_done ()
 Required for RandomWalk Interface. Relays to the MHWalker and the MHRWStatsCollector.
 
void done ()
 Required for RandomWalk Interface. Relays to the MHWalker and the MHRWStatsCollector.
 
const PointTypeget_curpt () const
 Access the current state of the random walk. More...
 
const FnValueTypeget_curptval () const
 Access the current function value of the random walk. More...
 
void set_curpt (const PointType &pt)
 Force manual state of random walk. More...
 
void move (CountIntType k, bool is_thermalizing, bool is_live_iter)
 Required for RandomWalk Interface. Processes a single move in the random walk. More...
 
bool has_acceptance_ratio () const
 Query whether we have any statistics about acceptance ratio. This is false, for example, during the thermalizing runs.
 
template<typename RatioType = double>
RatioType acceptance_ratio () const
 Return the acceptance ratio so far.
 
void process_sample (CountIntType k, CountIntType n)
 Required for RandomWalk Interface. Process a new live sample in the random walk. Relays the call to the MHRWStatsCollector (see MHRWStatsCollector Interface).
 
void run ()
 

Detailed Description

template<typename Rng_, typename MHWalker_, typename MHRWStatsCollector_, typename LoggerType_, typename CountIntType_ = unsigned int>
class Tomographer::MHRandomWalk< Rng_, MHWalker_, MHRWStatsCollector_, LoggerType_, CountIntType_ >

A Metropolis-Hastings Random Walk.

Implements a Metropolis-Hastings random walk. This takes care of accepting or rejecting a new point and taking samples.

The MHWalker is responsible for dealing with the state space, providing a new proposal point and calculating the function value at different points. See MHWalker Interface.

A MHRWStatsCollector takes care of collecting useful data during a random walk. It should be a type implementing a MHRWStatsCollector interface, see MHRWStatsCollector Interface.

Definition at line 303 of file mhrw.h.

Member Enumeration Documentation

template<typename Rng_, typename MHWalker_, typename MHRWStatsCollector_, typename LoggerType_, typename CountIntType_ = unsigned int>
anonymous enum
Enumerator
UseFnSyntaxType 

How to calculate the Metropolis-Hastings jump probability ratio (see class documentation)

Definition at line 330 of file mhrw.h.

Member Function Documentation

template<typename Rng_, typename MHWalker_, typename MHRWStatsCollector_, typename LoggerType_, typename CountIntType_ = unsigned int>
const PointType& Tomographer::MHRandomWalk< Rng_, MHWalker_, MHRWStatsCollector_, LoggerType_, CountIntType_ >::get_curpt ( ) const
inline

Access the current state of the random walk.

Returns
the current point the random walk is located at.

Definition at line 430 of file mhrw.h.

template<typename Rng_, typename MHWalker_, typename MHRWStatsCollector_, typename LoggerType_, typename CountIntType_ = unsigned int>
const FnValueType& Tomographer::MHRandomWalk< Rng_, MHWalker_, MHRWStatsCollector_, LoggerType_, CountIntType_ >::get_curptval ( ) const
inline

Access the current function value of the random walk.

Returns
the current value of the function in the current state of the random walk.
Warning
the meaning of this value depends on MHRandomWalk::UseFnSyntaxType. It is either the value of the function, its logarithm, or a dummy value.

Definition at line 442 of file mhrw.h.

template<typename Rng_, typename MHWalker_, typename MHRWStatsCollector_, typename LoggerType_, typename CountIntType_ = unsigned int>
void Tomographer::MHRandomWalk< Rng_, MHWalker_, MHRWStatsCollector_, LoggerType_, CountIntType_ >::move ( CountIntType  k,
bool  is_thermalizing,
bool  is_live_iter 
)
inline

Required for RandomWalk Interface. Processes a single move in the random walk.

This function gets a new move proposal from the MHWalker object, and calculates the a value, which tells us with which probability we should accept the move. This a value is calculated according to the documentation in Role of UseFnSyntaxType.

Definition at line 468 of file mhrw.h.

template<typename Rng_, typename MHWalker_, typename MHRWStatsCollector_, typename LoggerType_, typename CountIntType_ = unsigned int>
void Tomographer::MHRandomWalk< Rng_, MHWalker_, MHRWStatsCollector_, LoggerType_, CountIntType_ >::set_curpt ( const PointType pt)
inline

Force manual state of random walk.

This may be called to force setting the current state of the random walk to the given point pt.

Definition at line 452 of file mhrw.h.


The documentation for this class was generated from the following file: