![]() |
Stan
1.0
probability, sampling & optimization
|
Adaptive "constant distance" Hamiltonian Monte Carlo (CDHMC) sampler. More...
#include <adaptive_cdhmc.hpp>
Public Member Functions | |
| void | set_epsilon (double epsilon) |
| Set the step size epsilon. More... | |
| adaptive_cdhmc (stan::model::prob_grad &model, double epsilonL, double delta=0.651, double epsilon=-1, unsigned int random_seed=static_cast< unsigned int >(std::time(0))) | |
| Constructs an adaptive "constant distance" Hamiltonian Monte Carlo (CDHMC) sampler for the specified model, using the specified trajectory length, epsilonL, with the specified random seed for randomization. More... | |
| virtual | ~adaptive_cdhmc () |
| Destructor. More... | |
| virtual void | set_params (const std::vector< double > &x, const std::vector< int > &z) |
| Sets the model's real and integer parameters to the specified values. More... | |
| void | set_params_r (const std::vector< double > &x) |
| Sets the model's 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... | |
| virtual void | find_reasonable_parameters () |
| Searches for a roughly reasonable (within a factor of 2) setting of the step size epsilon. More... | |
| virtual sample | next_impl () |
| Returns the next sample. More... | |
| virtual void | adapt_off () |
| Turn off parameter adaptation. More... | |
| virtual void | get_parameters (std::vector< double > ¶ms) |
| Returns the value of epsilon. 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... | |
| 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... | |
Additional Inherited Members | |
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 |
Adaptive "constant distance" Hamiltonian Monte Carlo (CDHMC) sampler.
adaptive_cdhmc requires specification of the trajectory length, epsilon*L. CDHMC automatically tries to coerce the average acceptance probability to some value, delta, by choosing the number of steps, L, given the step size, epsilon, to make the trajectory length as close as possible to the target.
The CDHMC sampler requires a probability model with the ability to compute gradients, characterized as an instance of stan::model::prob_grad.
Samples from the sampler are returned through the base class sampler.
Definition at line 39 of file adaptive_cdhmc.hpp.
|
inline |
Constructs an adaptive "constant distance" Hamiltonian Monte Carlo (CDHMC) sampler for the specified model, using the specified trajectory length, epsilonL, with the specified random seed for randomization.
If the same seed is used twice, the series of samples should be the same. This property is most helpful for testing. If no random seed is specified, the std::time(0) function is called from the ctime library.
| model | Probability model with gradients. |
| epsilonL | Specified trajectory length, epsilon*L. |
| delta | Target value of E[acceptance probability]. Optional; defaults to the value of 0.651, which has some theoretical justification. |
| epsilon | Hamiltonian dynamics simulation step size. Optional; if not specified or set < 0, find_reasonable_parameters() will be called to initialize epsilon. |
| random_seed | Seed for random number generator. Optional; if not specified, generate new seen based on system time. |
Definition at line 107 of file adaptive_cdhmc.hpp.
|
inlinevirtual |
Destructor.
The implementation for this class is a no-op.
Definition at line 138 of file adaptive_cdhmc.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 300 of file adaptive_cdhmc.hpp.
|
inlinevirtual |
Searches for a roughly reasonable (within a factor of 2) setting of the step size epsilon.
Reimplemented from stan::mcmc::adaptive_sampler.
Definition at line 202 of file adaptive_cdhmc.hpp.
|
inlinevirtual |
Returns the value of epsilon.
| [out] | params | Where to store epsilon. |
Reimplemented from stan::mcmc::adaptive_sampler.
Definition at line 312 of file adaptive_cdhmc.hpp.
|
inlinevirtual |
Returns the next sample.
Implements stan::mcmc::adaptive_sampler.
Definition at line 239 of file adaptive_cdhmc.hpp.
|
inline |
Set the step size epsilon.
Automatically sets the number of steps L to make epsilon*L as close as possible to the target epsilonL.
| epsilon | The new step size epsilon. |
Definition at line 80 of file adaptive_cdhmc.hpp.
|
inlinevirtual |
Sets the model's 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 151 of file adaptive_cdhmc.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 191 of file adaptive_cdhmc.hpp.
|
inline |
Sets the model's real 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.
| 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 173 of file adaptive_cdhmc.hpp.