KJB
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Types | Public Member Functions | Protected Member Functions | List of all members
Abstract_sampler< Model > Class Template Referenceabstract

#include <sample_sampler.h>

Inheritance diagram for Abstract_sampler< Model >:
Multi_step_sampler< Model > Single_step_sampler< Model > Annealing_sampler< Model >

Public Types

typedef Sampler_step< Model >::Type Step
 
typedef Model Model_type
 

Public Member Functions

 Abstract_sampler (const Model &initial_state, double initial_log_target)
 
 BOOST_CONCEPT_ASSERT ((BaseModel< Model >))
 
virtual void run (int num_iterations)
 Runs the sampler. This function runs the sampler for the indicated number of iterations. At each iteration it chooses a sampler step using choose_step() and invokes it using its operator(). The best model is saved and returned. More...
 
Model & current_state ()
 
const Model & current_state () const
 
double current_log_target () const
 
template<class Recorder >
void add_recorder (Recorder r)
 
template<class Recorder >
void add_recorder (Recorder *r)
 
template<class Callback >
void add_record_callback (Callback cb)
 
template<class Recorder >
const Recorder & get_recorder (size_t i) const
 
void if_accept (const Callback &cb)
 
void if_reject (const Callback &cb)
 
void on_accept (const Callback &cb)
 
void on_reject (const Callback &cb)
 

Protected Member Functions

virtual const Stepchoose_step () const =0
 Chooses a sampler step. Pure virtual method, should be overwritten. More...
 

Detailed Description

template<typename Model>
class Abstract_sampler< Model >

Template Parameters
ModelThe model type. Must comply with BaseModel concept.

A generic sampler. Concrete classes must implement:

(1) choose_step() - returns a sampler step function to run. (2) get_recorder() - returns a recorder object for keeping track of accepted samples.

As far as the steps are concerned, they need only comply with the SamplerStep concept. Similarly, the recorder must comply with ModelRecorder concept.

Member Typedef Documentation

template<typename Model>
typedef Model Abstract_sampler< Model >::Model_type
template<typename Model>
typedef Sampler_step<Model>::Type Abstract_sampler< Model >::Step

Constructor & Destructor Documentation

template<typename Model>
Abstract_sampler< Model >::Abstract_sampler ( const Model &  initial_state,
double  initial_log_target 
)
inline
Parameters
initial_stateInitial model to start the sampler with.
initial_log_targetThe log of the target distribution at intitial_state

Member Function Documentation

template<typename Model>
template<class Callback >
void Abstract_sampler< Model >::add_record_callback ( Callback  cb)
inline
template<typename Model>
template<class Recorder >
void Abstract_sampler< Model >::add_recorder ( Recorder  r)
inline
template<typename Model>
template<class Recorder >
void Abstract_sampler< Model >::add_recorder ( Recorder *  r)
inline
template<typename Model>
Abstract_sampler< Model >::BOOST_CONCEPT_ASSERT ( (BaseModel< Model >)  )
template<typename Model>
virtual const Step& Abstract_sampler< Model >::choose_step ( ) const
protectedpure virtual

Chooses a sampler step. Pure virtual method, should be overwritten.

Implemented in Single_step_sampler< Model >, and Multi_step_sampler< Model >.

template<typename Model>
double Abstract_sampler< Model >::current_log_target ( ) const
inline

Return the value of the log-target distribution evaluated at the current state (cached value, no cost incurred)

template<typename Model>
Model& Abstract_sampler< Model >::current_state ( )
inline

Return the current state of the sampler.

template<typename Model>
const Model& Abstract_sampler< Model >::current_state ( ) const
inline

Return the current state of the sampler. (const version)

template<typename Model>
template<class Recorder >
const Recorder& Abstract_sampler< Model >::get_recorder ( size_t  i) const
inline
template<typename Model>
void Abstract_sampler< Model >::if_accept ( const Callback &  cb)
inline

Add a callback to be called if the next/current step is accepted This callback will be cleared at the end of the sampling iteration.

template<typename Model>
void Abstract_sampler< Model >::if_reject ( const Callback &  cb)
inline

Add a callback to be called if the next/current step is rejected. This callback will be cleared at the end of the sampling iteration.

template<typename Model>
void Abstract_sampler< Model >::on_accept ( const Callback &  cb)
inline

Add a callback to be called every time a step is accepted. If you want a callback to be called only if the next step is accepted, use if_accept().

If this is called multiple times, the callbacks will be called in sequence in the order they were added.

At the moment there is no way to remove a callback after it has been added. This could be added in the future if there is interest.

template<typename Model>
void Abstract_sampler< Model >::on_reject ( const Callback &  cb)
inline

Add a callback to be called every time a step is rejected. If you want a callback to be called only if the next step is rejected, use if_reject()

If this is called multiple times, the callbacks will be called in sequence in the order they were added.

At the moment there is no way to remove a callback after it has been added. This could be added in the future if there is interest.

template<typename Model >
void Abstract_sampler< Model >::run ( int  num_iterations)
virtual

Runs the sampler. This function runs the sampler for the indicated number of iterations. At each iteration it chooses a sampler step using choose_step() and invokes it using its operator(). The best model is saved and returned.

Parameters
initial_stateThe initial value of the model; e.g., the initial state of the Markov chain in MH.
num_iterationsThe number of iterations the sampler will do.

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