Classes | Functions
stan::services::sample Namespace Reference

Classes

struct  adaptation_engaged
 
struct  gamma
 
struct  init_buffer
 
struct  int_time
 
struct  kappa
 
struct  max_depth
 
struct  num_samples
 
struct  num_warmup
 
struct  save_warmup
 
struct  stepsize
 
struct  stepsize_jitter
 
struct  t0
 
struct  term_buffer
 
struct  thin
 
struct  window
 

Functions

template<class Model >
int fixed_param (Model &model, stan::io::var_context &init, unsigned int random_seed, unsigned int chain, double init_radius, int num_samples, int num_thin, int refresh, callbacks::interrupt &interrupt, callbacks::logger &logger, callbacks::writer &init_writer, callbacks::writer &sample_writer, callbacks::writer &diagnostic_writer)
 
template<class Model >
int hmc_nuts_dense_e (Model &model, stan::io::var_context &init, stan::io::var_context &init_inv_metric, 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, int max_depth, callbacks::interrupt &interrupt, callbacks::logger &logger, callbacks::writer &init_writer, callbacks::writer &sample_writer, callbacks::writer &diagnostic_writer)
 
template<class Model >
int hmc_nuts_dense_e (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, int max_depth, callbacks::interrupt &interrupt, callbacks::logger &logger, callbacks::writer &init_writer, callbacks::writer &sample_writer, callbacks::writer &diagnostic_writer)
 
template<class Model >
int hmc_nuts_dense_e_adapt (Model &model, stan::io::var_context &init, stan::io::var_context &init_inv_metric, 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, int max_depth, double delta, double gamma, double kappa, double t0, unsigned int init_buffer, unsigned int term_buffer, unsigned int window, callbacks::interrupt &interrupt, callbacks::logger &logger, callbacks::writer &init_writer, callbacks::writer &sample_writer, callbacks::writer &diagnostic_writer)
 
template<class Model >
int hmc_nuts_dense_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, int max_depth, double delta, double gamma, double kappa, double t0, unsigned int init_buffer, unsigned int term_buffer, unsigned int window, callbacks::interrupt &interrupt, callbacks::logger &logger, callbacks::writer &init_writer, callbacks::writer &sample_writer, callbacks::writer &diagnostic_writer)
 
template<class Model >
int hmc_nuts_diag_e (Model &model, stan::io::var_context &init, stan::io::var_context &init_inv_metric, 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, int max_depth, callbacks::interrupt &interrupt, callbacks::logger &logger, callbacks::writer &init_writer, callbacks::writer &sample_writer, callbacks::writer &diagnostic_writer)
 
template<class Model >
int hmc_nuts_diag_e (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, int max_depth, callbacks::interrupt &interrupt, callbacks::logger &logger, callbacks::writer &init_writer, callbacks::writer &sample_writer, callbacks::writer &diagnostic_writer)
 
template<class Model >
int hmc_nuts_diag_e_adapt (Model &model, stan::io::var_context &init, stan::io::var_context &init_inv_metric, 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, int max_depth, double delta, double gamma, double kappa, double t0, unsigned int init_buffer, unsigned int term_buffer, unsigned int window, callbacks::interrupt &interrupt, callbacks::logger &logger, callbacks::writer &init_writer, callbacks::writer &sample_writer, callbacks::writer &diagnostic_writer)
 
template<class Model >
int hmc_nuts_diag_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, int max_depth, double delta, double gamma, double kappa, double t0, unsigned int init_buffer, unsigned int term_buffer, unsigned int window, callbacks::interrupt &interrupt, callbacks::logger &logger, callbacks::writer &init_writer, callbacks::writer &sample_writer, callbacks::writer &diagnostic_writer)
 
template<class Model >
int hmc_nuts_unit_e (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, int max_depth, callbacks::interrupt &interrupt, callbacks::logger &logger, callbacks::writer &init_writer, callbacks::writer &sample_writer, callbacks::writer &diagnostic_writer)
 
template<class Model >
int hmc_nuts_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, int max_depth, 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)
 
template<class Model >
int hmc_static_dense_e (Model &model, stan::io::var_context &init, stan::io::var_context &init_inv_metric, 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, callbacks::interrupt &interrupt, callbacks::logger &logger, callbacks::writer &init_writer, callbacks::writer &sample_writer, callbacks::writer &diagnostic_writer)
 
template<class Model >
int hmc_static_dense_e (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, callbacks::interrupt &interrupt, callbacks::logger &logger, callbacks::writer &init_writer, callbacks::writer &sample_writer, callbacks::writer &diagnostic_writer)
 
template<class Model >
int hmc_static_dense_e_adapt (Model &model, stan::io::var_context &init, stan::io::var_context &init_inv_metric, 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, unsigned int init_buffer, unsigned int term_buffer, unsigned int window, callbacks::interrupt &interrupt, callbacks::logger &logger, callbacks::writer &init_writer, callbacks::writer &sample_writer, callbacks::writer &diagnostic_writer)
 
template<class Model >
int hmc_static_dense_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, unsigned int init_buffer, unsigned int term_buffer, unsigned int window, callbacks::interrupt &interrupt, callbacks::logger &logger, callbacks::writer &init_writer, callbacks::writer &sample_writer, callbacks::writer &diagnostic_writer)
 
template<class Model >
int hmc_static_diag_e (Model &model, stan::io::var_context &init, stan::io::var_context &init_inv_metric, 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, callbacks::interrupt &interrupt, callbacks::logger &logger, callbacks::writer &init_writer, callbacks::writer &sample_writer, callbacks::writer &diagnostic_writer)
 
template<class Model >
int hmc_static_diag_e (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, callbacks::interrupt &interrupt, callbacks::logger &logger, callbacks::writer &init_writer, callbacks::writer &sample_writer, callbacks::writer &diagnostic_writer)
 
template<class Model >
int hmc_static_diag_e_adapt (Model &model, stan::io::var_context &init, stan::io::var_context &init_inv_metric, 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, unsigned int init_buffer, unsigned int term_buffer, unsigned int window, callbacks::interrupt &interrupt, callbacks::logger &logger, callbacks::writer &init_writer, callbacks::writer &sample_writer, callbacks::writer &diagnostic_writer)
 
template<class Model >
int hmc_static_diag_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, unsigned int init_buffer, unsigned int term_buffer, unsigned int window, callbacks::interrupt &interrupt, callbacks::logger &logger, callbacks::writer &init_writer, callbacks::writer &sample_writer, callbacks::writer &diagnostic_writer)
 
template<class Model >
int hmc_static_unit_e (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, callbacks::interrupt &interrupt, callbacks::logger &logger, callbacks::writer &init_writer, callbacks::writer &sample_writer, callbacks::writer &diagnostic_writer)
 
template<class Model >
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)
 

Function Documentation

template<class Model >
int stan::services::sample::fixed_param ( Model model,
stan::io::var_context init,
unsigned int  random_seed,
unsigned int  chain,
double  init_radius,
int  num_samples,
int  num_thin,
int  refresh,
callbacks::interrupt interrupt,
callbacks::logger logger,
callbacks::writer init_writer,
callbacks::writer sample_writer,
callbacks::writer diagnostic_writer 
)

Runs the fixed parameter sampler.

The fixed parameter sampler sets the parameters randomly once on the unconstrained scale, then runs the model for the number of iterations specified with the parameters fixed.

Template Parameters
ModelModel class
Parameters
[in]modelInput model to test (with data already instantiated)
[in]initvar context for initialization
[in]random_seedrandom seed for the random number generator
[in]chainchain id to advance the pseudo random number generator
[in]init_radiusradius to initialize
[in]num_samplesNumber of samples
[in]num_thinNumber to thin the samples
[in]refreshControls the output
[in,out]interruptCallback for interrupts
[in,out]loggerLogger for messages
[in,out]init_writerWriter callback for unconstrained inits
[in,out]sample_writerWriter for draws
[in,out]diagnostic_writerWriter for diagnostic information
Returns
error_codes::OK if successful

Definition at line 44 of file fixed_param.hpp.

References stan::services::util::create_rng(), febshutoff_auto::end, stan::services::util::generate_transitions(), MECModelEnuComparisons::i, stan::services::util::initialize(), stan::services::error_codes::OK, febshutoff_auto::start, stan::services::util::mcmc_writer::write_diagnostic_names(), stan::services::util::mcmc_writer::write_sample_names(), and stan::services::util::mcmc_writer::write_timing().

Referenced by TEST_F().

52  {
53  boost::ecuyer1988 rng = util::create_rng(random_seed, chain);
54 
55  std::vector<int> disc_vector;
56  std::vector<double> cont_vector
57  = util::initialize(model, init, rng, init_radius, false,
58  logger, init_writer);
59 
61  util::mcmc_writer
62  writer(sample_writer, diagnostic_writer, logger);
63  Eigen::VectorXd cont_params(cont_vector.size());
64  for (size_t i = 0; i < cont_vector.size(); i++)
65  cont_params[i] = cont_vector[i];
66  stan::mcmc::sample s(cont_params, 0, 0);
67 
68  // Headers
69  writer.write_sample_names(s, sampler, model);
70  writer.write_diagnostic_names(s, sampler, model);
71 
72  clock_t start = clock();
73 
74  util::generate_transitions(sampler, num_samples, 0, num_samples,
75  num_thin, refresh, true, false, writer,
76  s, model, rng, interrupt, logger);
77  clock_t end = clock();
78 
79  double sampleDeltaT = static_cast<double>(end - start) / CLOCKS_PER_SEC;
80  writer.write_timing(0.0, sampleDeltaT);
81 
82  return error_codes::OK;
83  }
const XML_Char * s
Definition: expat.h:262
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
const XML_Char XML_Content * model
Definition: expat.h:151
void generate_transitions(stan::mcmc::base_mcmc &sampler, int num_iterations, int start, int finish, int num_thin, int refresh, bool save, bool warmup, util::mcmc_writer &mcmc_writer, stan::mcmc::sample &init_s, Model &model, RNG &base_rng, callbacks::interrupt &callback, callbacks::logger &logger)
boost::ecuyer1988 create_rng(unsigned int seed, unsigned int chain)
Definition: create_rng.hpp:25
void refresh()
Definition: show_event.C:21
template<class Model >
int stan::services::sample::hmc_nuts_dense_e ( Model model,
stan::io::var_context init,
stan::io::var_context init_inv_metric,
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,
int  max_depth,
callbacks::interrupt interrupt,
callbacks::logger logger,
callbacks::writer init_writer,
callbacks::writer sample_writer,
callbacks::writer diagnostic_writer 
)

