hmc_static_diag_inv_metric_test.cpp
Go to the documentation of this file.
4 #include <test/test-models/good/mcmc/hmc/common/gauss3D.hpp>
7 #include <iostream>
8 #include <gtest/gtest.h>
9 
10 /**
11  * Use 3-param model test-models/good/mcmc/hmc/common/gauss3D
12  * fix seed 12345, test against specified inv Euclidean metric
13  * Tests crafted by running samplers with test config
14  * to capture resulting inverse Euclidean metric values.
15  */
16 
17 class ServicesSampleHmcStaticDiagEMassMatrix : public testing::Test {
18 public:
20  : model(context, &model_log) {}
21 
22  std::stringstream model_log;
26  stan_model model;
27 };
28 
30  unsigned int random_seed = 12345;
31  unsigned int chain = 1;
32  double init_radius = 2;
33  int num_warmup = 0;
34  int num_samples = 2;
35  int num_thin = 1;
36  bool save_warmup = false;
37  int refresh = 0;
38  double stepsize = 1;
39  double stepsize_jitter = 0;
40  int int_time = 8;
42  EXPECT_EQ(interrupt.call_count(), 0);
43 
44  int return_code =
46  context,
47  random_seed,
48  chain,
49  init_radius,
50  num_warmup,
51  num_samples,
52  num_thin,
53  save_warmup,
54  refresh,
55  stepsize,
56  stepsize_jitter,
57  int_time,
58  interrupt,
59  logger,
60  init,
61  parameter,
62  diagnostic);
63  EXPECT_EQ(0, return_code);
64 
65  stan::io::dump dmp =
67  stan::io::var_context& inv_metric = dmp;
68  std::vector<double> diag_vals
69  = inv_metric.vals_r("inv_metric");
70  // check returned Euclidean metric
72 }
73 
75  unsigned int random_seed = 12345;
76  unsigned int chain = 1;
77  double init_radius = 2;
78  int num_warmup = 250;
79  int num_samples = 2;
80  int num_thin = 1;
81  bool save_warmup = false;
82  int refresh = 0;
83  double stepsize = 1;
84  double stepsize_jitter = 0;
85  int int_time = 8;
86  double delta = .8;
87  double gamma = .05;
88  double kappa = .75;
89  double t0 = 10;
90  unsigned int init_buffer = 75;
91  unsigned int term_buffer = 50;
92  unsigned int window = 25;
94  EXPECT_EQ(interrupt.call_count(), 0);
95 
96  int return_code =
98  context,
99  random_seed,
100  chain,
101  init_radius,
102  num_warmup,
103  num_samples,
104  num_thin,
105  save_warmup,
106  refresh,
107  stepsize,
108  stepsize_jitter,
109  int_time,
110  delta,
111  gamma,
112  kappa,
113  t0,
114  init_buffer,
115  term_buffer,
116  window,
117  interrupt,
118  logger,
119  init,
120  parameter,
121  diagnostic);
122  EXPECT_EQ(0, return_code);
123 }
124 
126  unsigned int random_seed = 12345;
127  unsigned int chain = 1;
128  double init_radius = 2;
129  int num_warmup = 0;
130  int num_samples = 2;
131  int num_thin = 1;
132  bool save_warmup = false;
133  int refresh = 0;
134  double stepsize = 1;
135  double stepsize_jitter = 0;
136  int int_time = 8;
138  EXPECT_EQ(interrupt.call_count(), 0);
139 
140  std::string txt =
141  "inv_metric <- structure(c(0.787405, 0.884987, 1.19869),.Dim=c(3))";
142  std::stringstream in(txt);
143  stan::io::dump dump(in);
144  stan::io::var_context& inv_metric = dump;
145 
146  int return_code =
148  context,
149  inv_metric,
150  random_seed,
151  chain,
152  init_radius,
153  num_warmup,
154  num_samples,
155  num_thin,
156  save_warmup,
157  refresh,
158  stepsize,
159  stepsize_jitter,
160  int_time,
161  interrupt,
162  logger,
163  init,
164  parameter,
165  diagnostic);
166 
167  EXPECT_EQ(0, return_code);
168 
169  std::vector<double> diag_vals(3);
170  diag_vals = inv_metric.vals_r("inv_metric");
171  stan::test::unit::check_adaptation(3, diag_vals, parameter, 0.2);
172 }
173 
175  unsigned int random_seed = 12345;
176  unsigned int chain = 1;
177  double init_radius = 2;
178  int num_warmup = 0;
179  int num_samples = 2;
180  int num_thin = 1;
181  bool save_warmup = false;
182  int refresh = 0;
183  double stepsize = 1;
184  double stepsize_jitter = 0;
185  int int_time = 8;
186  double delta = .8;
187  double gamma = .05;
188  double kappa = .75;
189  double t0 = 10;
190  unsigned int init_buffer = 75;
191  unsigned int term_buffer = 50;
192  unsigned int window = 25;
194  EXPECT_EQ(interrupt.call_count(), 0);
195 
196  std::string txt =
197  "inv_metric <- structure(c(0.787405, 0.884987, 1.19869),.Dim=c(3))";
198  std::stringstream in(txt);
199  stan::io::dump dump(in);
200  stan::io::var_context& inv_metric = dump;
201 
202  int return_code =
204  context,
205  inv_metric,
206  random_seed,
207  chain,
208  init_radius,
209  num_warmup,
210  num_samples,
211  num_thin,
212  save_warmup,
213  refresh,
214  stepsize,
215  stepsize_jitter,
216  int_time,
217  delta,
218  gamma,
219  kappa,
220  t0,
221  init_buffer,
222  term_buffer,
223  window,
224  interrupt,
225  logger,
226  init,
227  parameter,
228  diagnostic);
229 
230  EXPECT_EQ(0, return_code);
231 
232  std::vector<double> diag_vals(3);
233  diag_vals = inv_metric.vals_r("inv_metric");
234  stan::test::unit::check_adaptation(3, diag_vals, parameter, 0.2);
235 }
stan::test::unit::instrumented_logger logger
double delta
Definition: runWimpSim.h:98
virtual std::vector< double > vals_r(const std::string &name) const =0
stan::io::dump create_unit_e_diag_inv_metric(size_t num_params)
stan::test::unit::instrumented_writer diagnostic
chain
Check that an output directory exists.
stan::test::unit::instrumented_writer parameter
const XML_Char * context
Definition: expat.h:434
ifstream in
Definition: comparison.C:7
TEST_F(ServicesSampleHmcStaticDiagEMassMatrix, unit_e_no_adapt)
int hmc_static_diag_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)
void check_adaptation(const size_t &num_params, const std::vector< double > &param_vals, stan::test::unit::instrumented_writer &report, const double &err_margin)
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)
enum BeamMode string