Stan  1.0
probability, sampling & optimization
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
stan::mcmc::hmc_base< BaseRNG > Class Template Reference

#include <hmc_base.hpp>

Inheritance diagram for stan::mcmc::hmc_base< BaseRNG >:
stan::mcmc::adaptive_sampler

Public Member Functions

 hmc_base (stan::model::prob_grad &model, double epsilon=-1, double epsilon_pm=0.0, bool epsilon_adapt=true, double delta=0.651, double gamma=0.05, BaseRNG rand_int=BaseRNG(std::time(0)), const std::vector< double > *params_r=0, const std::vector< int > *params_i=0)
 Construct a base HMC sampler. More...
 
virtual ~hmc_base ()
 
virtual void set_params (const std::vector< double > &x, const std::vector< int > &z)
 Sets the model real and integer parameters to the specified values. More...
 
void set_params_r (const std::vector< double > &x)
 Sets the model real parameters to the specified values and update gradients and log probability to match. More...
 
void set_params_i (const std::vector< int > &z)
 Sets the model integer parameters to the specified values and update gradients and log probability to match. More...
 
bool varying_epsilon ()
 
virtual void adapt_off ()
 Turn off parameter adaptation. More...
 
virtual void get_parameters (std::vector< double > &params)
 Write the step size into position 1 of the specified vector. More...
 
- Public Member Functions inherited from stan::mcmc::adaptive_sampler
 adaptive_sampler (bool adapt, std::ostream *error_msgs=0, std::ostream *output_msgs=0)
 Constructs an adaptive sampler with specified adaptation status. More...
 
virtual ~adaptive_sampler ()
 Destructor. More...
 
void set_error_stream (std::ostream &error_msgs)
 Set the stream into which errors will be written as the sampler runs. More...
 
void unset_error_stream ()
 Unset the stream into which errors are written to 0 so that error messages are ignored. More...
 
void set_output_stream (std::ostream &output_msgs)
 Set the stream into which output will be written as the sampler runs. More...
 
void unset_output_stream ()
 Unset the stream into which errors are written to 0 so that output messages are ignored. More...
 
sample next ()
 Returns the next sample from this sampler. More...
 
virtual sample next_impl ()=0
 Returns the next sample from this sampler. More...
 
double mean_stat ()
 Returns the value of the statistic we are trying to coerce. More...
 
void set_mean_stat (double v)
 Sets the mean statistic to the specified value. More...
 
void update_mean_stat (double avg_eta, double adapt_stat)
 Updates the mean statistic given the specified adaptation statistic and weighting. More...
 
unsigned int nfevals ()
 Returns the number of times that the (possibly unnormalized) log probability function has been evaluated by this sampler. More...
 
void nfevals_plus_eq (int n)
 Add the specified number of evaluations to the number of function evaluations. More...
 
int n_steps ()
 Return the number of iterations for this sampler. More...
 
int n_adapt_steps ()
 Return how many iterations parameter adaptation has happened for. More...
 
virtual void adapt_on ()
 Turn on parameter adaptation. More...
 
bool adapting ()
 Return whether or not parameter adaptation is on. More...
 
virtual void write_sampler_params (std::ostream &o)
 Write out any sampler-specific parameters for output. More...
 
virtual void write_adaptation_params (std::ostream &o)
 Use this method to write the adaptation parameters into the output. More...
 
virtual void write_sampler_param_names (std::ostream &o)
 Write out any sampler-specific parameter names for output. More...
 
virtual void get_sampler_param_names (std::vector< std::string > &names)
 Get any sampler-specific parameter namess. More...
 
virtual void get_sampler_params (std::vector< double > &values)
 Get any sampler-specific parameters. More...
 

Protected Member Functions

virtual void find_reasonable_parameters ()
 Search for a roughly reasonable (within a factor of 2) setting of the step size epsilon. More...
 
void adaptation_init (double epsilon_scale)
 

Protected Attributes

stan::model::prob_grad_model
 
double _epsilon
 
double _epsilon_pm
 
double _epsilon_last
 
bool _epsilon_adapt
 
const double _delta
 
const double _gamma
 
DualAverage _da
 
BaseRNG _rand_int
 
boost::variate_generator< BaseRNG &, boost::normal_distribution<> > _rand_unit_norm
 
boost::uniform_01< BaseRNG & > _rand_uniform_01
 
std::vector< double > _x
 