Runs HMC with NUTS without adaptation using dense Euclidean metric with a pre-specified Euclidean metric.

Template Parameters
ModelModel class
Parameters
[in]modelInput model to test (with data already instantiated)
[in]initvar context for initialization
[in]init_inv_metricvar context exposing an initial dense inverse Euclidean metric (must be positive definite)
[in]random_seedrandom seed for the random number generator
[in]chainchain id to advance the pseudo random number generator
[in]init_radiusradius to initialize
[in]num_warmupNumber of warmup samples
[in]num_samplesNumber of samples
[in]num_thinNumber to thin the samples
[in]save_warmupIndicates whether to save the warmup iterations
[in]refreshControls the output
[in]stepsizeinitial stepsize for discrete evolution
[in]stepsize_jitteruniform random jitter of stepsize
[in]max_depthMaximum tree depth
[in,out]interruptCallback for interrupts
[in,out]loggerLogger for messages
[in,out]init_writerWriter callback for unconstrained inits
[in,out]sample_writerWriter for draws
[in,out]diagnostic_writerWriter for diagnostic information
Returns
error_codes::OK if successful

Definition at line 49 of file hmc_nuts_dense_e.hpp.

References stan::services::error_codes::CONFIG, stan::services::util::create_rng(), stan::math::domain_error(), e, stan::services::util::initialize(), stan::services::error_codes::OK, stan::services::util::read_dense_inv_metric(), stan::services::util::run_sampler(), stan::mcmc::base_nuts< Model, dense_e_metric, expl_leapfrog, BaseRNG >::set_max_depth(), stan::mcmc::base_nuts< Model, dense_e_metric, expl_leapfrog, BaseRNG >::set_metric(), stan::mcmc::base_hmc< Model, dense_e_metric, expl_leapfrog, BaseRNG >::set_nominal_stepsize(), stan::mcmc::base_hmc< Model, dense_e_metric, expl_leapfrog, BaseRNG >::set_stepsize_jitter(), and stan::services::util::validate_dense_inv_metric().

Referenced by hmc_nuts_dense_e(), and TEST_F().

60  {
61  boost::ecuyer1988 rng = util::create_rng(random_seed, chain);
62 
63  std::vector<int> disc_vector;
64  std::vector<double> cont_vector
65  = util::initialize(model, init, rng, init_radius, true,
66  logger, init_writer);
67 
68  Eigen::MatrixXd inv_metric;
69  try {
70  inv_metric =
71  util::read_dense_inv_metric(init_inv_metric, model.num_params_r(),
72  logger);
73  util::validate_dense_inv_metric(inv_metric, logger);
74  } catch (const std::domain_error& e) {
75  return error_codes::CONFIG;
76  }
77 
79  sampler(model, rng);
80 
81  sampler.set_metric(inv_metric);
82 
83  sampler.set_nominal_stepsize(stepsize);
84  sampler.set_stepsize_jitter(stepsize_jitter);
85  sampler.set_max_depth(max_depth);
86 
87  util::run_sampler(sampler, model, cont_vector, num_warmup, num_samples,
88  num_thin, refresh, save_warmup, rng, interrupt,
89  logger,
90  sample_writer, diagnostic_writer);
91  return error_codes::OK;
92  }
void validate_dense_inv_metric(const Eigen::MatrixXd &inv_metric, callbacks::logger &logger)
Eigen::MatrixXd read_dense_inv_metric(stan::io::var_context &init_context, size_t num_params, callbacks::logger &logger)
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 domain_error(const char *function, const char *name, const T &y, const char *msg1, const char *msg2)
void run_sampler(stan::mcmc::base_mcmc &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)
Definition: run_sampler.hpp:36
Float_t e
Definition: plot.C:35
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
template<class Model >
int stan::services::sample::hmc_nuts_dense_e ( 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,
int  max_depth,
callbacks::interrupt interrupt,
callbacks::logger logger,
callbacks::writer init_writer,
callbacks::writer sample_writer,
callbacks::writer diagnostic_writer 
)

Runs HMC with NUTS without adaptation using dense Euclidean metric, with identity matrix as initial inv_metric.

Template Parameters
ModelModel class
Parameters
[in]modelInput model to test (with data already instantiated)
[in]initvar context for initialization
[in]random_seedrandom seed for the random number generator
[in]chainchain id to advance the pseudo random number generator
[in]init_radiusradius to initialize
[in]num_warmupNumber of warmup samples
[in]num_samplesNumber of samples
[in]num_thinNumber to thin the samples
[in]save_warmupIndicates whether to save the warmup iterations
[in]refreshControls the output
[in]stepsizeinitial stepsize for discrete evolution
[in]stepsize_jitteruniform random jitter of stepsize
[in]max_depthMaximum tree depth
[in,out]interruptCallback for interrupts
[in,out]loggerLogger for messages
[in,out]init_writerWriter callback for unconstrained inits
[in,out]sample_writerWriter for draws
[in,out]diagnostic_writerWriter for diagnostic information
Returns
error_codes::OK if successful

Definition at line 121 of file hmc_nuts_dense_e.hpp.

References stan::services::util::create_unit_e_dense_inv_metric(), and hmc_nuts_dense_e().

131  {
132  stan::io::dump dmp =
134  stan::io::var_context& unit_e_metric = dmp;
135 
136  return hmc_nuts_dense_e(model, init, unit_e_metric,
137  random_seed, chain, init_radius, num_warmup,
138  num_samples, num_thin, save_warmup, refresh,
139  stepsize, stepsize_jitter, max_depth,
140  interrupt, logger,
141  init_writer, sample_writer, diagnostic_writer);
142  }
stan::io::dump create_unit_e_dense_inv_metric(size_t num_params)
chain
Check that an output directory exists.
const XML_Char XML_Content * model
Definition: expat.h:151
int hmc_nuts_dense_e(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, int max_depth, callbacks::interrupt &interrupt, callbacks::logger &logger, callbacks::writer &init_writer, callbacks::writer &sample_writer, callbacks::writer &diagnostic_writer)
void refresh()
Definition: show_event.C:21
template<class Model >
int stan::services::sample::hmc_nuts_dense_e_adapt ( Model model,
stan::io::var_context init,
stan::io::var_context init_inv_metric,
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,
int  max_depth,
double  delta,
double  gamma,
double  kappa,
double  t0,
unsigned int  init_buffer,
unsigned int  term_buffer,
unsigned int  window,
callbacks::interrupt interrupt,
callbacks::logger logger,
callbacks::writer init_writer,
callbacks::writer sample_writer,
callbacks::writer diagnostic_writer 
)

Runs HMC with NUTS with adaptation using dense Euclidean metric with a pre-specified Euclidean metric.

Template Parameters
ModelModel class
Parameters
[in]modelInput model to test (with data already instantiated)
[in]initvar context for initialization
[in]init_inv_metricvar context exposing an initial dense inverse Euclidean metric (must be positive definite)
[in]random_seedrandom seed for the random number generator
[in]chainchain id to advance the pseudo random number generator
[in]init_radiusradius to initialize
[in]num_warmupNumber of warmup samples
[in]num_samplesNumber of samples
[in]num_thinNumber to thin the samples
[in]save_warmupIndicates whether to save the warmup iterations
[in]refreshControls the output
[in]stepsizeinitial stepsize for discrete evolution
[in]stepsize_jitteruniform random jitter of stepsize
[in]max_depthMaximum tree depth
[in]deltaadaptation target acceptance statistic
[in]gammaadaptation regularization scale
[in]kappaadaptation relaxation exponent
[in]t0adaptation iteration offset
[in]init_bufferwidth of initial fast adaptation interval
[in]term_bufferwidth of final fast adaptation interval
[in]windowinitial width of slow adaptation interval
[in,out]interruptCallback for interrupts
[in,out]loggerLogger for messages
[in,out]init_writerWriter callback for unconstrained inits
[in,out]sample_writerWriter for draws
[in,out]diagnostic_writerWriter for diagnostic information
Returns
error_codes::OK if successful

Definition at line 57 of file hmc_nuts_dense_e_adapt.hpp.

References stan::services::error_codes::CONFIG, stan::services::util::create_rng(), stan::math::domain_error(), e, stan::mcmc::stepsize_covar_adapter::get_stepsize_adaptation(), stan::services::util::initialize(), test_ParserArtEvents::log, stan::services::error_codes::OK, stan::services::util::read_dense_inv_metric(), stan::services::util::run_adaptive_sampler(), stan::mcmc::base_nuts< Model, dense_e_metric, expl_leapfrog, BaseRNG >::set_max_depth(), stan::mcmc::base_nuts< Model, dense_e_metric, expl_leapfrog, BaseRNG >::set_metric(), stan::mcmc::base_hmc< Model, dense_e_metric, expl_leapfrog, BaseRNG >::set_nominal_stepsize(), stan::mcmc::base_hmc< Model, dense_e_metric, expl_leapfrog, BaseRNG >::set_stepsize_jitter(), stan::mcmc::stepsize_covar_adapter::set_window_params(), and stan::services::util::validate_dense_inv_metric().

