hmc_static_unit_e_adapt_test.cpp
Go to the documentation of this file.
2 #include <gtest/gtest.h>
4 #include <test/test-models/good/optimization/rosenbrock.hpp>
6 #include <iostream>
7 
8 class ServicesSampleHmcStaticUnitEAdapt : public testing::Test {
9 public:
11  : model(context, &model_log) {}
12 
13  std::stringstream model_log;
17  stan_model model;
18 };
19 
20 
22  unsigned int random_seed = 0;
23  unsigned int chain = 1;
24  double init_radius = 0;
25  int num_warmup = 200;
26  int num_samples = 400;
27  int num_thin = 5;
28  bool save_warmup = true;
29  int refresh = 0;
30  double stepsize = 0.1;
31  double stepsize_jitter = 0;
32  double int_time = 8;
33  double delta = .1;
34  double gamma = .1;
35  double kappa = .1;
36  double t0 = .1;
38  EXPECT_EQ(interrupt.call_count(), 0);
39 
41  model, context, random_seed, chain, init_radius,
42  num_warmup, num_samples, num_thin, save_warmup, refresh,
43  stepsize, stepsize_jitter, int_time, delta, gamma, kappa, t0,
44  interrupt, logger, init,
46 
47  EXPECT_EQ(0, return_code);
48 
49  std::vector<std::vector<std::string> > parameter_names;
50  parameter_names = parameter.vector_string_values();
51  std::vector<std::vector<double> > parameter_values;
52  parameter_values = parameter.vector_double_values();
53  std::vector<std::vector<std::string> > diagnostic_names;
54  diagnostic_names = diagnostic.vector_string_values();
55  std::vector<std::vector<double> > diagnostic_values;
56  diagnostic_values = diagnostic.vector_double_values();
57 
58  // Expecatations of message call counts
59  int num_output_lines = (num_warmup+num_samples)/num_thin;
60  EXPECT_EQ(num_warmup+num_samples, interrupt.call_count());
61  EXPECT_EQ(1, parameter.call_count("vector_string"));
62  EXPECT_EQ(num_output_lines, parameter.call_count("vector_double"));
63  EXPECT_EQ(1, diagnostic.call_count("vector_string"));
64  EXPECT_EQ(num_output_lines, diagnostic.call_count("vector_double"));
65 }
66 
67 
69  unsigned int random_seed = 0;
70  unsigned int chain = 1;
71  double init_radius = 0;
72  int num_warmup = 200;
73  int num_samples = 400;
74  int num_thin = 5;
75  bool save_warmup = true;
76  int refresh = 0;
77  double stepsize = 0.1;
78  double stepsize_jitter = 0;
79  double int_time = 8;
80  double delta = .1;
81  double gamma = .1;
82  double kappa = .1;
83  double t0 = .1;
85  EXPECT_EQ(interrupt.call_count(), 0);
86 
88  model, context, random_seed, chain, init_radius,
89  num_warmup, num_samples, num_thin, save_warmup, refresh,
90  stepsize, stepsize_jitter, int_time, delta, gamma, kappa, t0,
91  interrupt, logger, init,
93 
94  std::vector<std::vector<std::string> > parameter_names;
95  parameter_names = parameter.vector_string_values();
96  std::vector<std::vector<double> > parameter_values;
97  parameter_values = parameter.vector_double_values();
98  std::vector<std::vector<std::string> > diagnostic_names;
99  diagnostic_names = diagnostic.vector_string_values();
100  std::vector<std::vector<double> > diagnostic_values;
101  diagnostic_values = diagnostic.vector_double_values();
102 
103  // Expectations of parameter parameter names.
104  ASSERT_EQ(7, parameter_names[0].size());
105  EXPECT_EQ("lp__", parameter_names[0][0]);
106  EXPECT_EQ("accept_stat__", parameter_names[0][1]);
107  EXPECT_EQ("stepsize__", parameter_names[0][2]);
108  EXPECT_EQ("int_time__", parameter_names[0][3]);
109 
110  // Expect one name per parameter value.
111  EXPECT_EQ(parameter_names[0].size(), parameter_values[0].size());
112  EXPECT_EQ(diagnostic_names[0].size(), diagnostic_values[0].size());
113 
114  EXPECT_EQ((num_warmup+num_samples)/num_thin, parameter_values.size());
115 
116  // Expect one call to set parameter names, and one set of output per
117  // iteration.
118  EXPECT_EQ("lp__", diagnostic_names[0][0]);
119  EXPECT_EQ("accept_stat__", diagnostic_names[0][1]);
120 }
121 
122 
124  unsigned int random_seed = 0;
125  unsigned int chain = 1;
126  double init_radius = 0;
127  int num_warmup = 200;
128  int num_samples = 400;
129  int num_thin = 5;
130  bool save_warmup = true;
131  int refresh = 0;
132  double stepsize = 0.1;
133  double stepsize_jitter = 0;
134  double int_time = 8;
135  double delta = .1;
136  double gamma = .1;
137  double kappa = .1;
138  double t0 = .1;
140  EXPECT_EQ(interrupt.call_count(), 0);
141 
142 
144  model, context, random_seed, chain, init_radius,
145  num_warmup, num_samples, num_thin, save_warmup, refresh,
146  stepsize, stepsize_jitter, int_time, delta, gamma, kappa, t0,
147  interrupt, logger, init,
149 
150  std::vector<std::vector<std::string> > parameter_names;
151  parameter_names = parameter.vector_string_values();
152  std::vector<std::vector<double> > parameter_values;
153  parameter_values = parameter.vector_double_values();
154  std::vector<std::vector<std::string> > diagnostic_names;
155  diagnostic_names = diagnostic.vector_string_values();
156  std::vector<std::vector<double> > diagnostic_values;
157  diagnostic_values = diagnostic.vector_double_values();
158 
159  EXPECT_EQ(return_code, 0);
160 
161 }
162 
164  unsigned int random_seed = 0;
165  unsigned int chain = 1;
166  double init_radius = 0;
167  int num_warmup = 200;
168  int num_samples = 400;
169  int num_thin = 5;
170  bool save_warmup = true;
171  int refresh = 0;
172  double stepsize = 0.1;
173  double stepsize_jitter = 0;
174  double int_time = 8;
175  double delta = .1;
176  double gamma = .1;
177  double kappa = .1;
178  double t0 = .1;
180  EXPECT_EQ(interrupt.call_count(), 0);
181 
182 
184  model, context, random_seed, chain, init_radius,
185  num_warmup, num_samples, num_thin, save_warmup, refresh,
186  stepsize, stepsize_jitter, int_time, delta, gamma, kappa, t0,
187  interrupt, logger, init,
189 
190  std::vector<std::string> init_values;
191  init_values = init.string_values();
192 
193  EXPECT_EQ(0, init_values.size());
194 
195  EXPECT_EQ(1, logger.find_info("Elapsed Time:"));
196  EXPECT_EQ(1, logger.find_info("seconds (Warm-up)"));
197  EXPECT_EQ(1, logger.find_info("seconds (Sampling)"));
198  EXPECT_EQ(1, logger.find_info("seconds (Total)"));
199  EXPECT_EQ(0, logger.call_count_error());
200 }
std::vector< std::vector< std::string > > vector_string_values()
double delta
Definition: runWimpSim.h:98
int hmc_static_unit_e_adapt(Model &model, stan::io::var_context &init, unsigned int random_seed, unsigned int chain, double init_radius, int num_warmup, int num_samples, int num_thin, bool save_warmup, int refresh, double stepsize, double stepsize_jitter, double int_time, double delta, double gamma, double kappa, double t0, callbacks::interrupt &interrupt, callbacks::logger &logger, callbacks::writer &init_writer, callbacks::writer &sample_writer, callbacks::writer &diagnostic_writer)
TEST_F(ServicesSampleHmcStaticUnitEAdapt, call_count)
chain
Check that an output directory exists.
stan::test::unit::instrumented_writer parameter
const XML_Char * context
Definition: expat.h:434
stan::test::unit::instrumented_logger logger
stan::test::unit::instrumented_writer init
std::vector< std::vector< double > > vector_double_values()
unsigned int find_info(const std::string &msg)
const XML_Char XML_Content * model
Definition: expat.h:151
void refresh()
Definition: show_event.C:21
stan::test::unit::instrumented_writer diagnostic