standalone_gqs_big_test.cpp
Go to the documentation of this file.
4 #include <test/test-models/good/services/bym2_offset_only.hpp>
6 #include <test/unit/util.hpp>
7 #include <gtest/gtest.h>
8 #include <iostream>
9 
10 typedef bym2_offset_only_model_namespace::bym2_offset_only_model model_class;
11 
12 TEST(ServicesStandaloneGQ_big, genDraws_bym) {
14  std::stringstream model_log;
15  std::stringstream sample_ss, logger_ss;
16  stan::callbacks::stream_writer sample_writer(sample_ss, "");
17  stan::callbacks::stream_logger logger(logger_ss,
18  logger_ss,
19  logger_ss,
20  logger_ss,
21  logger_ss);
22 
23  // Get var_context for data
24  std::fstream data_stream("src/test/test-models/good/services/bym2_inputs.data.R",
26  stan::io::dump data_var_context(data_stream);
27  data_stream.close();
28 
29  // Instantiate model with data
30  model_class model(data_var_context);
31 
32  int num_params = stan::services::num_constrained_params(model);
33  EXPECT_EQ(num_params, 1420);
34 
35  // Get param data from dumpfile matrix 1000 rows, 1420 columns
36  // using stan "var_context" - PITA!
37  std::fstream params_stream("src/test/test-models/good/services/bym2_draws.data.R",
39  stan::io::dump params_var_context(params_stream);
40  params_stream.close();
41  std::vector<std::vector<double>> cdraws(1000);
42  try {
43  params_var_context.validate_dims("get params", "bym2_draws", "matrix",
44  params_var_context.to_vec(1420, 1000));
45  std::vector<double> bym2_pars_vals = params_var_context.vals_r("bym2_draws");
46  int idx = 0;
47  for (int i = 0; i < 1000; ++i) {
48  std::vector<double> tmp(1420);
49  for (int j = 0; j < 1420; ++j) {
50  tmp[j] = bym2_pars_vals[idx++];
51  }
52  cdraws[i] = tmp;
53  }
54  } catch (const std::exception& e) {
55  logger.error("Cannot read draws from file.");
56  logger.error("Caught exception: ");
57  logger.error(e.what());
58  std::cerr << logger_ss.str() << std::endl;
59  throw std::domain_error("Initialization failure");
60  }
61 
63  cdraws,
64  12345,
65  interrupt,
66  logger,
67  sample_writer);
68  // verify results...
69  // std::ofstream gqs_file;
70  // gqs_file.open ("src/test/test-models/good/services/bym2_gqs_v2.csv");
71  // gqs_file << sample_ss.str();
72  // gqs_file.close();
73 }
OStream cerr
Definition: OStream.cxx:7
::xsd::cxx::tree::exception< char > exception
Definition: Database.h:225
Float_t tmp
Definition: plot.C:36
static std::vector< size_t > to_vec()
void validate_dims(const std::string &stage, const std::string &name, const std::string &base_type, const std::vector< size_t > &dims_declared) const
bym2_offset_only_model_namespace::bym2_offset_only_model model_class
const double j
Definition: BetheBloch.cxx:29
void error(const std::string &message)
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)
void domain_error(const char *function, const char *name, const T &y, const char *msg1, const char *msg2)
ifstream in
Definition: comparison.C:7
std::vector< double > vals_r(const std::string &name) const
Definition: dump.hpp:680
int num_constrained_params(const Model &model)
TEST(ServicesStandaloneGQ_big, genDraws_bym)
Float_t e
Definition: plot.C:35
const XML_Char XML_Content * model
Definition: expat.h:151