hmc_static_unit_e_adapt.hpp
Go to the documentation of this file.
1 #ifndef STAN_SERVICES_SAMPLE_HMC_STATIC_UNIT_E_ADAPT_HPP
2 #define STAN_SERVICES_SAMPLE_HMC_STATIC_UNIT_E_ADAPT_HPP
3 
14 #include <vector>
15 
16 namespace stan {
17  namespace services {
18  namespace sample {
19 
20  /**
21  * Runs static HMC with unit Euclidean
22  * metric with adaptation.
23  *
24  * @tparam Model Model class
25  * @param[in] model Input model to test (with data already instantiated)
26  * @param[in] init var context for initialization
27  * @param[in] random_seed random seed for the random number generator
28  * @param[in] chain chain id to advance the pseudo random number generator
29  * @param[in] init_radius radius to initialize
30  * @param[in] num_warmup Number of warmup samples
31  * @param[in] num_samples Number of samples
32  * @param[in] num_thin Number to thin the samples
33  * @param[in] save_warmup Indicates whether to save the warmup iterations
34  * @param[in] refresh Controls the output
35  * @param[in] stepsize initial stepsize for discrete evolution
36  * @param[in] stepsize_jitter uniform random jitter of stepsize
37  * @param[in] int_time integration time
38  * @param[in] delta adaptation target acceptance statistic
39  * @param[in] gamma adaptation regularization scale
40  * @param[in] kappa adaptation relaxation exponent
41  * @param[in] t0 adaptation iteration offset
42  * @param[in,out] interrupt Callback for interrupts
43  * @param[in,out] logger Logger for messages
44  * @param[in,out] init_writer Writer callback for unconstrained inits
45  * @param[in,out] sample_writer Writer for draws
46  * @param[in,out] diagnostic_writer Writer for diagnostic information
47  * @return error_codes::OK if successful
48  */
49  template <class Model>
52  unsigned int random_seed,
53  unsigned int chain, double init_radius,
54  int num_warmup, int num_samples, int num_thin,
55  bool save_warmup, int refresh,
56  double stepsize, double stepsize_jitter,
57  double int_time, double delta, double gamma,
58  double kappa, double t0,
59  callbacks::interrupt& interrupt,
60  callbacks::logger& logger,
61  callbacks::writer& init_writer,
62  callbacks::writer& sample_writer,
63  callbacks::writer& diagnostic_writer) {
64  boost::ecuyer1988 rng = util::create_rng(random_seed, chain);
65 
66  std::vector<int> disc_vector;
67  std::vector<double> cont_vector
68  = util::initialize(model, init, rng, init_radius,
69  true, logger, init_writer);
70 
72  sampler(model, rng);
73  sampler.set_nominal_stepsize_and_T(stepsize, int_time);
74  sampler.set_stepsize_jitter(stepsize_jitter);
75 
76  sampler.get_stepsize_adaptation().set_mu(log(10 * stepsize));
77  sampler.get_stepsize_adaptation().set_delta(delta);
78  sampler.get_stepsize_adaptation().set_gamma(gamma);
79  sampler.get_stepsize_adaptation().set_kappa(kappa);
80  sampler.get_stepsize_adaptation().set_t0(t0);
81 
82  util::run_adaptive_sampler(sampler, model, cont_vector,
83  num_warmup, num_samples, num_thin,
84  refresh, save_warmup, rng,
85  interrupt, logger,
86  sample_writer, diagnostic_writer);
87 
88  return error_codes::OK;
89  }
90 
91  }
92  }
93 }
94 #endif
double delta
Definition: runWimpSim.h:98
int hmc_static_unit_e_adapt(Model &model, stan::io::var_context &init, unsigned int random_seed, unsigned int chain, double init_radius, int num_warmup, int num_samples, int num_thin, bool save_warmup, int refresh, double stepsize, double stepsize_jitter, double int_time, double delta, double gamma, double kappa, double t0, callbacks::interrupt &interrupt, callbacks::logger &logger, callbacks::writer &init_writer, callbacks::writer &sample_writer, callbacks::writer &diagnostic_writer)
rosenbrock_model_namespace::rosenbrock_model Model
chain
Check that an output directory exists.
std::vector< double > initialize(Model &model, stan::io::var_context &init, RNG &rng, double init_radius, bool print_timing, stan::callbacks::logger &logger, stan::callbacks::writer &init_writer)
Definition: initialize.hpp:68
void run_adaptive_sampler(Sampler &sampler, Model &model, std::vector< double > &cont_vector, int num_warmup, int num_samples, int num_thin, int refresh, bool save_warmup, RNG &rng, callbacks::interrupt &interrupt, callbacks::logger &logger, callbacks::writer &sample_writer, callbacks::writer &diagnostic_writer)
stepsize_adaptation & get_stepsize_adaptation()
const XML_Char XML_Content * model
Definition: expat.h:151
boost::ecuyer1988 create_rng(unsigned int seed, unsigned int chain)
Definition: create_rng.hpp:25
void refresh()
Definition: show_event.C:21