Namespaces | Classes | Functions
stan::services Namespace Reference

Namespaces

 diagnose
 
 experimental
 
 optimize
 
 sample
 
 util
 

Classes

struct  error_codes
 

Functions

template<class Model >
int num_constrained_params (const Model &model)
 
template<class Model >
int standalone_generate (const Model &model, const std::vector< std::vector< double > > &draws, unsigned int seed, callbacks::interrupt &interrupt, callbacks::logger &logger, callbacks::writer &sample_writer)
 

Function Documentation

template<class Model >
int stan::services::num_constrained_params ( const Model model)

Return the number of constrained parameters for the specified model.

Template Parameters
Modeltype of model
Parameters
[in]modelmodel to query
Returns
number of constrained parameters for the model

Definition at line 25 of file standalone_gqs.hpp.

Referenced by standalone_generate(), TEST(), and TEST_F().

25  {
26  std::vector<std::string> param_names;
27  static const bool include_tparams = false;
28  static const bool include_gqs = false;
29  model.constrained_param_names(param_names, include_tparams,
30  include_gqs);
31  return param_names.size();
32  }
const XML_Char XML_Content * model
Definition: expat.h:151
template<class Model >
int stan::services::standalone_generate ( const Model model,
const std::vector< std::vector< double > > &  draws,
unsigned int  seed,
callbacks::interrupt interrupt,
callbacks::logger logger,
callbacks::writer sample_writer 
)

Given a set of draws from a fitted model, generate corresponding quantities of interest. Data written to callback writer. Return code indicates success or type of error.

Template Parameters
Modelmodel class
Parameters
[in]modelinstantiated model
[in]drawssequence of draws of unconstrained parameters
[in]seedseed to use for randomization
[in,out]interruptcalled every iteration
[in,out]loggerlogger to which to write warning and error messages
[in,out]sample_writerwriter to which draws are written
Returns
error code

Definition at line 49 of file standalone_gqs.hpp.

References stan::services::error_codes::CONFIG, stan::services::util::create_rng(), stan::services::error_codes::DATAERR, stan::callbacks::logger::error(), lem_server::msg, num_constrained_params(), stan::services::error_codes::OK, stan::services::util::gq_writer::write_gq_names(), and stan::services::util::gq_writer::write_gq_values().

Referenced by TEST(), and TEST_F().

54  {
55  if (draws.empty()) {
56  logger.error("Empty set of draws from fitted model.");
57  return error_codes::DATAERR;
58  }
59 
60  int num_params = num_constrained_params(model);
61  std::vector<std::string> gq_names;
62  static const bool include_tparams = false;
63  static const bool include_gqs = true;
64  model.constrained_param_names(gq_names, include_tparams, include_gqs);
65  if (!(static_cast<size_t>(num_params) < gq_names.size())) {
66  logger.error("Model doesn't generate any quantities of interest.");
67  return error_codes::CONFIG;
68  }
69 
70  util::gq_writer writer(sample_writer, logger, num_params);
71  boost::ecuyer1988 rng = util::create_rng(seed, 1);
72  writer.write_gq_names(model);
73 
74  std::stringstream msg;
75  for (const std::vector<double>& draw : draws) {
76  if (static_cast<size_t>(num_params) != draw.size()) {
77  msg << "Wrong number of params in draws from fitted model. ";
78  msg << "Expecting " << num_params << " columns, ";
79  msg << "found " << draws[0].size() << " columns.";
80  std::string msgstr = msg.str();
81  logger.error(msgstr);
82  return error_codes::DATAERR;
83  }
84  interrupt(); // call out to interrupt and fail
85  writer.write_gq_values(model, rng, draw);
86  }
87  return error_codes::OK;
88  }
unsigned int seed
Definition: runWimpSim.h:102
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
int num_constrained_params(const Model &model)
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