Referenced by hmc_nuts_dense_e_adapt(), and TEST_F().

71  {
72  boost::ecuyer1988 rng = util::create_rng(random_seed, chain);
73 
74  std::vector<int> disc_vector;
75  std::vector<double> cont_vector
76  = util::initialize(model, init, rng, init_radius, true,
77  logger, init_writer);
78 
79  Eigen::MatrixXd inv_metric;
80  try {
81  inv_metric =
82  util::read_dense_inv_metric(init_inv_metric, model.num_params_r(),
83  logger);
84  util::validate_dense_inv_metric(inv_metric, logger);
85  } catch (const std::domain_error& e) {
86  return error_codes::CONFIG;
87  }
88 
90  sampler(model, rng);
91 
92  sampler.set_metric(inv_metric);
93 
94  sampler.set_nominal_stepsize(stepsize);
95  sampler.set_stepsize_jitter(stepsize_jitter);
96  sampler.set_max_depth(max_depth);
97 
98  sampler.get_stepsize_adaptation().set_mu(log(10 * stepsize));
99  sampler.get_stepsize_adaptation().set_delta(delta);
100  sampler.get_stepsize_adaptation().set_gamma(gamma);
101  sampler.get_stepsize_adaptation().set_kappa(kappa);
102  sampler.get_stepsize_adaptation().set_t0(t0);
103 
104  sampler.set_window_params(num_warmup, init_buffer, term_buffer,
105  window, logger);
106 
107  util::run_adaptive_sampler(sampler, model, cont_vector, num_warmup,
108  num_samples, num_thin, refresh, save_warmup,
109  rng, interrupt, logger,
110  sample_writer, diagnostic_writer);
111 
112  return error_codes::OK;
113  }
double delta
Definition: runWimpSim.h:98
void validate_dense_inv_metric(const Eigen::MatrixXd &inv_metric, callbacks::logger &logger)
Eigen::MatrixXd read_dense_inv_metric(stan::io::var_context &init_context, size_t num_params, callbacks::logger &logger)
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 domain_error(const char *function, const char *name, const T &y, const char *msg1, const char *msg2)
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)
Float_t e
Definition: plot.C:35
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
template<class Model >
int stan::services::sample::hmc_nuts_dense_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,
int  max_depth,
double  delta,
double  gamma,
double  kappa,
double  t0,
unsigned int  init_buffer,
unsigned int  term_buffer,
unsigned int  window,
callbacks::interrupt interrupt,
callbacks::logger logger,
callbacks::writer init_writer,
callbacks::writer sample_writer,
callbacks::writer diagnostic_writer 
)

Runs HMC with NUTS with adaptation using dense Euclidean metric, with identity matrix as initial inv_metric.

Template Parameters
ModelModel class
Parameters
[in]modelInput model to test (with data already instantiated)
[in]initvar context for initialization
[in]random_seedrandom seed for the random number generator
[in]chainchain id to advance the pseudo random number generator
[in]init_radiusradius to initialize
[in]num_warmupNumber of warmup samples
[in]num_samplesNumber of samples
[in]num_thinNumber to thin the samples
[in]save_warmupIndicates whether to save the warmup iterations
[in]refreshControls the output
[in]stepsizeinitial stepsize for discrete evolution
[in]stepsize_jitteruniform random jitter of stepsize
[in]max_depthMaximum tree depth
[in]deltaadaptation target acceptance statistic
[in]gammaadaptation regularization scale
[in]kappaadaptation relaxation exponent
[in]t0adaptation iteration offset
[in]init_bufferwidth of initial fast adaptation interval
[in]term_bufferwidth of final fast adaptation interval
[in]windowinitial width of slow adaptation interval
[in,out]interruptCallback for interrupts
[in,out]loggerLogger for messages
[in,out]init_writerWriter callback for unconstrained inits
[in,out]sample_writerWriter for draws
[in,out]diagnostic_writerWriter for diagnostic information
Returns
error_codes::OK if successful

Definition at line 148 of file hmc_nuts_dense_e_adapt.hpp.

References stan::services::util::create_unit_e_dense_inv_metric(), and hmc_nuts_dense_e_adapt().

161  {
162  stan::io::dump dmp =
164  stan::io::var_context& unit_e_metric = dmp;
165 
166  return hmc_nuts_dense_e_adapt(model, init, unit_e_metric,
167  random_seed, chain, init_radius,
168  num_warmup, num_samples, num_thin,
169  save_warmup, refresh,
170  stepsize, stepsize_jitter, max_depth,
171  delta, gamma, kappa, t0,
172  init_buffer, term_buffer, window,
173  interrupt, logger,
174  init_writer, sample_writer,
175  diagnostic_writer);
176  }
double delta
Definition: runWimpSim.h:98
stan::io::dump create_unit_e_dense_inv_metric(size_t num_params)
int hmc_nuts_dense_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, int max_depth, double delta, double gamma, double kappa, double t0, unsigned int init_buffer, unsigned int term_buffer, unsigned int window, callbacks::interrupt &interrupt, callbacks::logger &logger, callbacks::writer &init_writer, callbacks::writer &sample_writer, callbacks::writer &diagnostic_writer)
chain
Check that an output directory exists.
const XML_Char XML_Content * model
Definition: expat.h:151
void refresh()
Definition: show_event.C:21
template<class Model >
int stan::services::sample::hmc_nuts_diag_e ( Model model,
stan::io::var_context init,
stan::io::var_context init_inv_metric,
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,
int  max_depth,
callbacks::interrupt interrupt,
callbacks::logger logger,
callbacks::writer init_writer,
callbacks::writer sample_writer,
callbacks::writer diagnostic_writer 
)

Runs HMC with NUTS without adaptation using diagonal Euclidean metric with a pre-specified Euclidean metric.

Template Parameters
ModelModel class
Parameters
[in]modelInput model to test (with data already instantiated)
[in]initvar context for initialization
[in]init_inv_metricvar context exposing an initial diagonal inverse Euclidean metric (must be positive definite)
[in]random_seedrandom seed for the random number generator
[in]chainchain id to advance the pseudo random number generator
[in]init_radiusradius to initialize
[in]num_warmupNumber of warmup samples
[in]num_samplesNumber of samples
[in]num_thinNumber to thin the samples
[in]save_warmupIndicates whether to save the warmup iterations
[in]refreshControls the output
[in]stepsizeinitial stepsize for discrete evolution
[in]stepsize_jitteruniform random jitter of stepsize
[in]max_depthMaximum tree depth
[in,out]interruptCallback for interrupts
[in,out]loggerLogger for messages
[in,out]init_writerWriter callback for unconstrained inits
[in,out]sample_writerWriter for draws
[in,out]diagnostic_writerWriter for diagnostic information
Returns
error_codes::OK if successful

Definition at line 50 of file hmc_nuts_diag_e.hpp.

References stan::services::error_codes::CONFIG, stan::services::util::create_rng(), stan::math::domain_error(), e, stan::services::util::initialize(), stan::services::error_codes::OK, stan::services::util::read_diag_inv_metric(), stan::services::util::run_sampler(), stan::mcmc::base_nuts< Model, diag_e_metric, expl_leapfrog, BaseRNG >::set_max_depth(), stan::mcmc::base_nuts< Model, diag_e_metric, expl_leapfrog, BaseRNG >::set_metric(), stan::mcmc::base_hmc< Model, diag_e_metric, expl_leapfrog, BaseRNG >::set_nominal_stepsize(), stan::mcmc::base_hmc< Model, diag_e_metric, expl_leapfrog, BaseRNG >::set_stepsize_jitter(), and stan::services::util::validate_diag_inv_metric().

Referenced by hmc_nuts_diag_e(), and TEST_F().

61  {
62  boost::ecuyer1988 rng = util::create_rng(random_seed, chain);
63  std::vector<int> disc_vector;
64  std::vector<double> cont_vector
65  = util::initialize(model, init, rng, init_radius, true,
66  logger, init_writer);
67 
68  Eigen::VectorXd inv_metric;
69  try {
70  inv_metric =
71  util::read_diag_inv_metric(init_inv_metric, model.num_params_r(),
72  logger);
73  util::validate_diag_inv_metric(inv_metric, logger);
74  } catch (const std::domain_error& e) {
75  return error_codes::CONFIG;
76  }
77 
79  sampler(model, rng);
80 
81  sampler.set_metric(inv_metric);
82  sampler.set_nominal_stepsize(stepsize);
83  sampler.set_stepsize_jitter(stepsize_jitter);
84  sampler.set_max_depth(max_depth);
85 
86  util::run_sampler(sampler, model, cont_vector, num_warmup, num_samples,
87  num_thin, refresh, save_warmup, rng,
88  interrupt, logger,
89  sample_writer, diagnostic_writer);
90 
91  return error_codes::OK;
92  }
chain
Check that an output directory exists.
void validate_diag_inv_metric(const Eigen::VectorXd &inv_metric, callbacks::logger &logger)
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 domain_error(const char *function, const char *name, const T &y, const char *msg1, const char *msg2)
Eigen::VectorXd read_diag_inv_metric(stan::io::var_context &init_context, size_t num_params, callbacks::logger &logger)
void run_sampler(stan::mcmc::base_mcmc &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)
Definition: run_sampler.hpp:36
Float_t e
Definition: plot.C:35
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
template<class Model >
int stan::services::sample::hmc_nuts_diag_e ( 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,
int  max_depth,
callbacks::interrupt interrupt,
callbacks::logger logger,
callbacks::writer init_writer,
callbacks::writer sample_writer,
callbacks::writer diagnostic_writer 
)

