sampler_automated_factor_slice_sampler_MCMC Class Reference

Defines the interface to an automated factor slice sampler, which isn't as efficient as Stan in terms of ESS per iteration, but doesn't require gradients and tends to do better than an adaptive MH algorithm. Additionally it hardly uses any tuning parameters.

#include "sampling/sampler_automated_factor_slice_sampler_MCMC.h"

Inheritance diagram for sampler_automated_factor_slice_sampler_MCMC:
Collaboration diagram for sampler_automated_factor_slice_sampler_MCMC:

Public Member Functions

 sampler_automated_factor_slice_sampler_MCMC (int seed, likelihood &L, std::vector< std::string > var_names, size_t dimension)
 
void set_initial_location (std::vector< double > initial)
 Sets the starting location for the sampler. More...
 
void run_sampler (int nsteps, int thin, int refresh, int verbosity=1)
 
void set_adaptation_parameters (int num_warmup, bool save_adapt)
 sets the adaption interval for the slice sampler. This will adapt the directions of the slices and the windowing procedure for the problem. This is important for performance. More...
 
void set_intial_widths (std::vector< double > intitial_width)
 Sets the initial widths to be used for slices. More...
 
void set_window_parameters (int init_buffer, int window)
 Sets the window parameters for the adaptation. This is inspired by stan. The initial window will be solely for building the initial covariance estimate and finding some reasonable initial widths for the slices. Window then says how long the initial covariance adaptation round will last. We then increase by factors of 2 until we have exhausted the adaptation stage of the sampler. More...
 
void set_initial_covariance (Eigen::MatrixXd covariance)
 Sets the initial covariance matrix for the slice sampler. This will then be diagonalized to find the principal directions. More...
 
void get_chain_state (std::vector< double > &parameters, std::vector< double > &sample_state)
 
void set_chain_state (std::vector< double > model_values, std::vector< double > state_values)
 
void write_checkpoint (std::ostream &)
 
void read_checkpoint (std::string ckpt_file)
 Restarts the sampler from the state specified in the ckpt_file. More...
 
void read_checkpoint (std::istream &ckpt_in)
 
void reset_sampler_step ()
 
- Public Member Functions inherited from sampler_MCMC_base
 sampler_MCMC_base (int seed, likelihood &L, std::vector< std::string > var_names, size_t dimension)
 
virtual void set_output_stream (std::string chain_name, std::string state_name, std::string sampler_name, int output_precision=8)
 Sets the output names for the chains and sampler states. This must be implemented in any classes inheriting sampler_exploration_mcmc_base. More...
 
virtual std::vector< double > find_best_fit (std::string chain_file, std::string state_file) const
 Finds the best fit within provided chain file and returns it. More...
 
virtual std::vector< double > find_best_fit () const
 Finds the best fit from the chain and state file saved in set_output_stream. More...
 
void set_checkpoint (int ckpt_stride, std::string ckpt_file)
 Sets the checkpoint/restart functionality. More...
 
void reset_likelihood_sum ()
 
double get_likelihood_sum ()
 
virtual double get_rand ()
 
virtual void reset_rng_seed (int seed)
 
void set_mpi_communicator (MPI_Comm comm)
 Sets the MPI_Comm to be used for the likelihood evaluation. More...
 
void close_streams ()
 Helper function that closes the streams from a sampler.
 

Private Member Functions

void write_state ()
 
void write_chain_header ()
 
void write_state_header ()
 
void write_sampler_header ()
 
double loglklhd_transform (std::vector< double > cont_params)
 
void generate_transition (int step, int start, int finish, int nthin, int refresh, bool save, int verbosity)
 
void factor_slice_sample (const int k, const double h)
 
void ray_position (int k, double t, std::vector< double > &ray)
 
int step_out (const int k, double logh, std::vector< double > &lower_ray, std::vector< double > &upper_ray, double &tmin, double &tmax)
 
void shrink (int k, std::vector< double > &lower_ray, std::vector< double > &upper_ray, double t)
 
void update_covariance (std::vector< double > sample)
 
void set_adaptation_schedule ()
 
double factor_adapt ()
 
void width_adapt ()
 

Private Attributes

std::vector< double > _current_parameters
 
std::vector< double > _current_state
 
bool _adaptation
 
bool _save_adaptation
 
int _nadapt
 
int _start_step
 
double _width_tol
 
double _cov_tol
 
int _width_adapt_stride
 
int _cov_adapt_stride
 
int _adapt_width_count
 
int _adapt_cov_count
 
int _number_slow_adapt
 restart flag.
 
bool _restart
 
Eigen::MatrixXd _Gammak
 
Eigen::MatrixXd _covariance
 
Eigen::VectorXd _Dk
 
Eigen::VectorXd _mean
 
std::vector< double > _initial_width
 
std::vector< int > _nexpansion
 
std::vector< int > _ncontraction
 
std::vector< bool > _width_adapt
 
int _init_buffer
 
int _window
 
std::vector< double > _lbound
 
std::vector< double > _ubound
 
std::vector< Themis::transform_base * > _transforms
 

Additional Inherited Members

- Protected Attributes inherited from sampler_MCMC_base
int _seed
 
Ran2RNG _rng
 
std::vector< std::string > _var_names
 
size_t _dimension
 
size_t _step_count
 
likelihood_L
 
std::string _chain_file
 
std::string _state_file
 
std::string _sampler_file
 
std::string _ckpt_file
 
std::ofstream _chain_out
 
std::ofstream _state_out
 
std::ofstream _sampler_out
 
int _output_precision
 
int _ckpt_stride
 
double _sum_lklhd
 
MPI_Comm _comm
 
int _rank
 

Member Function Documentation

void read_checkpoint ( std::string  ckpt_file)
inlinevirtual
Parameters
ckpt_fileThe file where the checkpoint information was saved.

Reimplemented from sampler_MCMC_base.

Here is the call graph for this function:

void set_adaptation_parameters ( int  num_warmup,
bool  save_adapt 
)
Parameters
num_warmupThe number of adaptation steps to take. Default is 10,000.
save_adaptWhether to save the adaptation steps.
Note
Be aggressive with adaptation.
void set_initial_covariance ( Eigen::MatrixXd  covariance)
Parameters
covariance.The covariance matrix for the problem.
void set_initial_location ( std::vector< double >  initial)
virtual
Parameters
initial_parametersThe initial location of the sampler. This must be set before calling run_sampler.

Implements sampler_MCMC_base.

Here is the call graph for this function:

void set_intial_widths ( std::vector< double >  intitial_width)
Parameters
intitial_widthThe initial widths of the slices to be used.
Note
If you aren't sure what these should be make them too big. It is cheaper to shrink a slice than to expand it.
void set_window_parameters ( int  init_buffer,
int  window 
)
Note
at the the end of this we will have nadapt steps.
Parameters
init_bufferThe initial length to adapt the slices.
windowThe initial length of the covariance adaptation.

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