hmc_static_dense_e_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 ServicesSampleHmcStaticDenseE : 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;
33  EXPECT_EQ(interrupt.call_count(), 0);
34 
36  model, context, random_seed, chain, init_radius,
37  num_warmup, num_samples, num_thin, save_warmup, refresh,
38  stepsize, stepsize_jitter, int_time,
39  interrupt, logger, init,
41 
42  EXPECT_EQ(0, return_code);
43 
44  int num_output_lines = (num_warmup+num_samples)/num_thin;
45  EXPECT_EQ(num_warmup+num_samples, interrupt.call_count());
46  EXPECT_EQ(1, parameter.call_count("vector_string"));
47  EXPECT_EQ(num_output_lines, parameter.call_count("vector_double"));
48  EXPECT_EQ(1, diagnostic.call_count("vector_string"));
49  EXPECT_EQ(num_output_lines, diagnostic.call_count("vector_double"));
50 }
51 
53  unsigned int random_seed = 0;
54  unsigned int chain = 1;
55  double init_radius = 0;
56  int num_warmup = 200;
57  int num_samples = 400;
58  int num_thin = 5;
59  bool save_warmup = true;
60  int refresh = 0;
61  double stepsize = 0.1;
62  double stepsize_jitter = 0;
63  double int_time = 8;
65  EXPECT_EQ(interrupt.call_count(), 0);
66 
68  model, context, random_seed, chain, init_radius,
69  num_warmup, num_samples, num_thin, save_warmup, refresh,
70  stepsize, stepsize_jitter, int_time,
71  interrupt, logger, init,
73 
74  std::vector<std::vector<std::string> > parameter_names;
75  parameter_names = parameter.vector_string_values();
76  std::vector<std::vector<double> > parameter_values;
77  parameter_values = parameter.vector_double_values();
78  std::vector<std::vector<std::string> > diagnostic_names;
79  diagnostic_names = diagnostic.vector_string_values();
80  std::vector<std::vector<double> > diagnostic_values;
81  diagnostic_values = diagnostic.vector_double_values();
82 
83  // Expectations of parameter parameter names.
84  ASSERT_EQ(7, parameter_names[0].size());
85  EXPECT_EQ("lp__", parameter_names[0][0]);
86  EXPECT_EQ("accept_stat__", parameter_names[0][1]);
87  EXPECT_EQ("stepsize__", parameter_names[0][2]);
88  EXPECT_EQ("int_time__", parameter_names[0][3]);
89  EXPECT_EQ("energy__", parameter_names[0][4]);
90  EXPECT_EQ("x", parameter_names[0][5]);
91  EXPECT_EQ("y", parameter_names[0][6]);
92 
93  // Expect one name per parameter value.
94  EXPECT_EQ(parameter_names[0].size(), parameter_values[0].size());
95  EXPECT_EQ(diagnostic_names[0].size(), diagnostic_values[0].size());
96 
97  EXPECT_EQ((num_warmup+num_samples)/num_thin, parameter_values.size());
98 
99  // Expect one call to set parameter names, and one set of output per
100  // iteration.
101  EXPECT_EQ("lp__", diagnostic_names[0][0]);
102  EXPECT_EQ("accept_stat__", diagnostic_names[0][1]);
103 }
104 
106  unsigned int random_seed = 0;
107  unsigned int chain = 1;
108  double init_radius = 0;
109  int num_warmup = 200;
110  int num_samples = 400;
111  int num_thin = 5;
112  bool save_warmup = true;
113  int refresh = 0;
114  double stepsize = 0.1;
115  double stepsize_jitter = 0;
116  double int_time = 8;
118  EXPECT_EQ(interrupt.call_count(), 0);
119 
121  model, context, random_seed, chain, init_radius,
122  num_warmup, num_samples, num_thin, save_warmup, refresh,
123  stepsize, stepsize_jitter, int_time,
124  interrupt, logger, init,
126 
127  std::vector<std::vector<std::string> > parameter_names;
128  parameter_names = parameter.vector_string_values();
129  std::vector<std::vector<double> > parameter_values;
130  parameter_values = parameter.vector_double_values();
131  std::vector<std::vector<std::string> > diagnostic_names;
132  diagnostic_names = diagnostic.vector_string_values();
133  std::vector<std::vector<double> > diagnostic_values;
134  diagnostic_values = diagnostic.vector_double_values();
135 
136  EXPECT_EQ(return_code, 0);
137 }
138 
140  unsigned int random_seed = 0;
141  unsigned int chain = 1;
142  double init_radius = 0;
143  int num_warmup = 200;
144  int num_samples = 400;
145  int num_thin = 5;
146  bool save_warmup = true;
147  int refresh = 0;
148  double stepsize = 0.1;
149  double stepsize_jitter = 0;
150  double int_time = 8;
152  EXPECT_EQ(interrupt.call_count(), 0);
153 
154 
156  model, context, random_seed, chain, init_radius,
157  num_warmup, num_samples, num_thin, save_warmup, refresh,
158  stepsize, stepsize_jitter, int_time,
159  interrupt, logger, init,
161 
162  std::vector<std::string> init_values;
163  init_values = init.string_values();
164 
165  EXPECT_EQ(0, init_values.size());
166 
167  EXPECT_EQ(1, logger.find_info("Elapsed Time:"));
168  EXPECT_EQ(1, logger.find_info("seconds (Warm-up)"));
169  EXPECT_EQ(1, logger.find_info("seconds (Sampling)"));
170  EXPECT_EQ(1, logger.find_info("seconds (Total)"));
171  EXPECT_EQ(0, logger.call_count_error());
172 }
std::vector< std::vector< std::string > > vector_string_values()
stan::test::unit::instrumented_writer parameter
chain
Check that an output directory exists.
TEST_F(ServicesSampleHmcStaticDenseE, call_count)
stan::io::empty_var_context context
stan::test::unit::instrumented_logger logger
stan::test::unit::instrumented_writer diagnostic
const XML_Char * context
Definition: expat.h:434
int hmc_static_dense_e(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, callbacks::interrupt &interrupt, callbacks::logger &logger, callbacks::writer &init_writer, callbacks::writer &sample_writer, callbacks::writer &diagnostic_writer)
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
stan::test::unit::instrumented_writer init
void refresh()
Definition: show_event.C:21