1 #ifndef STAN__IO__MCMC__WRITER__HPP
2 #define STAN__IO__MCMC__WRITER__HPP
27 class SampleRecorder,
class DiagnosticRecorder,
28 class MessageRecorder>
32 SampleRecorder& sample_recorder_;
33 DiagnosticRecorder& diagnostic_recorder_;
34 MessageRecorder& message_recorder_;
36 std::ostream* msg_stream_;
52 DiagnosticRecorder& diagnostic_recorder,
53 MessageRecorder& message_recorder,
54 std::ostream* msg_stream = 0)
55 : sample_recorder_(sample_recorder),
56 diagnostic_recorder_(diagnostic_recorder),
57 message_recorder_(message_recorder),
58 msg_stream_(msg_stream) {
82 std::vector<std::string> names;
86 model.constrained_param_names(names,
true,
true);
88 sample_recorder_(names);
111 std::vector<double> values;
116 Eigen::VectorXd model_values;
118 model.write_array(rng,
119 const_cast<Eigen::VectorXd&>(sample.
cont_params()),
124 for (
int i = 0; i < model_values.size(); ++i)
125 values.push_back(model_values(i));
127 sample_recorder_(values);
138 template <
class Recorder>
140 Recorder& recorder) {
141 if (!recorder.is_recording())
143 std::stringstream stream;
146 recorder(
"Adaptation terminated\n" + stream.str());
178 std::vector<std::string> names;
183 std::vector<std::string> model_names;
184 model.unconstrained_param_names(model_names,
false,
false);
188 diagnostic_recorder_(names);
205 std::vector<double> values;
211 diagnostic_recorder_(values);
230 template <
class Recorder>
232 Recorder& recorder) {
233 if (!recorder.is_recording())
236 std::string title(
" Elapsed Time: ");
237 std::stringstream ss;
243 ss << title << warmDeltaT <<
" seconds (Warm-up)";
247 ss << std::string(title.size(),
' ') << sampleDeltaT
248 <<
" seconds (Sampling)";
252 ss << std::string(title.size(),
' ')
253 << warmDeltaT + sampleDeltaT
254 <<
" seconds (Total)";
268 write_timing(warmDeltaT, sampleDeltaT, sample_recorder_);
269 write_timing(warmDeltaT, sampleDeltaT, diagnostic_recorder_);
270 write_timing(warmDeltaT, sampleDeltaT, message_recorder_);
mcmc_writer(SampleRecorder &sample_recorder, DiagnosticRecorder &diagnostic_recorder, MessageRecorder &message_recorder, std::ostream *msg_stream=0)
Constructor.
void write_sample_params(RNG &rng, stan::mcmc::sample &sample, stan::mcmc::base_mcmc &sampler, M &model)
Outputs samples.
void write_sample_names(stan::mcmc::sample &sample, stan::mcmc::base_mcmc *sampler, M &model)
Outputs parameter string names.
virtual void get_sampler_diagnostic_names(std::vector< std::string > &model_names, std::vector< std::string > &names)
virtual void get_sampler_params(std::vector< double > &values)
void get_sample_params(std::vector< double > &values)
void write_adapt_finish(stan::mcmc::base_mcmc *sampler, Recorder &recorder)
Internal method.
virtual void get_sampler_diagnostics(std::vector< double > &values)
double cont_params(int k) const
void write_timing(double warmDeltaT, double sampleDeltaT, Recorder &recorder)
Internal method.
virtual void get_sampler_param_names(std::vector< std::string > &names)
void write_diagnostic_names(stan::mcmc::sample sample, stan::mcmc::base_mcmc *sampler, M &model)
Print diagnostic names.
void write_adapt_finish(stan::mcmc::base_mcmc *sampler)
Prints additional info to the streams.
void write_timing(double warmDeltaT, double sampleDeltaT)
Print timing information to all streams.
mcmc_writer writes out headers and samples
virtual void write_sampler_state(std::ostream *o)
void write_diagnostic_params(stan::mcmc::sample &sample, stan::mcmc::base_mcmc *sampler)
Print diagnostic params to the diagnostic stream.
void get_sample_param_names(std::vector< std::string > &names)
void sample(stan::mcmc::base_mcmc *sampler, int num_warmup, int num_samples, int num_thin, int refresh, bool save, stan::io::mcmc_writer< Model, SampleRecorder, DiagnosticRecorder, MessageRecorder > &writer, stan::mcmc::sample &init_s, Model &model, RNG &base_rng, const std::string &prefix, const std::string &suffix, std::ostream &o, StartTransitionCallback &callback)