std::vector< int > _z
 
std::vector< double > _g
 
double _logp
 
- Protected Attributes inherited from stan::mcmc::adaptive_sampler
bool _adapt
 
unsigned int _n_steps
 
int _n_adapt_steps
 
unsigned int _nfevals
 
double _mean_stat
 
std::ostream * _error_msgs
 
std::ostream * _output_msgs
 

Detailed Description

template<class BaseRNG = boost::mt19937>
class stan::mcmc::hmc_base< BaseRNG >

Definition at line 22 of file hmc_base.hpp.

Constructor & Destructor Documentation

◆ hmc_base()

template<class BaseRNG = boost::mt19937>
stan::mcmc::hmc_base< BaseRNG >::hmc_base ( stan::model::prob_grad model,
double  epsilon = -1,
double  epsilon_pm = 0.0,
bool  epsilon_adapt = true,
double  delta = 0.651,
double  gamma = 0.05,
BaseRNG  rand_int = BaseRNG(std::time(0)),
const std::vector< double > *  params_r = 0,
const std::vector< int > *  params_i = 0 
)
inline

Construct a base HMC sampler.

Parameters
modelLog probability model with gradients.
epsilonHamiltonian dynamics simulation step size. Optional; if not specified or set < 0, find_reasonable_parameters() will be called to initialize epsilon; default value = -1
epsilon_pmSample in range defined by plus-or minus this value over epsilon (sample step size uniformly in interval [epsilon*(1-epsilon_pm), epsilon*(1+epsilon_pm)]; default value = 0.0
epsilon_adaptFlag indicating whether adaptation is turned on.
deltaTarget acceptance rate for adaptation.
gammaTuning parameter for dual averaging adaptation.
rand_intBase random integer generator.

Definition at line 115 of file hmc_base.hpp.

◆ ~hmc_base()

template<class BaseRNG = boost::mt19937>
virtual stan::mcmc::hmc_base< BaseRNG >::~hmc_base ( )
inlinevirtual

Definition at line 156 of file hmc_base.hpp.

Member Function Documentation

◆ adapt_off()

template<class BaseRNG = boost::mt19937>
virtual void stan::mcmc::hmc_base< BaseRNG >::adapt_off ( )
inlinevirtual

Turn off parameter adaptation.

Because we're using primal-dual averaging, once we're done adapting we want to set epsilon=the average value of epsilon over each adaptation step. This results in a lower-variance estimate of the optimal epsilon.

Reimplemented from stan::mcmc::adaptive_sampler.

Definition at line 228 of file hmc_base.hpp.

◆ adaptation_init()

template<class BaseRNG = boost::mt19937>
void stan::mcmc::hmc_base< BaseRNG >::adaptation_init ( double  epsilon_scale)
inlineprotected

Definition at line 90 of file hmc_base.hpp.

◆ find_reasonable_parameters()

template<class BaseRNG = boost::mt19937>
virtual void stan::mcmc::hmc_base< BaseRNG >::find_reasonable_parameters ( )
inlineprotectedvirtual

Search for a roughly reasonable (within a factor of 2) setting of the step size epsilon.

Reimplemented from stan::mcmc::adaptive_sampler.

Definition at line 56 of file hmc_base.hpp.

◆ get_parameters()

template<class BaseRNG = boost::mt19937>
virtual void stan::mcmc::hmc_base< BaseRNG >::get_parameters ( std::vector< double > &  params)
inlinevirtual

Write the step size into position 1 of the specified vector.

Parameters
[out]paramsWhere to store epsilon.

Reimplemented from stan::mcmc::adaptive_sampler.

Definition at line 241 of file hmc_base.hpp.

◆ set_params()

template<class BaseRNG = boost::mt19937>
virtual void stan::mcmc::hmc_base< BaseRNG >::set_params ( const std::vector< double > &  x,
const std::vector< int > &  z 
)
inlinevirtual

Sets the model real and integer parameters to the specified values.


This method will typically be used to set the parameters by the client of this class after initialization.

Parameters
xReal parameters.
zInteger parameters.

Implements stan::mcmc::adaptive_sampler.

Definition at line 168 of file hmc_base.hpp.

◆ set_params_i()

template<class BaseRNG = boost::mt19937>
void stan::mcmc::hmc_base< BaseRNG >::set_params_i ( const std::vector< int > &  z)
inline

Sets the model integer parameters to the specified values and update gradients and log probability to match.

This method will typically be used to set the parameters by the client of this class after initialization.

Parameters
zInteger parameters.
Exceptions
std::invalid_argumentif the number of integer parameters does not match the number of parameters defined by the model.

Definition at line 209 of file hmc_base.hpp.

◆ set_params_r()

template<class BaseRNG = boost::mt19937>
void stan::mcmc::hmc_base< BaseRNG >::set_params_r ( const std::vector< double > &  x)
inline

Sets the model real parameters to the specified values and update gradients and log probability to match.

This method will typically be used to set the parrs by the client of this class after initialization.

Parameters
xReal parameters.
Exceptions
std::invalid_argumentif the number of real parameters does not match the number of parameters defined by the model.

Definition at line 190 of file hmc_base.hpp.

◆ varying_epsilon()

template<class BaseRNG = boost::mt19937>
bool stan::mcmc::hmc_base< BaseRNG >::varying_epsilon ( )
inline

Definition at line 216 of file hmc_base.hpp.

Member Data Documentation

◆ _da

template<class BaseRNG = boost::mt19937>
DualAverage stan::mcmc::hmc_base< BaseRNG >::_da
protected

Definition at line 36 of file hmc_base.hpp.

◆ _delta

template<class BaseRNG = boost::mt19937>
const double stan::mcmc::hmc_base< BaseRNG >::_delta
protected

Definition at line 34 of file hmc_base.hpp.

◆ _epsilon

template<class BaseRNG = boost::mt19937>
double stan::mcmc::hmc_base< BaseRNG >::_epsilon
protected

Definition at line 29 of file hmc_base.hpp.

◆ _epsilon_adapt

template<class BaseRNG = boost::mt19937>
bool stan::mcmc::hmc_base< BaseRNG >::_epsilon_adapt
protected

Definition at line 32 of file hmc_base.hpp.

◆ _epsilon_last

template<class BaseRNG = boost::mt19937>
double stan::mcmc::hmc_base< BaseRNG >::_epsilon_last
protected

Definition at line 31 of file hmc_base.hpp.

◆ _epsilon_pm

template<class BaseRNG = boost::mt19937>
double stan::mcmc::hmc_base< BaseRNG >::_epsilon_pm
protected

Definition at line 30 of file hmc_base.hpp.

◆ _g

template<class BaseRNG = boost::mt19937>
std::vector<double> stan::mcmc::hmc_base< BaseRNG >::_g
protected

Definition at line 49 of file hmc_base.hpp.

◆ _gamma

template<class BaseRNG = boost::mt19937>
const double stan::mcmc::hmc_base< BaseRNG >::_gamma
protected

Definition at line 35 of file hmc_base.hpp.

◆ _logp

template<class BaseRNG = boost::mt19937>
double stan::mcmc::hmc_base< BaseRNG >::_logp
protected

Definition at line 50 of file hmc_base.hpp.

◆ _model

template<class BaseRNG = boost::mt19937>
stan::model::prob_grad& stan::mcmc::hmc_base< BaseRNG >::_model
protected

Definition at line 27 of file hmc_base.hpp.

◆ _rand_int

template<class BaseRNG = boost::mt19937>
BaseRNG stan::mcmc::hmc_base< BaseRNG >::_rand_int
protected

Definition at line 38 of file hmc_base.hpp.

◆ _rand_uniform_01

template<class BaseRNG = boost::mt19937>
boost::uniform_01<BaseRNG&> stan::mcmc::hmc_base< BaseRNG >::_rand_uniform_01
protected

Definition at line 44 of file hmc_base.hpp.

◆ _rand_unit_norm

template<class BaseRNG = boost::mt19937>
boost::variate_generator<BaseRNG&, boost::normal_distribution<> > stan::mcmc::hmc_base< BaseRNG >::_rand_unit_norm
protected

Definition at line 41 of file hmc_base.hpp.

◆ _x

template<class BaseRNG = boost::mt19937>
std::vector<double> stan::mcmc::hmc_base< BaseRNG >::_x
protected

Definition at line 47 of file hmc_base.hpp.

◆ _z

template<class BaseRNG = boost::mt19937>
std::vector<int> stan::mcmc::hmc_base< BaseRNG >::_z
protected

Definition at line 48 of file hmc_base.hpp.


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

     [ Stan Home Page ] © 2011–2012, Stan Development Team.