Tomographer  v5.4
Tomographer C++ Framework Documentation
Tomographer::MHRandomWalk< Rng_, MHWalker_, MHRWStatsCollector_, MHRWController_, LoggerType_, CountIntType_ > Class Template Reference

A Metropolis-Hastings Random Walk. More...

#include <tomographer/mhrw.h>

+ Inheritance diagram for Tomographer::MHRandomWalk< Rng_, MHWalker_, MHRWStatsCollector_, MHRWController_, LoggerType_, CountIntType_ >:
+ Collaboration diagram for Tomographer::MHRandomWalk< Rng_, MHWalker_, MHRWStatsCollector_, MHRWController_, LoggerType_, CountIntType_ >:

Public Types

enum  
 
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 which will be provided by user to constructor (see Logging and Loggers)
 
typedef CountIntType_ CountIntType
 The type used for counting numbers of iterations (see, e.g. nSweep() or MHRWParams)
 
typedef MHWalker::PointType PointType
 The type of a point in the random walk.
 
typedef MHWalker::WalkerParams MHWalkerParams
 The parameters type of the MHWalker implememtation, typically just a double storing the step size of the random walk.
 
typedef MHRWParams< MHWalkerParams, CountIntTypeMHRWParamsType
 The struct which can hold the parameters of this random walk.
 
typedef MHRWController_ MHRWController
 The type which will take care of dynamically adjusting the parameters of the random walk.
 
typedef MHRWControllerInvoker< MHRWControllerMHRWControllerInvokerType
 The MHRWControllerInvoker for our random walk controller, for convenience.
 
typedef _FnValueType FnValueType
 The type of the Metropolis-Hastings function value. (See class documentation)
 

Public Member Functions

 MHRandomWalk (MHWalkerParams mhwalker_params, CountIntType n_sweep, CountIntType n_therm, CountIntType n_run, MHWalker &mhwalker, MHRWStatsCollector &stats, MHRWController &mhrw_controller, Rng &rng, LoggerType &logger_)
 Simple constructor, initializes the given fields.
 
template<typename MHRWParamsTypeInit >
 MHRandomWalk (MHRWParamsTypeInit &&n_rw, MHWalker &mhwalker, MHRWStatsCollector &stats, MHRWController &mhrw_controller, Rng &rng, LoggerType &logger_)
 Simple constructor, initializes the given fields.
 
 MHRandomWalk (const MHRandomWalk &other)=delete
 
const MHRWStatsCollectorstatsCollector () const
 Access the stats collector.
 
const MHRWControllermhrwController () const
 Access the random walk controller.
 
MHRWParamsType mhrwParams () const
 The parameters of the random walk.
 
MHWalkerParams mhWalkerParams () const
 Get the MHWalker parameters.
 
CountIntType nSweep () const
 Number of iterations in a sweep.
 
CountIntType nTherm () const
 Number of thermalizing sweeps.
 
CountIntType nRun () const
 Number of live run sweeps.
 
bool hasAcceptanceRatio () const
 Query whether we have any statistics about acceptance ratio. This is false, for example, during the thermalizing runs.
 
template<typename RatioType = double>
RatioType acceptanceRatio () const
 Return the acceptance ratio so far.
 
const PointTypegetCurrentPoint () const
 Access the current state of the random walk. More...
 
const FnValueTypegetCurrentPointValue () const
 Access the current function value of the random walk. More...
 
void setCurrentPoint (const PointType &pt)
 Force manual state of random walk. More...
 
void run ()
 Run the random walk. (pun intended) More...
 

Detailed Description

template<typename Rng_, typename MHWalker_, typename MHRWStatsCollector_, typename MHRWController_ = MHRWNoController, typename LoggerType_ = Logger::VacuumLogger, typename CountIntType_ = int>
class Tomographer::MHRandomWalk< Rng_, MHWalker_, MHRWStatsCollector_, MHRWController_, 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.

This class takes care to update the state of a random walk for it to perform thermalizing sweeps, followed by "live" runs.

