hmc_static_diag_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 ServicesSampleHmcStaticDiagEAdapt : public testing::Test {
9 public:
11  : model(context, &model_log) {}
12 
13  std::stringstream model_log;
17  stan_model model;
18 };
19 
21  unsigned int random_seed = 0;
22  unsigned int chain = 1;
23  double init_radius = 0;
24  int num_warmup = 200;
25  int num_samples = 400;
26  int num_thin = 5;
27  bool save_warmup = true;
28  int refresh = 0;
29  double stepsize = 0.1;
30  double stepsize_jitter = 0;
31  double int_time = 8;
32  double delta = .1;
33  double gamma = .1;
34  double kappa = .1;
35  double t0 = .1;
36  unsigned int init_buffer = 50;
37  unsigned int term_buffer = 50;
38  unsigned int window = 100;
40  EXPECT_EQ(interrupt.call_count(), 0);
41 
43  model, context, random_seed, chain, init_radius,
44  num_warmup, num_samples, num_thin, save_warmup, refresh,
45  stepsize, stepsize_jitter, int_time, delta, gamma, kappa, t0,
46  init_buffer, term_buffer, window,
47  interrupt, logger, init,
49 
50  EXPECT_EQ(0, return_code);
51 
52  int num_output_lines = (num_warmup+num_samples)/num_thin;
53  EXPECT_EQ(num_warmup+num_samples, interrupt.call_count());
54  EXPECT_EQ(1, parameter.call_count("vector_string"));
55  EXPECT_EQ(num_output_lines, parameter.call_count("vector_double"));
56  EXPECT_EQ(1, diagnostic.call_count("vector_string"));
57  EXPECT_EQ(num_output_lines, diagnostic.call_count("vector_double"));
58 }
59 
61  unsigned int random_seed = 0;
62  unsigned int chain = 1;
63  double init_radius = 0;
64  int num_warmup = 200;
65  int num_samples = 400;
66  int num_thin = 5;
67  bool save_warmup = true;
68  int refresh = 0;
69  double stepsize = 0.1;
70  double stepsize_jitter = 0;
71  double int_time = 8;
72  double delta = .1;
73  double gamma = .1;
74  double kappa = .1;
75  double t0 = .1;
76  unsigned int init_buffer = 50;
77  unsigned int term_buffer = 50;
78  unsigned int window = 100;
80  EXPECT_EQ(interrupt.call_count(), 0);
81 
83  model, context, random_seed, chain, init_radius,
84  num_warmup, num_samples, num_thin, save_warmup, refresh,
85  stepsize, stepsize_jitter, int_time, delta, gamma, kappa, t0,
86  init_buffer, term_buffer, window,
87  interrupt, logger, init,
89 
90  std::vector<std::vector<std::string> > parameter_names;
91  parameter_names = parameter.vector_string_values();
92  std::vector<std::vector<double> > parameter_values;
93  parameter_values = parameter.vector_double_values();
94  std::vector<std::vector<std::string> > diagnostic_names;
95  diagnostic_names = diagnostic.vector_string_values();
96  std::vector<std::vector<double> > diagnostic_values;
97  diagnostic_values = diagnostic.vector_double_values();
98 
99  // Expectations of parameter parameter names.
100  ASSERT_EQ(7, parameter_names[0].size());
101  EXPECT_EQ("lp__", parameter_names[0][0]);
102  EXPECT_EQ("accept_stat__", parameter_names[0][1]);
103  EXPECT_EQ("stepsize__", parameter_names[0][2]);
104  EXPECT_EQ("int_time__", parameter_names[0][3]);
105  EXPECT_EQ("energy__", parameter_names[0][4]);
106  EXPECT_EQ("x", parameter_names[0][5]);
107  EXPECT_EQ("y", parameter_names[0][6]);
108 
109  // Expect one name per parameter value.
110  EXPECT_EQ(parameter_names[0].size(), parameter_values[0].size());
111  EXPECT_EQ(diagnostic_names[0].size(), diagnostic_values[0].size());
112 
113  EXPECT_EQ((num_warmup+num_samples)/num_thin, parameter_values.size());
114 
115  // Expect one call to set parameter names, and one set of output per
116  // iteration.
117  EXPECT_EQ("lp__", diagnostic_names[0][0]);
118  EXPECT_EQ("accept_stat__", diagnostic_names[0][1]);
119 }
120 
122  unsigned int random_seed = 0;
123  unsigned int chain = 1;
124  double init_radius = 0;
125  int num_warmup = 200;
126  int num_samples = 400;
127  int num_thin = 5;
128  bool save_warmup = true;
129  int refresh = 0;
130  double stepsize = 0.1;
131  double stepsize_jitter = 0;
132  double int_time = 8;
133  double delta = .1;
134  double gamma = .1;
135  double kappa = .1;
136  double t0 = .1;
137  unsigned int init_buffer = 50;
138  unsigned int term_buffer = 50;
139  unsigned int window = 100;
141  EXPECT_EQ(interrupt.call_count(), 0);
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  init_buffer, term_buffer, window,
148  interrupt, logger, init,
150 
151  std::vector<std::vector<std::string> > parameter_names;
152  parameter_names = parameter.vector_string_values();
153  std::vector<std::vector<double> > parameter_values;
154  parameter_values = parameter.vector_double_values();
155  std::vector<std::vector<std::string> > diagnostic_names;
156  diagnostic_names = diagnostic.vector_string_values();
157  std::vector<std::vector<double> > diagnostic_values;
158  diagnostic_values = diagnostic.vector_double_values();
159 
160  EXPECT_EQ(return_code, 0);
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;
179  unsigned int init_buffer = 50;
180  unsigned int term_buffer = 50;
181  unsigned int window = 100;
183  EXPECT_EQ(interrupt.call_count(), 0);
184 
185 
187  model, context, random_seed, chain, init_radius,
188  num_warmup, num_samples, num_thin, save_warmup, refresh,
189  stepsize, stepsize_jitter, int_time, delta, gamma, kappa, t0,
190  init_buffer, term_buffer, window,
191  interrupt, logger, init,
193 
194  std::vector<std::string> init_values;
195  init_values = init.string_values();
196 
197  EXPECT_EQ(0, init_values.size());
198 
199  EXPECT_EQ(1, logger.find_info("Elapsed Time:"));
200  EXPECT_EQ(1, logger.find_info("seconds (Warm-up)"));
201  EXPECT_EQ(1, logger.find_info("seconds (Sampling)"));
202  EXPECT_EQ(1, logger.find_info("seconds (Total)"));
203  EXPECT_EQ(0, logger.call_count_error());
204 }
std::vector< std::vector< std::string > > vector_string_values()
double delta
Definition: runWimpSim.h:98
stan::test::unit::instrumented_logger logger
stan::test::unit::instrumented_writer parameter
chain
Check that an output directory exists.
TEST_F(ServicesSampleHmcStaticDiagEAdapt, call_count)
const XML_Char * context
Definition: expat.h:434
std::vector< std::vector< double > > vector_double_values()
stan::test::unit::instrumented_writer init
stan::test::unit::instrumented_writer diagnostic
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
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)