Classes | Functions
stan::services::experimental::advi Namespace Reference

Classes

struct  adapt_engaged
 
struct  adapt_iterations
 
struct  elbo_samples
 
struct  eta
 
struct  eval_elbo
 
struct  gradient_samples
 
struct  max_iterations
 
struct  output_draws
 
struct  tol_rel_obj
 

Functions

template<class Model >
int fullrank (Model &model, stan::io::var_context &init, unsigned int random_seed, unsigned int chain, double init_radius, int grad_samples, int elbo_samples, int max_iterations, double tol_rel_obj, double eta, bool adapt_engaged, int adapt_iterations, int eval_elbo, int output_samples, callbacks::interrupt &interrupt, callbacks::logger &logger, callbacks::writer &init_writer, callbacks::writer &parameter_writer, callbacks::writer &diagnostic_writer)
 
template<class Model >
int meanfield (Model &model, stan::io::var_context &init, unsigned int random_seed, unsigned int chain, double init_radius, int grad_samples, int elbo_samples, int max_iterations, double tol_rel_obj, double eta, bool adapt_engaged, int adapt_iterations, int eval_elbo, int output_samples, callbacks::interrupt &interrupt, callbacks::logger &logger, callbacks::writer &init_writer, callbacks::writer &parameter_writer, callbacks::writer &diagnostic_writer)
 

Function Documentation

template<class Model >
int stan::services::experimental::advi::fullrank ( Model model,
stan::io::var_context init,
unsigned int  random_seed,
unsigned int  chain,
double  init_radius,
int  grad_samples,
int  elbo_samples,
int  max_iterations,
double  tol_rel_obj,
double  eta,
bool  adapt_engaged,
int  adapt_iterations,
int  eval_elbo,
int  output_samples,
callbacks::interrupt interrupt,
callbacks::logger logger,
callbacks::writer init_writer,
callbacks::writer parameter_writer,
callbacks::writer diagnostic_writer 
)

Runs full rank ADVI.

Template Parameters
ModelA model implementation
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 random number generator
[in]init_radiusradius to initialize
[in]grad_samplesnumber of samples for Monte Carlo estimate of gradients
[in]elbo_samplesnumber of samples for Monte Carlo estimate of ELBO
[in]max_iterationsmaximum number of iterations
[in]tol_rel_objconvergence tolerance on the relative norm of the objective
[in]etastepsize scaling parameter for variational inference
[in]adapt_engagedadaptation engaged?
[in]adapt_iterationsnumber of iterations for eta adaptation
[in]eval_elboevaluate ELBO every Nth iteration
[in]output_samplesnumber of posterior samples to draw and save
[in,out]interruptcallback to be called every iteration
[in,out]loggerLogger for messages
[in,out]init_writerWriter callback for unconstrained inits
[in,out]parameter_writeroutput for parameter values
[in,out]diagnostic_writeroutput for diagnostic values
Returns
error_codes::OK if successful

Definition at line 51 of file fullrank.hpp.

References stan::services::util::create_rng(), stan::services::util::experimental_message(), stan::services::util::initialize(), and gen_hdf5record::names.

Referenced by TEST_F().

61  {
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, true,
69  logger, init_writer);
70 
71  std::vector<std::string> names;
72  names.push_back("lp__");
73  model.constrained_param_names(names, true, true);
74  parameter_writer(names);
75 
76  Eigen::VectorXd cont_params
77  = Eigen::Map<Eigen::VectorXd>(&cont_vector[0],
78  cont_vector.size(), 1);
79 
82  boost::ecuyer1988>
83  cmd_advi(model, cont_params, rng, grad_samples,
84  elbo_samples, eval_elbo, output_samples);
85  cmd_advi.run(eta, adapt_engaged, adapt_iterations,
86  tol_rel_obj, max_iterations,
87  logger, parameter_writer, diagnostic_writer);
88 
89  return 0;
90  }
rosenbrock_model_namespace::rosenbrock_model Model
void experimental_message(stan::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
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
template<class Model >
int stan::services::experimental::advi::meanfield ( Model model,
stan::io::var_context init,
unsigned int  random_seed,
unsigned int  chain,
double  init_radius,
int  grad_samples,
int  elbo_samples,
int  max_iterations,
double  tol_rel_obj,
double  eta,
bool  adapt_engaged,
int  adapt_iterations,
int  eval_elbo,
int  output_samples,
callbacks::interrupt interrupt,
callbacks::logger logger,
callbacks::writer init_writer,
callbacks::writer parameter_writer,
callbacks::writer diagnostic_writer 
)

Runs mean field ADVI.

Template Parameters
ModelA model implementation
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 random number generator
[in]init_radiusradius to initialize
[in]grad_samplesnumber of samples for Monte Carlo estimate of gradients
[in]elbo_samplesnumber of samples for Monte Carlo estimate of ELBO
[in]max_iterationsmaximum number of iterations
[in]tol_rel_objconvergence tolerance on the relative norm of the objective
[in]etastepsize scaling parameter for variational inference
[in]adapt_engagedadaptation engaged?
[in]adapt_iterationsnumber of iterations for eta adaptation
[in]eval_elboevaluate ELBO every Nth iteration
[in]output_samplesnumber of posterior samples to draw and save
[in,out]interruptcallback to be called every iteration
[in,out]loggerLogger for messages
[in,out]init_writerWriter callback for unconstrained inits
[in,out]parameter_writeroutput for parameter values
[in,out]diagnostic_writeroutput for diagnostic values
Returns
error_codes::OK if successful

Definition at line 51 of file meanfield.hpp.

References stan::services::util::create_rng(), stan::services::util::experimental_message(), stan::services::util::initialize(), and gen_hdf5record::names.

Referenced by TEST_F().

61  {
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, true,
69  logger, init_writer);
70 
71  std::vector<std::string> names;
72  names.push_back("lp__");
73  model.constrained_param_names(names, true, true);
74  parameter_writer(names);
75 
76  Eigen::VectorXd cont_params
77  = Eigen::Map<Eigen::VectorXd>(&cont_vector[0],
78  cont_vector.size(), 1);
79 
82  boost::ecuyer1988>
83  cmd_advi(model, cont_params, rng, grad_samples,
84  elbo_samples, eval_elbo, output_samples);
85  cmd_advi.run(eta, adapt_engaged, adapt_iterations,
86  tol_rel_obj, max_iterations,
87  logger, parameter_writer, diagnostic_writer);
88 
89  return 0;
90  }
rosenbrock_model_namespace::rosenbrock_model Model
void experimental_message(stan::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
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