The random walk is composed of iterations. There are n_sweep iterations per "sweep". This number should be approximately chosen such that step_size * n_sweep is of order of the size of the state space. (This is in order to better decorrelate the samples.)

Initially, a number n_therm of thermalizing sweeps are performed. No samples are taken during this period, and this is meant for a Metropolis random walk to find its "valley".

After the thermalizing runs, a number of run sweeps are performed, in which a live sample is taken at the last iteration of each sweep.

Since
Since Tomographer 5.0: added MHRWController.
Template Parameters
Rngis a C++ random number generator (for example, std::mt19937)
MHWalkeris responsible for dealing with the state space, providing a new proposal point and calculating the function value at different points. See MHWalker Interface.
MHRWStatsCollectortakes care of collecting useful data during a random walk. It should be a type implementing a MHRWStatsCollector interface, see MHRWStatsCollector Interface.
MHRWControllera MHRWController Interface compliant type which may dynamically adjust the parameters of the random walker. Just specify MHRWNoController if you don't need the parameters to be dynamically adjusted.
LoggerTypeis a logger type to which log messages can be generated (see Logging and Loggers)
CountIntTypeis an integer type used to count the number of iterations. You'll want to use int here, unless you really want to pursue exceptionally long random walks.

Definition at line 643 of file mhrw.h.

Member Enumeration Documentation

§ anonymous enum

template<typename Rng_ , typename MHWalker_ , typename MHRWStatsCollector_ , typename MHRWController_ = MHRWNoController, typename LoggerType_ = Logger::VacuumLogger, typename CountIntType_ = int>
anonymous enum
Enumerator
UseFnSyntaxType 

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

Definition at line 683 of file mhrw.h.

Member Function Documentation

§ getCurrentPoint()

template<typename Rng_ , typename MHWalker_ , typename MHRWStatsCollector_ , typename MHRWController_ = MHRWNoController, typename LoggerType_ = Logger::VacuumLogger, typename CountIntType_ = int>
const PointType& Tomographer::MHRandomWalk< Rng_, MHWalker_, MHRWStatsCollector_, MHRWController_, LoggerType_, CountIntType_ >::getCurrentPoint ( ) const
inline

Access the current state of the random walk.

Returns
the current point the random walk is located at.

Definition at line 806 of file mhrw.h.

§ getCurrentPointValue()

template<typename Rng_ , typename MHWalker_ , typename MHRWStatsCollector_ , typename MHRWController_ = MHRWNoController, typename LoggerType_ = Logger::VacuumLogger, typename CountIntType_ = int>
const FnValueType& Tomographer::MHRandomWalk< Rng_, MHWalker_, MHRWStatsCollector_, MHRWController_, LoggerType_, CountIntType_ >::getCurrentPointValue ( ) 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 818 of file mhrw.h.

§ run()

template<typename Rng_ , typename MHWalker_ , typename MHRWStatsCollector_ , typename MHRWController_ = MHRWNoController, typename LoggerType_ = Logger::VacuumLogger, typename CountIntType_ = int>
void Tomographer::MHRandomWalk< Rng_, MHWalker_, MHRWStatsCollector_, MHRWController_, LoggerType_, CountIntType_ >::run ( )
inline

Run the random walk. (pun intended)

This will take care of the full random walk. The specified number of thermalizing sweeps will be run, followed by a number of "live" sweeps where one sample is taken per sweep.

Definition at line 1053 of file mhrw.h.

§ setCurrentPoint()

template<typename Rng_ , typename MHWalker_ , typename MHRWStatsCollector_ , typename MHRWController_ = MHRWNoController, typename LoggerType_ = Logger::VacuumLogger, typename CountIntType_ = int>
void Tomographer::MHRandomWalk< Rng_, MHWalker_, MHRWStatsCollector_, MHRWController_, LoggerType_, CountIntType_ >::setCurrentPoint ( 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 828 of file mhrw.h.


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