Example #1
0
 void print_sample_params(RNG& rng, 
                          stan::mcmc::sample& sample,
                          stan::mcmc::base_mcmc& sampler,
                          M& model) {
   
   if(!_sample_stream) return;
   
   std::vector<double> values;
   
   sample.get_sample_params(values);
   sampler.get_sampler_params(values);
   
   std::vector<double> model_values;
   
   model.write_array(rng,
                     const_cast<std::vector<double>&>(sample.cont_params()),
                     const_cast<std::vector<int>&>(sample.disc_params()),
                     model_values,
                     true, true); // FIXME: add ostream for msgs!
   
   values.insert(values.end(), model_values.begin(), model_values.end());
   
   (*_sample_stream) << values.at(0);
   for (size_t i = 1; i < values.size(); ++i) {
     (*_sample_stream) << "," << values.at(i);
   }
   (*_sample_stream) << std::endl;
   
 }
Example #2
0
    void output_sample_params(RNG& rng, 
                              stan::mcmc::sample& s,
                              stan::mcmc::base_mcmc* sampler_ptr, 
                              M& model, 
                              std::vector<Rcpp::NumericVector>& chains, 
                              bool is_warmup,
                              std::vector<Rcpp::NumericVector>& sampler_params, 
                              std::vector<Rcpp::NumericVector>& iter_params, 
                              std::vector<double>& sum_pars,
                              double& sum_lp,
                              const std::vector<size_t>& qoi_idx,
                              int iter_save_i,
                              std::ostream* pstream) {
      std::vector<double> values;
      s.get_sample_params(values);

      std::vector<double> sampler_values;
      sampler_ptr -> get_sampler_params(sampler_values);
        
      std::vector<double> param_values;
      model.write_array(rng, 
                        const_cast<std::vector<double>&>(s.cont_params()),
                        const_cast<std::vector<int>&>(s.disc_params()),
                        param_values, true, true, pstream);
      // values in param_values are column-major.

      size_t z = 0;
      if (!is_warmup) {
        for (z = 0; z < param_values.size(); z++)
          sum_pars[z] += param_values[z];
        sum_lp += values.at(index_for_lp_);
      } 
     
      for (z = 0; z < sample_names_.size(); z++) {
        iter_params[z][iter_save_i] = values[z];
      } 
      for (z = 0; z < qoi_idx.size() - 1; ++z) {
        chains[z][iter_save_i] = param_values[qoi_idx[z]];
      } 
      chains[z][iter_save_i] = values.at(index_for_lp_);
      for (z = 0; z < sampler_values.size(); z++)
        sampler_params[z][iter_save_i] = sampler_values[z];
      
      if (!psample_stream_) return;
      (*psample_stream_) << values.at(0);
      for (size_t i = 1; i < values.size(); ++i) {
        (*psample_stream_) << "," << values[i];
      }
      for (size_t i = 0; i < sampler_values.size(); ++i)
        (*psample_stream_) << "," << sampler_values[i];
      for (size_t i = 0; i < param_values.size(); ++i)
        (*psample_stream_) << "," << param_values[i];
      (*psample_stream_) << std::endl;
    }