KJB
|
#include <sample_sampler.h>
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 Step & | choose_step () const =0 |
Chooses a sampler step. Pure virtual method, should be overwritten. More... | |
Model | The 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.
typedef Model Abstract_sampler< Model >::Model_type |
typedef Sampler_step<Model>::Type Abstract_sampler< Model >::Step |
|
inline |
initial_state | Initial model to start the sampler with. |
initial_log_target | The log of the target distribution at intitial_state |
|
inline |
|
inline |
|
inline |
Abstract_sampler< Model >::BOOST_CONCEPT_ASSERT | ( | (BaseModel< Model >) | ) |
|
protectedpure virtual |
Chooses a sampler step. Pure virtual method, should be overwritten.
Implemented in Single_step_sampler< Model >, and Multi_step_sampler< Model >.
|
inline |
Return the value of the log-target distribution evaluated at the current state (cached value, no cost incurred)
|
inline |
Return the current state of the sampler.
|
inline |
Return the current state of the sampler. (const version)
|
inline |
|
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.
|
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.
|
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.
|
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.
|
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.
initial_state | The initial value of the model; e.g., the initial state of the Markov chain in MH. |
num_iterations | The number of iterations the sampler will do. |