Runs HMC with NUTS without adaptation using diagonal Euclidean metric, with identity matrix as initial inv_metric.

Template Parameters
ModelModel class
Parameters
[in]modelInput model to test (with data already instantiated)
[in]initvar context for initialization
[in]random_seedrandom seed for the random number generator
[in]chainchain id to advance the pseudo random number generator
[in]init_radiusradius to initialize
[in]num_warmupNumber of warmup samples
[in]num_samplesNumber of samples
[in]num_thinNumber to thin the samples
[in]save_warmupIndicates whether to save the warmup iterations
[in]refreshControls the output
[in]stepsizeinitial stepsize for discrete evolution
[in]stepsize_jitteruniform random jitter of stepsize
[in]max_depthMaximum tree depth
[in,out]interruptCallback for interrupts
[in,out]loggerLogger for messages
[in,out]init_writerWriter callback for unconstrained inits
[in,out]sample_writerWriter for draws
[in,out]diagnostic_writerWriter for diagnostic information
Returns
error_codes::OK if successful

Definition at line 120 of file hmc_nuts_diag_e.hpp.

References stan::services::util::create_unit_e_diag_inv_metric(), and hmc_nuts_diag_e().

130  {
131  stan::io::dump dmp =
133  stan::io::var_context& unit_e_metric = dmp;
134 
135  return hmc_nuts_diag_e(model, init, unit_e_metric,
136  random_seed, chain, init_radius, num_warmup,
137  num_samples, num_thin, save_warmup, refresh,
138  stepsize, stepsize_jitter, max_depth,
139  interrupt, logger,
140  init_writer, sample_writer, diagnostic_writer);
141  }
stan::io::dump create_unit_e_diag_inv_metric(size_t num_params)
int hmc_nuts_diag_e(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, int max_depth, callbacks::interrupt &interrupt, callbacks::logger &logger, callbacks::writer &init_writer, callbacks::writer &sample_writer, callbacks::writer &diagnostic_writer)
chain
Check that an output directory exists.
const XML_Char XML_Content * model
Definition: expat.h:151
void refresh()
Definition: show_event.C:21
template<class Model >
int stan::services::sample::hmc_nuts_diag_e_adapt ( Model model,
stan::io::var_context init,
stan::io::var_context init_inv_metric,
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,
int  max_depth,
double  delta,
double  gamma,
double  kappa,
double  t0,
unsigned int  init_buffer,
unsigned int  term_buffer,
unsigned int  window,
callbacks::interrupt interrupt,
callbacks::logger logger,
callbacks::writer init_writer,
callbacks::writer sample_writer,
callbacks::writer diagnostic_writer 
)

Runs HMC with NUTS with adaptation using diagonal Euclidean metric with a pre-specified Euclidean metric.

Template Parameters
ModelModel class
Parameters
[in]modelInput model to test (with data already instantiated)
[in]initvar context for initialization
[in]init_inv_metricvar context exposing an initial diagonal inverse Euclidean metric (must be positive definite)
[in]random_seedrandom seed for the random number generator
[in]chainchain id to advance the pseudo random number generator
[in]init_radiusradius to initialize
[in]num_warmupNumber of warmup samples
[in]num_samplesNumber of samples
[in]num_thinNumber to thin the samples
[in]save_warmupIndicates whether to save the warmup iterations
[in]refreshControls the output
[in]stepsizeinitial stepsize for discrete evolution
[in]stepsize_jitteruniform random jitter of stepsize
[in]max_depthMaximum tree depth
[in]deltaadaptation target acceptance statistic
[in]gammaadaptation regularization scale
[in]kappaadaptation relaxation exponent
[in]t0adaptation iteration offset
[in]init_bufferwidth of initial fast adaptation interval
[in]term_bufferwidth of final fast adaptation interval
[in]windowinitial width of slow adaptation interval
[in,out]interruptCallback for interrupts
[in,out]loggerLogger for messages
[in,out]init_writerWriter callback for unconstrained inits
[in,out]sample_writerWriter for draws
[in,out]diagnostic_writerWriter for diagnostic information
Returns
error_codes::OK if successful

Definition at line 57 of file hmc_nuts_diag_e_adapt.hpp.

References stan::services::error_codes::CONFIG, stan::services::util::create_rng(), stan::math::domain_error(), e, stan::mcmc::stepsize_var_adapter::get_stepsize_adaptation(), stan::services::util::initialize(), test_ParserArtEvents::log, stan::services::error_codes::OK, stan::services::util::read_diag_inv_metric(), stan::services::util::run_adaptive_sampler(), stan::mcmc::base_nuts< Model, diag_e_metric, expl_leapfrog, BaseRNG >::set_max_depth(), stan::mcmc::base_nuts< Model, diag_e_metric, expl_leapfrog, BaseRNG >::set_metric(), stan::mcmc::base_hmc< Model, diag_e_metric, expl_leapfrog, BaseRNG >::set_nominal_stepsize(), stan::mcmc::base_hmc< Model, diag_e_metric, expl_leapfrog, BaseRNG >::set_stepsize_jitter(), stan::mcmc::stepsize_var_adapter::set_window_params(), and stan::services::util::validate_diag_inv_metric().

Referenced by stan::test::performance::command(), ana::StanFitter::FitHelperSeeded(), hmc_nuts_diag_e_adapt(), and TEST_F().

71  {
72  boost::ecuyer1988 rng = util::create_rng(random_seed, chain);
73 
74  std::vector<int> disc_vector;
75  std::vector<double> cont_vector
76  = util::initialize(model, init, rng, init_radius, true,
77  logger, init_writer);
78 
79  Eigen::VectorXd inv_metric;
80  try {
81  inv_metric =
82  util::read_diag_inv_metric(init_inv_metric, model.num_params_r(),
83  logger);
84  util::validate_diag_inv_metric(inv_metric, logger);
85  } catch (const std::domain_error& e) {
86  return error_codes::CONFIG;
87  }
88 
90  sampler(model, rng);
91 
92  sampler.set_metric(inv_metric);
93  sampler.set_nominal_stepsize(stepsize);
94  sampler.set_stepsize_jitter(stepsize_jitter);
95  sampler.set_max_depth(max_depth);
96 
97  sampler.get_stepsize_adaptation().set_mu(log(10 * stepsize));
98  sampler.get_stepsize_adaptation().set_delta(delta);
99  sampler.get_stepsize_adaptation().set_gamma(gamma);
100  sampler.get_stepsize_adaptation().set_kappa(kappa);
101  sampler.get_stepsize_adaptation().set_t0(t0);
102 
103  sampler.set_window_params(num_warmup, init_buffer, term_buffer,
104  window, logger);
105 
106  util::run_adaptive_sampler(sampler, model, cont_vector, num_warmup,
107  num_samples, num_thin, refresh, save_warmup,
108  rng, interrupt, logger,
109  sample_writer, diagnostic_writer);
110 
111  return error_codes::OK;
112  }
double delta
Definition: runWimpSim.h:98
chain
Check that an output directory exists.
void validate_diag_inv_metric(const Eigen::VectorXd &inv_metric, callbacks::logger &logger)
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 domain_error(const char *function, const char *name, const T &y, const char *msg1, const char *msg2)
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)
Eigen::VectorXd read_diag_inv_metric(stan::io::var_context &init_context, size_t num_params, callbacks::logger &logger)
Float_t e
Definition: plot.C:35
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
template<class Model >
int stan::services::sample::hmc_nuts_diag_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,
int  max_depth,
double  delta,
double  gamma,
double  kappa,
double  t0,
unsigned int  init_buffer,
unsigned int  term_buffer,
unsigned int  window,
callbacks::interrupt interrupt,
callbacks::logger logger,
callbacks::writer init_writer,
callbacks::writer sample_writer,
callbacks::writer diagnostic_writer 
)

Runs HMC with NUTS with adaptation using diagonal Euclidean metric.

Template Parameters
ModelModel class
Parameters
[in]modelInput model to test (with data already instantiated)
[in]initvar context for initialization
[in]random_seedrandom seed for the random number generator
[in]chainchain id to advance the pseudo random number generator
[in]init_radiusradius to initialize
[in]num_warmupNumber of warmup samples
[in]num_samplesNumber of samples
[in]num_thinNumber to thin the samples
[in]save_warmupIndicates whether to save the warmup iterations
[in]refreshControls the output
[in]stepsizeinitial stepsize for discrete evolution
[in]stepsize_jitteruniform random jitter of stepsize
[in]max_depthMaximum tree depth
[in]deltaadaptation target acceptance statistic
[in]gammaadaptation regularization scale
[in]kappaadaptation relaxation exponent
[in]t0adaptation iteration offset
[in]init_bufferwidth of initial fast adaptation interval
[in]term_bufferwidth of final fast adaptation interval
[in]windowinitial width of slow adaptation interval
[in,out]interruptCallback for interrupts
[in,out]loggerLogger for messages
[in,out]init_writerWriter callback for unconstrained inits
[in,out]sample_writerWriter for draws
[in,out]diagnostic_writerWriter for diagnostic information
Returns
error_codes::OK if successful

Definition at line 146 of file hmc_nuts_diag_e_adapt.hpp.

References stan::services::util::create_unit_e_diag_inv_metric(), and hmc_nuts_diag_e_adapt().

