![]() |
Stan
1.0
probability, sampling & optimization
|
#include <hmc_base.hpp>
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. | |
| 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. | |
| 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. | |
| 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. | |
| bool | varying_epsilon () |
| virtual void | adapt_off () |
| Turn off parameter adaptation. | |
| virtual void | get_parameters (std::vector< double > ¶ms) |
| Write the step size into position 1 of the specified vector. | |
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. | |
| virtual | ~adaptive_sampler () |
| Destructor. | |
| void | set_error_stream (std::ostream &error_msgs) |
| Set the stream into which errors will be written as the sampler runs. | |
| void | unset_error_stream () |
| Unset the stream into which errors are written to 0 so that error messages are ignored. | |
| void | set_output_stream (std::ostream &output_msgs) |
| Set the stream into which output will be written as the sampler runs. | |
| void | unset_output_stream () |
| Unset the stream into which errors are written to 0 so that output messages are ignored. | |
| sample | next () |
| Returns the next sample from this sampler. | |
| virtual sample | next_impl ()=0 |
| Returns the next sample from this sampler. | |
| double | mean_stat () |
| Returns the value of the statistic we are trying to coerce. | |
| void | set_mean_stat (double v) |
| Sets the mean statistic to the specified value. | |
| void | update_mean_stat (double avg_eta, double adapt_stat) |
| Updates the mean statistic given the specified adaptation statistic and weighting. | |
| unsigned int | nfevals () |
| Returns the number of times that the (possibly unnormalized) log probability function has been evaluated by this sampler. | |
| void | nfevals_plus_eq (int n) |
| Add the specified number of evaluations to the number of function evaluations. | |
| int | n_steps () |
| Return the number of iterations for this sampler. | |
| int | n_adapt_steps () |
| Return how many iterations parameter adaptation has happened for. | |
| virtual void | adapt_on () |
| Turn on parameter adaptation. | |
| bool | adapting () |
| Return whether or not parameter adaptation is on. | |
| virtual void | write_sampler_params (std::ostream &o) |
| Write out any sampler-specific parameters for output. | |
| virtual void | write_adaptation_params (std::ostream &o) |
| Use this method to write the adaptation parameters into the output. | |
| virtual void | write_sampler_param_names (std::ostream &o) |
| Write out any sampler-specific parameter names for output. | |
| virtual void | get_sampler_param_names (std::vector< std::string > &names) |
| Get any sampler-specific parameter namess. | |
| virtual void | get_sampler_params (std::vector< double > &values) |
| Get any sampler-specific parameters. | |
Protected Member Functions | |
| virtual void | find_reasonable_parameters () |
| Search for a roughly reasonable (within a factor of 2) setting of the step size epsilon. | |
| 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 |
Definition at line 22 of file hmc_base.hpp.
|
inline |
Construct a base HMC sampler.
| model | Log probability model with gradients. |
| epsilon | Hamiltonian dynamics simulation step size. Optional; if not specified or set < 0, find_reasonable_parameters() will be called to initialize epsilon; default value = -1 |
| epsilon_pm | Sample 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_adapt | Flag indicating whether adaptation is turned on. |
| delta | Target acceptance rate for adaptation. |
| gamma | Tuning parameter for dual averaging adaptation. |
| rand_int | Base random integer generator. |
Definition at line 115 of file hmc_base.hpp.
|
inlinevirtual |
Definition at line 156 of file hmc_base.hpp.
|
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.
|
inlineprotected |
Definition at line 90 of file hmc_base.hpp.
|
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.
|
inlinevirtual |
Write the step size into position 1 of the specified vector.
| [out] | params | Where to store epsilon. |
Reimplemented from stan::mcmc::adaptive_sampler.
Definition at line 241 of file hmc_base.hpp.
|
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.
| x | Real parameters. |
| z | Integer parameters. |
Implements stan::mcmc::adaptive_sampler.
Definition at line 168 of file hmc_base.hpp.
|
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.
| z | Integer parameters. |
| std::invalid_argument | if 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.
|
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.
| x | Real parameters. |
| std::invalid_argument | if 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.
|
inline |
Definition at line 216 of file hmc_base.hpp.
|
protected |
Definition at line 36 of file hmc_base.hpp.
|
protected |
Definition at line 34 of file hmc_base.hpp.
|
protected |
Definition at line 29 of file hmc_base.hpp.
|
protected |
Definition at line 32 of file hmc_base.hpp.
|
protected |
Definition at line 31 of file hmc_base.hpp.
|
protected |
Definition at line 30 of file hmc_base.hpp.
|
protected |
Definition at line 49 of file hmc_base.hpp.
|
protected |
Definition at line 35 of file hmc_base.hpp.
|
protected |
Definition at line 50 of file hmc_base.hpp.
|
protected |
Definition at line 27 of file hmc_base.hpp.
|
protected |
Definition at line 38 of file hmc_base.hpp.
|
protected |
Definition at line 44 of file hmc_base.hpp.
|
protected |
Definition at line 41 of file hmc_base.hpp.
|
protected |
Definition at line 47 of file hmc_base.hpp.
|
protected |
Definition at line 48 of file hmc_base.hpp.