Classes | Functions
hmc_nuts_dense_e_test.cpp File Reference
#include <stan/services/sample/hmc_nuts_dense_e.hpp>
#include <gtest/gtest.h>
#include <stan/io/empty_var_context.hpp>
#include <test/test-models/good/optimization/rosenbrock.hpp>
#include <test/unit/services/instrumented_callbacks.hpp>
#include <iostream>

Go to the source code of this file.

Classes

class  ServicesSampleHmcNutsDenseE
 

Functions

 TEST_F (ServicesSampleHmcNutsDenseE, call_count)
 
 TEST_F (ServicesSampleHmcNutsDenseE, parameter_checks)
 
 TEST_F (ServicesSampleHmcNutsDenseE, return_checks)
 
 TEST_F (ServicesSampleHmcNutsDenseE, output_regression)
 

Function Documentation

TEST_F ( ServicesSampleHmcNutsDenseE  ,
call_count   
)

Definition at line 20 of file hmc_nuts_dense_e_test.cpp.

References stan::test::unit::instrumented_interrupt::call_count(), stan::test::unit::instrumented_writer::call_count(), productionTest::chain, ServicesSampleHmcNutsDenseE::diagnostic, stan::services::sample::hmc_nuts_dense_e(), ServicesSampleHmcNutsDenseE::init, ServicesSampleHmcNutsDenseE::logger, ServicesSampleHmcNutsDenseE::parameter, refresh(), and makeTestPickles::return_code.

20  {
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;
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, max_depth,
39  interrupt, logger, init,
40  parameter, diagnostic);
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 }
int hmc_nuts_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, int max_depth, callbacks::interrupt &interrupt, callbacks::logger &logger, callbacks::writer &init_writer, callbacks::writer &sample_writer, callbacks::writer &diagnostic_writer)
chain
Check that an output directory exists.
const XML_Char * context
Definition: expat.h:434
const XML_Char XML_Content * model
Definition: expat.h:151
void refresh()
Definition: show_event.C:21
TEST_F ( ServicesSampleHmcNutsDenseE  ,
parameter_checks   
)

Definition at line 52 of file hmc_nuts_dense_e_test.cpp.

References stan::test::unit::instrumented_interrupt::call_count(), productionTest::chain, ServicesSampleHmcNutsDenseE::diagnostic, stan::services::sample::hmc_nuts_dense_e(), ServicesSampleHmcNutsDenseE::init, ServicesSampleHmcNutsDenseE::logger, ServicesSampleHmcNutsDenseE::parameter, refresh(), gen_hdf5record::size, stan::test::unit::instrumented_writer::vector_double_values(), and stan::test::unit::instrumented_writer::vector_string_values().

52  {
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  int max_depth = 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, max_depth,
71  interrupt, logger, init,
72  parameter, diagnostic);
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(9, 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("treedepth__", parameter_names[0][3]);
89  EXPECT_EQ("n_leapfrog__", parameter_names[0][4]);
90  EXPECT_EQ("divergent__", parameter_names[0][5]);
91  EXPECT_EQ("energy__", parameter_names[0][6]);
92  EXPECT_EQ("x", parameter_names[0][7]);
93  EXPECT_EQ("y", parameter_names[0][8]);
94 
95  // Expect one name per parameter value.
96  EXPECT_EQ(parameter_names[0].size(), parameter_values[0].size());
97  EXPECT_EQ(diagnostic_names[0].size(), diagnostic_values[0].size());
98 
99  EXPECT_EQ((num_warmup+num_samples)/num_thin, parameter_values.size());
100 
101  // Expect one call to set parameter names, and one set of output per
102  // iteration.
103  EXPECT_EQ("lp__", diagnostic_names[0][0]);
104  EXPECT_EQ("accept_stat__", diagnostic_names[0][1]);
105 }
int hmc_nuts_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, int max_depth, callbacks::interrupt &interrupt, callbacks::logger &logger, callbacks::writer &init_writer, callbacks::writer &sample_writer, callbacks::writer &diagnostic_writer)
chain
Check that an output directory exists.
const XML_Char * context
Definition: expat.h:434
const XML_Char XML_Content * model
Definition: expat.h:151
void refresh()
Definition: show_event.C:21
TEST_F ( ServicesSampleHmcNutsDenseE  ,
return_checks   
)

Definition at line 107 of file hmc_nuts_dense_e_test.cpp.