159  {
160  stan::io::dump dmp =
162  stan::io::var_context& unit_e_metric = dmp;
163 
164  return hmc_nuts_diag_e_adapt(model, init, unit_e_metric,
165  random_seed, chain, init_radius,
166  num_warmup, num_samples, num_thin,
167  save_warmup, refresh,
168  stepsize, stepsize_jitter, max_depth,
169  delta, gamma, kappa, t0,
170  init_buffer, term_buffer, window,
171  interrupt, logger,
172  init_writer, sample_writer,
173  diagnostic_writer);
174  }
double delta
Definition: runWimpSim.h:98
int hmc_nuts_diag_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, int max_depth, double delta, double gamma, double kappa, double t0, unsigned int init_buffer, unsigned int term_buffer, unsigned int window, callbacks::interrupt &interrupt, callbacks::logger &logger, callbacks::writer &init_writer, callbacks::writer &sample_writer, callbacks::writer &diagnostic_writer)
stan::io::dump create_unit_e_diag_inv_metric(size_t num_params)
chain
Check that an output directory exists.
const XML_Char XML_Content * model
Definition: expat.h:151
void refresh()
Definition: show_event.C:21
template<class Model >
int stan::services::sample::hmc_nuts_unit_e ( 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,
int  max_depth,
callbacks::interrupt interrupt,
callbacks::logger logger,
callbacks::writer init_writer,
callbacks::writer sample_writer,
callbacks::writer diagnostic_writer 
)

Runs HMC with NUTS with unit Euclidean metric without adaptation.

Template Parameters
ModelModel class
Parameters
[in]modelInput model to test (with data already instantiated)
[in]initvar context for initialization
[in]random_seedrandom seed for the random number generator
[in]chainchain id to advance the pseudo random number generator
[in]init_radiusradius to initialize
[in]num_warmupNumber of warmup samples
[in]num_samplesNumber of samples
[in]num_thinNumber to thin the samples
[in]save_warmupIndicates whether to save the warmup iterations
[in]refreshControls the output
[in]stepsizeinitial stepsize for discrete evolution
[in]stepsize_jitteruniform random jitter of stepsize
[in]max_depthMaximum tree depth
[in,out]interruptCallback for interrupts
[in,out]loggerLogger for messages
[in,out]init_writerWriter callback for unconstrained inits
[in,out]sample_writerWriter for draws
[in,out]diagnostic_writerWriter for diagnostic information
Returns
error_codes::OK if successful

Definition at line 45 of file hmc_nuts_unit_e.hpp.

References stan::services::util::create_rng(), stan::services::util::initialize(), stan::services::error_codes::OK, stan::services::util::run_sampler(), stan::mcmc::base_nuts< Model, unit_e_metric, expl_leapfrog, BaseRNG >::set_max_depth(), stan::mcmc::base_hmc< Model, unit_e_metric, expl_leapfrog, BaseRNG >::set_nominal_stepsize(), and stan::mcmc::base_hmc< Model, unit_e_metric, expl_leapfrog, BaseRNG >::set_stepsize_jitter().

Referenced by TEST_F().

55  {
56  boost::ecuyer1988 rng = util::create_rng(random_seed, chain);
57 
58  std::vector<int> disc_vector;
59  std::vector<double> cont_vector
60  = util::initialize(model, init, rng, init_radius, true,
61  logger, init_writer);
62 
64  sampler.set_nominal_stepsize(stepsize);
65  sampler.set_stepsize_jitter(stepsize_jitter);
66  sampler.set_max_depth(max_depth);
67 
68  util::run_sampler(sampler, model, cont_vector, num_warmup, num_samples,
69  num_thin, refresh, save_warmup, rng, interrupt,
70  logger,
71  sample_writer, diagnostic_writer);
72 
73  return error_codes::OK;
74  }
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_sampler(stan::mcmc::base_mcmc &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)
Definition: run_sampler.hpp:36
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
template<class Model >
int stan::services::sample::hmc_nuts_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,
int  max_depth,
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 
)

Runs HMC with NUTS with unit Euclidean metric with adaptation.

Template Parameters
ModelModel class
Parameters
[in]modelInput model to test (with data already instantiated)
[in]initvar context for initialization
[in]random_seedrandom seed for the random number generator
[in]chainchain id to advance the pseudo random number generator
[in]init_radiusradius to initialize
[in]num_warmupNumber of warmup samples
[in]num_samplesNumber of samples
[in]num_thinNumber to thin the samples
[in]save_warmupIndicates whether to save the warmup iterations
[in]refreshControls the output
[in]stepsizeinitial stepsize for discrete evolution
[in]stepsize_jitteruniform random jitter of stepsize
[in]max_depthMaximum tree depth
[in]deltaadaptation target acceptance statistic
[in]gammaadaptation regularization scale
[in]kappaadaptation relaxation exponent
[in]t0adaptation iteration offset
[in,out]interruptCallback for interrupts
[in,out]loggerLogger for messages
[in,out]init_writerWriter callback for unconstrained inits
[in,out]sample_writerWriter for draws
[in,out]diagnostic_writerWriter for diagnostic information
Returns
error_codes::OK if successful

Definition at line 49 of file hmc_nuts_unit_e_adapt.hpp.

References stan::services::util::create_rng(), stan::mcmc::stepsize_adapter::get_stepsize_adaptation(), stan::services::util::initialize(), test_ParserArtEvents::log, stan::services::error_codes::OK, stan::services::util::run_adaptive_sampler(), stan::mcmc::base_nuts< Model, unit_e_metric, expl_leapfrog, BaseRNG >::set_max_depth(), stan::mcmc::base_hmc< Model, unit_e_metric, expl_leapfrog, BaseRNG >::set_nominal_stepsize(), and stan::mcmc::base_hmc< Model, unit_e_metric, expl_leapfrog, BaseRNG >::set_stepsize_jitter().

Referenced by TEST_F().

61  {
62  boost::ecuyer1988 rng = util::create_rng(random_seed, chain);
63 
64  std::vector<int> disc_vector;
65  std::vector<double> cont_vector
66  = util::initialize(model, init, rng, init_radius, true,
67  logger, init_writer);
68 
70  sampler(model, rng);
71  sampler.set_nominal_stepsize(stepsize);
72  sampler.set_stepsize_jitter(stepsize_jitter);
73  sampler.set_max_depth(max_depth);
74 
75  sampler.get_stepsize_adaptation().set_mu(log(10 * stepsize));
76  sampler.get_stepsize_adaptation().set_delta(delta);
77  sampler.get_stepsize_adaptation().set_gamma(gamma);
78  sampler.get_stepsize_adaptation().set_kappa(kappa);
79  sampler.get_stepsize_adaptation().set_t0(t0);
80 
81  util::run_adaptive_sampler(sampler, model, cont_vector, num_warmup,
82  num_samples, num_thin, refresh, save_warmup,
83  rng, interrupt, logger,
84  sample_writer, diagnostic_writer);
85 
86  return error_codes::OK;
87  }
double delta
Definition: runWimpSim.h:98
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)
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
template<class Model >
int stan::services::sample::hmc_static_dense_e ( Model model,
stan::io::var_context init,
stan::io::var_context init_inv_metric,
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,
callbacks::interrupt interrupt,
callbacks::logger logger,
callbacks::writer init_writer,
callbacks::writer sample_writer,
callbacks::writer diagnostic_writer 
)

Runs static HMC without adaptation using dense Euclidean metric with a pre-specified Euclidean metric.

Template Parameters
ModelModel class
Parameters
[in]modelInput model to test (with data already instantiated)
[in]initvar context for initialization
[in]init_inv_metricvar context exposing an initial diagonal inverse Euclidean metric (must be positive definite)
[in]random_seedrandom seed for the random number generator
[in]chainchain id to advance the pseudo random number generator
[in]init_radiusradius to initialize
[in]num_warmupNumber of warmup samples
[in]num_samplesNumber of samples
[in]num_thinNumber to thin the samples
[in]save_warmupIndicates whether to save the warmup iterations
[in]refreshControls the output
[in]stepsizeinitial stepsize for discrete evolution
[in]stepsize_jitteruniform random jitter of stepsize
[in]int_timeintegration time
[in,out]interruptCallback for interrupts
[in,out]loggerLogger for messages
[in,out]init_writerWriter callback for unconstrained inits
[in,out]sample_writerWriter for draws
[in,out]diagnostic_writerWriter for diagnostic information
Returns
error_codes::OK if successful

Definition at line 48 of file hmc_static_dense_e.hpp.

References stan::services::error_codes::CONFIG, stan::services::util::create_rng(), stan::math::domain_error(), e, stan::services::util::initialize(), stan::services::error_codes::OK, stan::services::util::read_dense_inv_metric(), stan::services::util::run_sampler(), stan::mcmc::base_static_hmc< Model, dense_e_metric, expl_leapfrog, BaseRNG >::set_metric(), stan::mcmc::base_static_hmc< Model, dense_e_metric, expl_leapfrog, BaseRNG >::set_nominal_stepsize_and_T(), stan::mcmc::base_hmc< Model, dense_e_metric, expl_leapfrog, BaseRNG >::set_stepsize_jitter(), and stan::services::util::validate_dense_inv_metric().

Referenced by hmc_static_dense_e(), and TEST_F().

