hmc_nuts_dense_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 ServicesSampleHmcNutsDenseEAdapt : 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  int max_depth = 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, max_depth, 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  int max_depth = 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, max_depth, 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(9, 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("treedepth__", parameter_names[0][3]);
105  EXPECT_EQ("n_leapfrog__", parameter_names[0][4]);
106  EXPECT_EQ("divergent__", parameter_names[0][5]);
107  EXPECT_EQ("energy__", parameter_names[0][6]);
108  EXPECT_EQ("x", parameter_names[0][7]);
109  EXPECT_EQ("y", parameter_names[0][8]);
110 
111  // Expect one name per parameter value.
112  EXPECT_EQ(parameter_names[0].size(), parameter_values[0].size());
113  EXPECT_EQ(diagnostic_names[0].size(), diagnostic_values[0].size());
114 
115  EXPECT_EQ((num_warmup+num_samples)/num_thin, parameter_values.size());
116 
117  // Expect one call to set parameter names, and one set of output per
118  // iteration.
119  EXPECT_EQ("lp__", diagnostic_names[0][0]);
120  EXPECT_EQ("accept_stat__", diagnostic_names[0][1]);
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  int max_depth = 8;
135  double delta = .1;
136  double gamma = .1;
137  double kappa = .1;
138  double t0 = .1;
139  unsigned int init_buffer = 50;
140  unsigned int term_buffer = 50;
141  unsigned int window = 100;
143  EXPECT_EQ(interrupt.call_count(), 0);
144 
146  model, context, random_seed, chain, init_radius,
147  num_warmup, num_samples, num_thin, save_warmup, refresh,
148  stepsize, stepsize_jitter, max_depth, delta, gamma, kappa, t0,
149  init_buffer, term_buffer, window,
150  interrupt, logger, init,
152  EXPECT_EQ(return_code, 0);
153 }
154 
156  unsigned int random_seed = 0;
157  unsigned int chain = 1;
158  double init_radius = 0;
159  int num_warmup = 200;
160  int num_samples = 400;
161  int num_thin = 5;
162  bool save_warmup = true;
163  int refresh = 0;
164  double stepsize = 0.1;
165  double stepsize_jitter = 0;
166  int max_depth = 8;
167  double delta = .1;
168  double gamma = .1;
169  double kappa = .1;
170  double t0 = .1;
171  unsigned int init_buffer = 50;
172  unsigned int term_buffer = 50;
173  unsigned int window = 100;
175  EXPECT_EQ(interrupt.call_count(), 0);
176 
177 
179  model, context, random_seed, chain, init_radius,
180  num_warmup, num_samples, num_thin, save_warmup, refresh,
181  stepsize, stepsize_jitter, max_depth, delta, gamma, kappa, t0,
182  init_buffer, term_buffer, window,
183  interrupt, logger, init,
185 
186  std::vector<std::string> init_values;
187  init_values = init.string_values();
188 
189  EXPECT_EQ(0, init_values.size());
190 
191  EXPECT_EQ(1, logger.find_info("Elapsed Time:"));
192  EXPECT_EQ(1, logger.find_info("seconds (Warm-up)"));
193  EXPECT_EQ(1, logger.find_info("seconds (Sampling)"));
194  EXPECT_EQ(1, logger.find_info("seconds (Total)"));
195  EXPECT_EQ(0, logger.call_count_error());
196 }
TEST_F(ServicesSampleHmcNutsDenseEAdapt, call_count)
stan::test::unit::instrumented_writer diagnostic
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 init
chain
Check that an output directory exists.
const XML_Char * context
Definition: expat.h:434
int hmc_nuts_dense_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, int max_depth, 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)
stan::test::unit::instrumented_writer parameter
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