References stan::test::unit::instrumented_interrupt::call_count(), productionTest::chain, ServicesSampleHmcNutsDenseE::diagnostic, stan::services::sample::hmc_nuts_dense_e(), ServicesSampleHmcNutsDenseE::init, ServicesSampleHmcNutsDenseE::logger, ServicesSampleHmcNutsDenseE::parameter, refresh(), makeTestPickles::return_code, stan::test::unit::instrumented_writer::vector_double_values(), and stan::test::unit::instrumented_writer::vector_string_values().

107  {
108  unsigned int random_seed = 0;
109  unsigned int chain = 1;
110  double init_radius = 0;
111  int num_warmup = 200;
112  int num_samples = 400;
113  int num_thin = 5;
114  bool save_warmup = true;
115  int refresh = 0;
116  double stepsize = 0.1;
117  double stepsize_jitter = 0;
118  int max_depth = 8;
120  EXPECT_EQ(interrupt.call_count(), 0);
121 
123  model, context, random_seed, chain, init_radius,
124  num_warmup, num_samples, num_thin, save_warmup, refresh,
125  stepsize, stepsize_jitter, max_depth,
126  interrupt, logger, init,
127  parameter, diagnostic);
128  EXPECT_EQ(0, return_code);
129 
130  std::vector<std::vector<std::string> > parameter_names;
131  parameter_names = parameter.vector_string_values();
132  std::vector<std::vector<double> > parameter_values;
133  parameter_values = parameter.vector_double_values();
134  std::vector<std::vector<std::string> > diagnostic_names;
135  diagnostic_names = diagnostic.vector_string_values();
136  std::vector<std::vector<double> > diagnostic_values;
137  diagnostic_values = diagnostic.vector_double_values();
138 
139  EXPECT_EQ(return_code, 0);
140 
141 }
int hmc_nuts_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, int max_depth, callbacks::interrupt &interrupt, callbacks::logger &logger, callbacks::writer &init_writer, callbacks::writer &sample_writer, callbacks::writer &diagnostic_writer)
chain
Check that an output directory exists.
const XML_Char * context
Definition: expat.h:434
const XML_Char XML_Content * model
Definition: expat.h:151
void refresh()
Definition: show_event.C:21
TEST_F ( ServicesSampleHmcNutsDenseE  ,
output_regression   
)

Definition at line 143 of file hmc_nuts_dense_e_test.cpp.

References stan::test::unit::instrumented_interrupt::call_count(), stan::test::unit::instrumented_logger::call_count_error(), productionTest::chain, ServicesSampleHmcNutsDenseE::diagnostic, stan::test::unit::instrumented_logger::find_info(), stan::services::sample::hmc_nuts_dense_e(), ServicesSampleHmcNutsDenseE::init, ServicesSampleHmcNutsDenseE::logger, ServicesSampleHmcNutsDenseE::parameter, refresh(), and stan::test::unit::instrumented_writer::string_values().

143  {
144  unsigned int random_seed = 0;
145  unsigned int chain = 1;
146  double init_radius = 0;
147  int num_warmup = 200;
148  int num_samples = 400;
149  int num_thin = 5;
150  bool save_warmup = true;
151  int refresh = 0;
152  double stepsize = 0.1;
153  double stepsize_jitter = 0;
154  int max_depth = 8;
156  EXPECT_EQ(interrupt.call_count(), 0);
157 
158 
160  model, context, random_seed, chain, init_radius,
161  num_warmup, num_samples, num_thin, save_warmup, refresh,
162  stepsize, stepsize_jitter, max_depth,
163  interrupt, logger, init,
164  parameter, diagnostic);
165 
166  std::vector<std::string> init_values;
167  init_values = init.string_values();
168 
169  EXPECT_EQ(0, init_values.size());
170 
171  EXPECT_EQ(1, logger.find_info("Elapsed Time:"));
172  EXPECT_EQ(1, logger.find_info("seconds (Warm-up)"));
173  EXPECT_EQ(1, logger.find_info("seconds (Sampling)"));
174  EXPECT_EQ(1, logger.find_info("seconds (Total)"));
175  EXPECT_EQ(0, logger.call_count_error());
176 }
int hmc_nuts_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, int max_depth, callbacks::interrupt &interrupt, callbacks::logger &logger, callbacks::writer &init_writer, callbacks::writer &sample_writer, callbacks::writer &diagnostic_writer)
chain
Check that an output directory exists.
const XML_Char * context
Definition: expat.h:434
const XML_Char XML_Content * model
Definition: expat.h:151
void refresh()
Definition: show_event.C:21