60  {
61  boost::ecuyer1988 rng = util::create_rng(random_seed, chain);
62 
63  std::vector<int> disc_vector;
64  std::vector<double> cont_vector
65  = util::initialize(model, init, rng, init_radius, true,
66  logger, init_writer);
67 
68  Eigen::MatrixXd inv_metric;
69  try {
70  inv_metric =
71  util::read_dense_inv_metric(init_inv_metric, model.num_params_r(),
72  logger);
73  util::validate_dense_inv_metric(inv_metric, logger);
74  } catch (const std::domain_error& e) {
75  return error_codes::CONFIG;
76  }
77 
79  sampler(model, rng);
80 
81  sampler.set_metric(inv_metric);
82  sampler.set_nominal_stepsize_and_T(stepsize, int_time);
83  sampler.set_stepsize_jitter(stepsize_jitter);
84 
85  util::run_sampler(sampler, model, cont_vector, num_warmup, num_samples,
86  num_thin, refresh, save_warmup, rng, interrupt,
87  logger,
88  sample_writer, diagnostic_writer);
89 
90  return error_codes::OK;
91  }
void validate_dense_inv_metric(const Eigen::MatrixXd &inv_metric, callbacks::logger &logger)
Eigen::MatrixXd read_dense_inv_metric(stan::io::var_context &init_context, size_t num_params, callbacks::logger &logger)
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 domain_error(const char *function, const char *name, const T &y, const char *msg1, const char *msg2)
void run_sampler(stan::mcmc::base_mcmc &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)
Definition: run_sampler.hpp:36
Float_t e
Definition: plot.C:35
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
template<class Model >
int stan::services::sample::hmc_static_dense_e ( 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,
callbacks::interrupt interrupt,
callbacks::logger logger,
callbacks::writer init_writer,
callbacks::writer sample_writer,
callbacks::writer diagnostic_writer 
)

Runs static HMC without adaptation using dense Euclidean metric, with identity matrix as initial inv_metric.

Template Parameters
ModelModel class
Parameters
[in]modelInput model to test (with data already instantiated)
[in]initvar context for initialization
[in]random_seedrandom seed for the random number generator
[in]chainchain id to advance the pseudo random number generator
[in]init_radiusradius to initialize
[in]num_warmupNumber of warmup samples
[in]num_samplesNumber of samples
[in]num_thinNumber to thin the samples
[in]save_warmupIndicates whether to save the warmup iterations
[in]refreshControls the output
[in]stepsizeinitial stepsize for discrete evolution
[in]stepsize_jitteruniform random jitter of stepsize
[in]int_timeintegration time
[in,out]interruptCallback for interrupts
[in,out]loggerLogger for messages
[in,out]init_writerWriter callback for unconstrained inits
[in,out]sample_writerWriter for draws
[in,out]diagnostic_writerWriter for diagnostic information
Returns
error_codes::OK if successful

Definition at line 120 of file hmc_static_dense_e.hpp.

References stan::services::util::create_unit_e_dense_inv_metric(), and hmc_static_dense_e().

131  {
132  stan::io::dump dmp =
134  stan::io::var_context& unit_e_metric = dmp;
135 
136  return hmc_static_dense_e(model, init, unit_e_metric,
137  random_seed, chain, init_radius, num_warmup,
138  num_samples, num_thin, save_warmup, refresh,
139  stepsize, stepsize_jitter, int_time,
140  interrupt, logger,
141  init_writer, sample_writer, diagnostic_writer);
142  }
stan::io::dump create_unit_e_dense_inv_metric(size_t num_params)
chain
Check that an output directory exists.
int hmc_static_dense_e(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, callbacks::interrupt &interrupt, callbacks::logger &logger, callbacks::writer &init_writer, callbacks::writer &sample_writer, callbacks::writer &diagnostic_writer)
const XML_Char XML_Content * model
Definition: expat.h:151
void refresh()
Definition: show_event.C:21
template<class Model >
int stan::services::sample::hmc_static_dense_e_adapt ( Model model,
stan::io::var_context init,
stan::io::var_context init_inv_metric,
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,
unsigned int  init_buffer,
unsigned int  term_buffer,
unsigned int  window,
callbacks::interrupt interrupt,
callbacks::logger logger,
callbacks::writer init_writer,
callbacks::writer sample_writer,
callbacks::writer diagnostic_writer 
)

Runs static HMC with adaptation using dense Euclidean metric with a pre-specified Euclidean metric.

Template Parameters
ModelModel class
Parameters
[in]modelInput model to test (with data already instantiated)
[in]initvar context for initialization
[in]init_inv_metricvar context exposing an initial diagonal inverse Euclidean metric (must be positive definite)
[in]random_seedrandom seed for the random number generator
[in]chainchain id to advance the pseudo random number generator
[in]init_radiusradius to initialize
[in]num_warmupNumber of warmup samples
[in]num_samplesNumber of samples
[in]num_thinNumber to thin the samples
[in]save_warmupIndicates whether to save the warmup iterations
[in]refreshControls the output
[in]stepsizeinitial stepsize for discrete evolution
[in]stepsize_jitteruniform random jitter of stepsize
[in]int_timeintegration time
[in]deltaadaptation target acceptance statistic
[in]gammaadaptation regularization scale
[in]kappaadaptation relaxation exponent
[in]t0adaptation iteration offset
[in]init_bufferwidth of initial fast adaptation interval
[in]term_bufferwidth of final fast adaptation interval
[in]windowinitial width of slow adaptation interval
[in,out]interruptCallback for interrupts
[in,out]loggerLogger for messages
[in,out]init_writerWriter callback for unconstrained inits
[in,out]sample_writerWriter for draws
[in,out]diagnostic_writerWriter for diagnostic information
Returns
error_codes::OK if successful

Definition at line 57 of file hmc_static_dense_e_adapt.hpp.

References stan::services::error_codes::CONFIG, stan::services::util::create_rng(), stan::math::domain_error(), e, stan::mcmc::stepsize_covar_adapter::get_stepsize_adaptation(), stan::services::util::initialize(), test_ParserArtEvents::log, stan::services::error_codes::OK, stan::services::util::read_dense_inv_metric(), stan::services::util::run_adaptive_sampler(), stan::mcmc::base_static_hmc< Model, dense_e_metric, expl_leapfrog, BaseRNG >::set_metric(), stan::mcmc::base_static_hmc< Model, dense_e_metric, expl_leapfrog, BaseRNG >::set_nominal_stepsize_and_T(), stan::mcmc::base_hmc< Model, dense_e_metric, expl_leapfrog, BaseRNG >::set_stepsize_jitter(), stan::mcmc::stepsize_covar_adapter::set_window_params(), and stan::services::util::validate_dense_inv_metric().

Referenced by hmc_static_dense_e_adapt(), and TEST_F().

73  {
74  boost::ecuyer1988 rng = util::create_rng(random_seed, chain);
75 
76  std::vector<int> disc_vector;
77  std::vector<double> cont_vector
78  = util::initialize(model, init, rng, init_radius, true,
79  logger, init_writer);
80 
81  Eigen::MatrixXd inv_metric;
82  try {
83  inv_metric =
84  util::read_dense_inv_metric(init_inv_metric, model.num_params_r(),
85  logger);
86  util::validate_dense_inv_metric(inv_metric, logger);
87  } catch (const std::domain_error& e) {
88  return error_codes::CONFIG;
89  }
90 
92  sampler(model, rng);
93 
94  sampler.set_metric(inv_metric);
95  sampler.set_nominal_stepsize_and_T(stepsize, int_time);
96  sampler.set_stepsize_jitter(stepsize_jitter);
97 
98  sampler.get_stepsize_adaptation().set_mu(log(10 * stepsize));
99  sampler.get_stepsize_adaptation().set_delta(delta);
100  sampler.get_stepsize_adaptation().set_gamma(gamma);
101  sampler.get_stepsize_adaptation().set_kappa(kappa);
102  sampler.get_stepsize_adaptation().set_t0(t0);
103 
104  sampler.set_window_params(num_warmup, init_buffer, term_buffer,
105  window, logger);
106 
107  util::run_adaptive_sampler(sampler, model, cont_vector, num_warmup,
108  num_samples, num_thin, refresh, save_warmup,
109  rng, interrupt, logger,
110  sample_writer, diagnostic_writer);
111 
112  return error_codes::OK;
113  }
double delta
Definition: runWimpSim.h:98
void validate_dense_inv_metric(const Eigen::MatrixXd &inv_metric, callbacks::logger &logger)
Eigen::MatrixXd read_dense_inv_metric(stan::io::var_context &init_context, size_t num_params, callbacks::logger &logger)
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 domain_error(const char *function, const char *name, const T &y, const char *msg1, const char *msg2)
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)
Float_t e
Definition: plot.C:35
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
template<class Model >
int stan::services::sample::hmc_static_dense_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,
unsigned int  init_buffer,
unsigned int  term_buffer,
unsigned int  window,
callbacks::interrupt interrupt,
callbacks::logger logger,
callbacks::writer init_writer,
callbacks::writer sample_writer,
callbacks::writer diagnostic_writer 
)

Runs static HMC with adaptation using dense Euclidean metric. with identity matrix as initial inv_metric.

Template Parameters
ModelModel class
Parameters
[in]modelInput model to test (with data already instantiated)
[in]initvar context for initialization
[in]random_seedrandom seed for the random number generator
[in]chainchain id to advance the pseudo random number generator
[in]init_radiusradius to initialize
[in]num_warmupNumber of warmup samples
[in]num_samplesNumber of samples
[in]num_thinNumber to thin the samples
[in]save_warmupIndicates whether to save the warmup iterations
[in]refreshControls the output
[in]stepsizeinitial stepsize for discrete evolution
[in]stepsize_jitteruniform random jitter of stepsize
[in]int_timeintegration time
[in]deltaadaptation target acceptance statistic
[in]gammaadaptation regularization scale
[in]kappaadaptation relaxation exponent
[in]t0adaptation iteration offset
[in]init_bufferwidth of initial fast adaptation interval
[in]term_bufferwidth of final fast adaptation interval
[in]windowinitial width of slow adaptation interval
[in,out]interruptCallback for interrupts
[in,out]loggerLogger for messages
[in,out]init_writerWriter callback for unconstrained inits
[in,out]sample_writerWriter for draws
[in,out]diagnostic_writerWriter for diagnostic information
Returns
error_codes::OK if successful

Definition at line 148 of file hmc_static_dense_e_adapt.hpp.

References stan::services::util::create_unit_e_dense_inv_metric(), and hmc_static_dense_e_adapt().

163  {
164  stan::io::dump dmp =
166  stan::io::var_context& unit_e_metric = dmp;
167 
168  return hmc_static_dense_e_adapt(model, init, unit_e_metric,
169  random_seed, chain, init_radius,
170  num_warmup, num_samples, num_thin,
171  save_warmup, refresh,
172  stepsize, stepsize_jitter, int_time,
173  delta, gamma, kappa, t0,
174  init_buffer, term_buffer, window,
175  interrupt, logger,
176  init_writer, sample_writer,
177  diagnostic_writer);
178  }
double delta
Definition: runWimpSim.h:98
stan::io::dump create_unit_e_dense_inv_metric(size_t num_params)
chain
Check that an output directory exists.
int hmc_static_dense_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, unsigned int init_buffer, unsigned int term_buffer, unsigned int window, callbacks::interrupt &interrupt, callbacks::logger &logger, callbacks::writer &init_writer, callbacks::writer &sample_writer, callbacks::writer &diagnostic_writer)
const XML_Char XML_Content * model
Definition: expat.h:151
void refresh()
Definition: show_event.C:21
template<class Model >
int stan::services::sample::hmc_static_diag_e ( Model model,
stan::io::var_context init,
stan::io::var_context init_inv_metric,
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,
callbacks::interrupt interrupt,
callbacks::logger logger,
callbacks::writer init_writer,
callbacks::writer sample_writer,
callbacks::writer diagnostic_writer 
)

Runs static HMC without adaptation using diagonal Euclidean metric with a pre-specified Euclidean metric.

Template Parameters
ModelModel class
Parameters
[in]modelInput model to test (with data already instantiated)
[in]initvar context for initialization
[in]init_inv_metricvar context exposing an initial diagonal inverse Euclidean metric (must be positive definite)
[in]random_seedrandom seed for the random number generator
[in]chainchain id to advance the pseudo random number generator
[in]init_radiusradius to initialize
[in]num_warmupNumber of warmup samples
[in]num_samplesNumber of samples
[in]num_thinNumber to thin the samples
[in]save_warmupIndicates whether to save the warmup iterations
[in]refreshControls the output
[in]stepsizeinitial stepsize for discrete evolution
[in]stepsize_jitteruniform random jitter of stepsize
[in]int_timeintegration time
[in,out]interruptCallback for interrupts
[in,out]loggerLogger for messages
[in,out]init_writerWriter callback for unconstrained inits
[in,out]sample_writerWriter for draws
[in,out]diagnostic_writerWriter for diagnostic information
Returns
error_codes::OK if successful

Definition at line 51 of file hmc_static_diag_e.hpp.

References stan::services::error_codes::CONFIG, stan::services::util::create_rng(), stan::math::domain_error(), e, stan::services::util::initialize(), stan::services::error_codes::OK, stan::services::util::read_diag_inv_metric(), stan::services::util::run_sampler(), stan::mcmc::base_static_hmc< Model, diag_e_metric, expl_leapfrog, BaseRNG >::set_metric(), stan::mcmc::base_static_hmc< Model, diag_e_metric, expl_leapfrog, BaseRNG >::set_nominal_stepsize_and_T(), stan::mcmc::base_hmc< Model, diag_e_metric, expl_leapfrog, BaseRNG >::set_stepsize_jitter(), and stan::services::util::validate_diag_inv_metric().

Referenced by hmc_static_diag_e(), and TEST_F().

62  {
63  boost::ecuyer1988 rng = util::create_rng(random_seed, chain);
64 
65  std::vector<int> disc_vector;
66  std::vector<double> cont_vector
67  = util::initialize(model, init, rng, init_radius, true,
68  logger, init_writer);
69 
70  Eigen::VectorXd inv_metric;
71  try {
72  inv_metric =
73  util::read_diag_inv_metric(init_inv_metric, model.num_params_r(),
74  logger);
75  util::validate_diag_inv_metric(inv_metric, logger);
76  } catch (const std::domain_error& e) {
77  return error_codes::CONFIG;
78  }
79 
81  sampler(model, rng);
82 
83  sampler.set_metric(inv_metric);
84  sampler.set_nominal_stepsize_and_T(stepsize, int_time);
85  sampler.set_stepsize_jitter(stepsize_jitter);
86 
87  util::run_sampler(sampler, model, cont_vector, num_warmup, num_samples,
88  num_thin, refresh, save_warmup, rng, interrupt,
89  logger, sample_writer, diagnostic_writer);
90 
91  return error_codes::OK;
92  }
chain
Check that an output directory exists.
void validate_diag_inv_metric(const Eigen::VectorXd &inv_metric, callbacks::logger &logger)
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 domain_error(const char *function, const char *name, const T &y, const char *msg1, const char *msg2)
Eigen::VectorXd read_diag_inv_metric(stan::io::var_context &init_context, size_t num_params, callbacks::logger &logger)
void run_sampler(stan::mcmc::base_mcmc &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)
Definition: run_sampler.hpp:36
Float_t e
Definition: plot.C:35
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
template<class Model >
int stan::services::sample::hmc_static_diag_e ( 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,
callbacks::interrupt interrupt,
callbacks::logger logger,
callbacks::writer init_writer,
callbacks::writer sample_writer,
callbacks::writer diagnostic_writer 
)

Runs static HMC without adaptation using diagonal Euclidean metric. with identity matrix as initial inv_metric.

Template Parameters
ModelModel class
Parameters
[in]modelInput model to test (with data already instantiated)
[in]initvar context for initialization
[in]random_seedrandom seed for the random number generator
[in]chainchain id to advance the pseudo random number generator
[in]init_radiusradius to initialize
[in]num_warmupNumber of warmup samples
[in]num_samplesNumber of samples
[in]num_thinNumber to thin the samples
[in]save_warmupIndicates whether to save the warmup iterations
[in]refreshControls the output
[in]stepsizeinitial stepsize for discrete evolution
[in]stepsize_jitteruniform random jitter of stepsize
[in]int_timeintegration time
[in,out]interruptCallback for interrupts
[in,out]loggerLogger for messages
[in,out]init_writerWriter callback for unconstrained inits
[in,out]sample_writerWriter for draws
[in,out]diagnostic_writerWriter for diagnostic information
Returns
error_codes::OK if successful

Definition at line 120 of file hmc_static_diag_e.hpp.

References stan::services::util::create_unit_e_diag_inv_metric(), and hmc_static_diag_e().

130  {
131  stan::io::dump dmp =
133  stan::io::var_context& unit_e_metric = dmp;
134 
135  return hmc_static_diag_e(model, init, unit_e_metric,
136  random_seed, chain, init_radius, num_warmup,
137  num_samples, num_thin, save_warmup, refresh,
138  stepsize, stepsize_jitter, int_time,
139  interrupt, logger,
140  init_writer, sample_writer, diagnostic_writer);
141  }
stan::io::dump create_unit_e_diag_inv_metric(size_t num_params)
int hmc_static_diag_e(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, callbacks::interrupt &interrupt, callbacks::logger &logger, callbacks::writer &init_writer, callbacks::writer &sample_writer, callbacks::writer &diagnostic_writer)
chain
Check that an output directory exists.
const XML_Char XML_Content * model
Definition: expat.h:151
void refresh()
Definition: show_event.C:21
template<class Model >
int stan::services::sample::hmc_static_diag_e_adapt ( Model model,
stan::io::var_context init,
stan::io::var_context init_inv_metric,
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,
unsigned int  init_buffer,
unsigned int  term_buffer,
unsigned int  window,
callbacks::interrupt interrupt,
callbacks::logger logger,
callbacks::writer init_writer,
callbacks::writer sample_writer,
callbacks::writer diagnostic_writer 
)

Runs static HMC with adaptation using diagonal Euclidean metric with a pre-specified Euclidean metric.

Template Parameters
ModelModel class
Parameters
[in]modelInput model to test (with data already instantiated)
[in]initvar context for initialization
[in]init_inv_metricvar context exposing an initial diagonal inverse Euclidean metric (must be positive definite)
[in]random_seedrandom seed for the random number generator
[in]chainchain id to advance the pseudo random number generator
[in]init_radiusradius to initialize
[in]num_warmupNumber of warmup samples
[in]num_samplesNumber of samples
[in]num_thinNumber to thin the samples
[in]save_warmupIndicates whether to save the warmup iterations
[in]refreshControls the output
[in]stepsizeinitial stepsize for discrete evolution
[in]stepsize_jitteruniform random jitter of stepsize
[in]int_timeintegration time
[in]deltaadaptation target acceptance statistic
[in]gammaadaptation regularization scale
[in]kappaadaptation relaxation exponent
[in]t0adaptation iteration offset
[in]init_bufferwidth of initial fast adaptation interval
[in]term_bufferwidth of final fast adaptation interval
[in]windowinitial width of slow adaptation interval
[in,out]interruptCallback for interrupts
[in,out]loggerLogger for messages
[in,out]init_writerWriter callback for unconstrained inits
[in,out]sample_writerWriter for draws
[in,out]diagnostic_writerWriter for diagnostic information
Returns
error_codes::OK if successful

Definition at line 57 of file hmc_static_diag_e_adapt.hpp.

References stan::services::error_codes::CONFIG, stan::services::util::create_rng(), stan::math::domain_error(), e, stan::mcmc::stepsize_var_adapter::get_stepsize_adaptation(), stan::services::util::initialize(), test_ParserArtEvents::log, stan::services::error_codes::OK, stan::services::util::read_diag_inv_metric(), stan::services::util::run_adaptive_sampler(), stan::mcmc::base_static_hmc< Model, diag_e_metric, expl_leapfrog, BaseRNG >::set_metric(), stan::mcmc::base_static_hmc< Model, diag_e_metric, expl_leapfrog, BaseRNG >::set_nominal_stepsize_and_T(), stan::mcmc::base_hmc< Model, diag_e_metric, expl_leapfrog, BaseRNG >::set_stepsize_jitter(), stan::mcmc::stepsize_var_adapter::set_window_params(), and stan::services::util::validate_diag_inv_metric().

Referenced by hmc_static_diag_e_adapt(), and TEST_F().

72  {
73  boost::ecuyer1988 rng = util::create_rng(random_seed, chain);
74 
75  std::vector<int> disc_vector;
76  std::vector<double> cont_vector
77  = util::initialize(model, init, rng, init_radius, true,
78  logger, init_writer);
79 
80  Eigen::VectorXd inv_metric;
81  try {
82  inv_metric =
83  util::read_diag_inv_metric(init_inv_metric, model.num_params_r(),
84  logger);
85  util::validate_diag_inv_metric(inv_metric, logger);
86  } catch (const std::domain_error& e) {
87  return error_codes::CONFIG;
88  }
89 
91  sampler(model, rng);
92 
93  sampler.set_metric(inv_metric);
94  sampler.set_nominal_stepsize_and_T(stepsize, int_time);
95  sampler.set_stepsize_jitter(stepsize_jitter);
96 
97  sampler.get_stepsize_adaptation().set_mu(log(10 * stepsize));
98  sampler.get_stepsize_adaptation().set_delta(delta);
99  sampler.get_stepsize_adaptation().set_gamma(gamma);
100  sampler.get_stepsize_adaptation().set_kappa(kappa);
101  sampler.get_stepsize_adaptation().set_t0(t0);
102 
103  sampler.set_window_params(num_warmup, init_buffer, term_buffer,
104  window, logger);
105 
106  util::run_adaptive_sampler(sampler, model, cont_vector, num_warmup,
107  num_samples, num_thin, refresh, save_warmup,
108  rng, interrupt, logger,
109  sample_writer, diagnostic_writer);
110 
111  return error_codes::OK;
112  }
double delta
Definition: runWimpSim.h:98
chain
Check that an output directory exists.
void validate_diag_inv_metric(const Eigen::VectorXd &inv_metric, callbacks::logger &logger)
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 domain_error(const char *function, const char *name, const T &y, const char *msg1, const char *msg2)
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)
Eigen::VectorXd read_diag_inv_metric(stan::io::var_context &init_context, size_t num_params, callbacks::logger &logger)
Float_t e
Definition: plot.C:35
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
template<class Model >
int stan::services::sample::hmc_static_diag_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,
unsigned int  init_buffer,
unsigned int  term_buffer,
unsigned int  window,
callbacks::interrupt interrupt,
callbacks::logger logger,
callbacks::writer init_writer,
callbacks::writer sample_writer,
callbacks::writer diagnostic_writer 
)

Runs static HMC with adaptation using diagonal Euclidean metric, with identity matrix as initial inv_metric.

Template Parameters
ModelModel class
Parameters
[in]modelInput model to test (with data already instantiated)
[in]initvar context for initialization
[in]random_seedrandom seed for the random number generator
[in]chainchain id to advance the pseudo random number generator
[in]init_radiusradius to initialize
[in]num_warmupNumber of warmup samples
[in]num_samplesNumber of samples
[in]num_thinNumber to thin the samples
[in]save_warmupIndicates whether to save the warmup iterations
[in]refreshControls the output
[in]stepsizeinitial stepsize for discrete evolution
[in]stepsize_jitteruniform random jitter of stepsize
[in]int_timeintegration time
[in]deltaadaptation target acceptance statistic
[in]gammaadaptation regularization scale
[in]kappaadaptation relaxation exponent
[in]t0adaptation iteration offset
[in]init_bufferwidth of initial fast adaptation interval
[in]term_bufferwidth of final fast adaptation interval
[in]windowinitial width of slow adaptation interval
[in,out]interruptCallback for interrupts
[in,out]loggerLogger for messages
[in,out]init_writerWriter callback for unconstrained inits
[in,out]sample_writerWriter for draws
[in,out]diagnostic_writerWriter for diagnostic information
Returns
error_codes::OK if successful

Definition at line 147 of file hmc_static_diag_e_adapt.hpp.

References stan::services::util::create_unit_e_diag_inv_metric(), and hmc_static_diag_e_adapt().

161  {
162  stan::io::dump dmp =
164  stan::io::var_context& unit_e_metric = dmp;
165 
166  return hmc_static_diag_e_adapt(model, init, unit_e_metric,
167  random_seed, chain, init_radius,
168  num_warmup, num_samples, num_thin,
169  save_warmup, refresh,
170  stepsize, stepsize_jitter, int_time,
171  delta, gamma, kappa, t0,
172  init_buffer, term_buffer, window,
173  interrupt, logger,
174  init_writer, sample_writer,
175  diagnostic_writer);
176  }
int hmc_static_diag_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, unsigned int init_buffer, unsigned int term_buffer, unsigned int window, callbacks::interrupt &interrupt, callbacks::logger &logger, callbacks::writer &init_writer, callbacks::writer &sample_writer, callbacks::writer &diagnostic_writer)
double delta
Definition: runWimpSim.h:98
stan::io::dump create_unit_e_diag_inv_metric(size_t num_params)
chain
Check that an output directory exists.
const XML_Char XML_Content * model
Definition: expat.h:151
void refresh()
Definition: show_event.C:21
template<class Model >
int stan::services::sample::hmc_static_unit_e ( 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,
callbacks::interrupt interrupt,
callbacks::logger logger,
callbacks::writer init_writer,
callbacks::writer sample_writer,
callbacks::writer diagnostic_writer 
)

Runs static HMC with unit Euclidean metric without adaptation.

Template Parameters
ModelModel class
Parameters
[in]modelInput model to test (with data already instantiated)
[in]initvar context for initialization
[in]random_seedrandom seed for the random number generator
[in]chainchain id to advance the pseudo random number generator
[in]init_radiusradius to initialize
[in]num_warmupNumber of warmup samples
[in]num_samplesNumber of samples
[in]num_thinNumber to thin the samples
[in]save_warmupIndicates whether to save the warmup iterations
[in]refreshControls the output
[in]stepsizeinitial stepsize for discrete evolution
[in]stepsize_jitteruniform random jitter of stepsize
[in]int_timeintegration time
[in,out]interruptCallback for interrupts
[in,out]loggerLogger for messages
[in,out]init_writerWriter callback for unconstrained inits
[in,out]sample_writerWriter for draws
[in,out]diagnostic_writerWriter for diagnostic information
Returns
error_codes::OK if successful

Definition at line 46 of file hmc_static_unit_e.hpp.

References stan::services::util::create_rng(), stan::services::util::initialize(), stan::services::error_codes::OK, stan::services::util::run_sampler(), stan::mcmc::base_static_hmc< Model, unit_e_metric, expl_leapfrog, BaseRNG >::set_nominal_stepsize_and_T(), and stan::mcmc::base_hmc< Model, unit_e_metric, expl_leapfrog, BaseRNG >::set_stepsize_jitter().

56  {
57  boost::ecuyer1988 rng = util::create_rng(random_seed, chain);
58 
59  std::vector<int> disc_vector;
60  std::vector<double> cont_vector
61  = util::initialize(model, init, rng, init_radius, true,
62  logger, init_writer);
63 
65  sampler(model, rng);
66  sampler.set_nominal_stepsize_and_T(stepsize, int_time);
67  sampler.set_stepsize_jitter(stepsize_jitter);
68 
69  util::run_sampler(sampler, model, cont_vector, num_warmup, num_samples,
70  num_thin, refresh, save_warmup, rng, interrupt,
71  logger, sample_writer,
72  diagnostic_writer);
73 
74  return error_codes::OK;
75  }
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_sampler(stan::mcmc::base_mcmc &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)
Definition: run_sampler.hpp:36
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
template<class Model >
int stan::services::sample::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 
)

Runs static HMC with unit Euclidean metric with adaptation.

Template Parameters
ModelModel class
Parameters
[in]modelInput model to test (with data already instantiated)
[in]initvar context for initialization
[in]random_seedrandom seed for the random number generator
[in]chainchain id to advance the pseudo random number generator
[in]init_radiusradius to initialize
[in]num_warmupNumber of warmup samples
[in]num_samplesNumber of samples
[in]num_thinNumber to thin the samples
[in]save_warmupIndicates whether to save the warmup iterations
[in]refreshControls the output
[in]stepsizeinitial stepsize for discrete evolution
[in]stepsize_jitteruniform random jitter of stepsize
[in]int_timeintegration time
[in]deltaadaptation target acceptance statistic
[in]gammaadaptation regularization scale
[in]kappaadaptation relaxation exponent
[in]t0adaptation iteration offset
[in,out]interruptCallback for interrupts
[in,out]loggerLogger for messages
[in,out]init_writerWriter callback for unconstrained inits
[in,out]sample_writerWriter for draws
[in,out]diagnostic_writerWriter for diagnostic information
Returns
error_codes::OK if successful

Definition at line 50 of file hmc_static_unit_e_adapt.hpp.

References stan::services::util::create_rng(), stan::mcmc::stepsize_adapter::get_stepsize_adaptation(), stan::services::util::initialize(), test_ParserArtEvents::log, stan::services::error_codes::OK, stan::services::util::run_adaptive_sampler(), stan::mcmc::base_static_hmc< Model, unit_e_metric, expl_leapfrog, BaseRNG >::set_nominal_stepsize_and_T(), and stan::mcmc::base_hmc< Model, unit_e_metric, expl_leapfrog, BaseRNG >::set_stepsize_jitter().

Referenced by TEST_F().

63  {
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  }
double delta
Definition: runWimpSim.h:98
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)
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