コード例 #1
0
ファイル: mcmc_writer.hpp プロジェクト: frenchjl/stan
 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;
   
 }
コード例 #2
0
ファイル: mcmc_output.hpp プロジェクト: RossBoylan/rstan
    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;
    }
コード例 #3
0
ファイル: mcmc_writer.hpp プロジェクト: BunnyRabbit8mile/stan
      /**
       * Print diagnostic params to the diagnostic stream.
       *
       * @param sample unconstrained sample
       * @param sampler sampler
       *
       * @pre sample and sampler are consistent
       * @post none.
       * @sideeffects diagnostic_stream_ is appended with csv values of the
       *   sample's get_sample_params(), the sampler's get_sampler_params(),
       *   and get_sampler_diagnostics()
       */
      void write_diagnostic_params(stan::mcmc::sample& sample,
                                   stan::mcmc::base_mcmc* sampler) {
        std::vector<double> values;

        sample.get_sample_params(values);
        sampler->get_sampler_params(values);
        sampler->get_sampler_diagnostics(values);

        diagnostic_writer_(values);
      }
コード例 #4
0
ファイル: mcmc_writer.hpp プロジェクト: BunnyRabbit8mile/stan
      /**
       * Outputs parameter string names. First outputs the names stored in
       * the sample object (stan::mcmc::sample), then uses the sampler provided
       * to output sampler specific names, then adds the model constrained
       * parameter names.
       *
       * The names are written to the sample_stream as comma separated values
       * with a newline at the end.
       *
       * @param sample a sample (unconstrained) that works with the model
       * @param sampler a stan::mcmc::base_mcmc object
       * @param model the model
       *
       * @pre none
       * @post none
       * @sideeffects sample_stream_ is written to with comma separated values
       *   with a newline at the end
       */
      void write_sample_names(stan::mcmc::sample& sample,
                              stan::mcmc::base_mcmc* sampler,
                              M& model) {
        std::vector<std::string> names;

        sample.get_sample_param_names(names);
        sampler->get_sampler_param_names(names);
        model.constrained_param_names(names, true, true);

        sample_writer_(names);
      }
コード例 #5
0
ファイル: mcmc_writer.hpp プロジェクト: BunnyRabbit8mile/stan
      void write_sample_params(RNG& rng,
                               stan::mcmc::sample& sample,
                               stan::mcmc::base_mcmc& sampler,
                               M& model) {
        std::vector<double> values;

        sample.get_sample_params(values);
        sampler.get_sampler_params(values);

        Eigen::VectorXd model_values;

        model.write_array(rng,
                          const_cast<Eigen::VectorXd&>(sample.cont_params()),
                          model_values,
                          true, true,
                          msg_stream_);

        for (int i = 0; i < model_values.size(); ++i)
          values.push_back(model_values(i));

        sample_writer_(values);
      }
コード例 #6
0
ファイル: mcmc_output.hpp プロジェクト: RossBoylan/rstan
    void output_diagnostic_params(stan::mcmc::sample& s, 
                                  stan::mcmc::base_mcmc* sampler_ptr) { 
      if (!pdiagnostic_stream_) return;

      std::vector<double> values;
      s.get_sample_params(values);
      sampler_ptr -> get_sampler_params(values);
      sampler_ptr -> get_sampler_diagnostics(values); // FIXME,col/row-major order??
      (*pdiagnostic_stream_) << values.at(0);
      for (size_t i = 1; i < values.size(); ++i) {
        (*pdiagnostic_stream_) << "," << values.at(i);
      }
      (*pdiagnostic_stream_) << std::endl;
    }
コード例 #7
0
ファイル: mcmc_writer.hpp プロジェクト: BunnyRabbit8mile/stan
      /**
       * Print diagnostic names
       *
       * @param sample unconstrained sample
       * @param sampler sampler
       * @param model model
       *
       * @pre sample, sampler, and model are consistent.
       * @post none
       * @sideeffects diagnostic_stream_ is appended with comma
       *   separated names with newline at the end
       */
      void write_diagnostic_names(stan::mcmc::sample sample,
                                  stan::mcmc::base_mcmc* sampler,
                                  M& model) {
        std::vector<std::string> names;

        sample.get_sample_param_names(names);
        sampler->get_sampler_param_names(names);

        std::vector<std::string> model_names;
        model.unconstrained_param_names(model_names, false, false);

        sampler->get_sampler_diagnostic_names(model_names, names);

        diagnostic_writer_(names);
      }
コード例 #8
0
ファイル: mcmc_output.hpp プロジェクト: RossBoylan/rstan
 /*
  * @param iter_param_names
  * @param sampler_param_names
  */
 void set_output_names(stan::mcmc::sample& s, 
                       stan::mcmc::base_mcmc* sampler_ptr,
                       M& model,
                       std::vector<std::string>& iter_param_names,
                       std::vector<std::string>& sampler_param_names) { 
   sample_names_.clear();
   s.get_sample_param_names(sample_names_);
   index_for_lp_ = find_index(sample_names_, std::string("lp__")); 
   sampler_names_.clear();
   sampler_ptr -> get_sampler_param_names(sampler_names_);
   param_names_.clear();
   model.constrained_param_names(param_names_, true, true);
   iter_param_names = sample_names_;
   sampler_param_names = sampler_names_;
 }
コード例 #9
0
ファイル: mcmc_writer.hpp プロジェクト: frenchjl/stan
 void print_diagnostic_params(stan::mcmc::sample& sample,
                              stan::mcmc::base_mcmc* sampler) {
   
   if(!_diagnostic_stream) return;
   
   std::vector<double> values;
   
   sample.get_sample_params(values);
   sampler->get_sampler_params(values);
   sampler->get_sampler_diagnostics(values);
   
   (*_diagnostic_stream) << values.at(0);
   for (size_t i = 1; i < values.size(); ++i) {
     (*_diagnostic_stream) << "," << values.at(i);
   }
   (*_diagnostic_stream) << std::endl;
   
 }
コード例 #10
0
ファイル: mcmc_output.hpp プロジェクト: RossBoylan/rstan
    void output_diagnostic_names(stan::mcmc::sample& s,
                                 stan::mcmc::base_mcmc* sampler_ptr, 
                                 M& model) {
      if (!pdiagnostic_stream_) return;

      std::vector<std::string> names;
      s.get_sample_param_names(names);
      sampler_ptr -> get_sampler_param_names(names);
      std::vector<std::string> model_names;
      model.unconstrained_param_names(model_names, false, false);
      sampler_ptr -> get_sampler_diagnostic_names(model_names, names);
        
      (*pdiagnostic_stream_) << names.at(0);
      for (size_t i = 1; i < names.size(); ++i) {
        (*pdiagnostic_stream_) << "," << names.at(i);
      }
      (*pdiagnostic_stream_) << std::endl;
    }
コード例 #11
0
ファイル: mcmc_writer.hpp プロジェクト: frenchjl/stan
 void print_sample_names(stan::mcmc::sample& sample,
                         stan::mcmc::base_mcmc* sampler,
                         M& model) {
   
   if(!_sample_stream) return;
   
   std::vector<std::string> names;
   
   sample.get_sample_param_names(names);
   sampler->get_sampler_param_names(names);
   model.constrained_param_names(names, true, true);
  
   (*_sample_stream) << names.at(0);
   for (size_t i = 1; i < names.size(); ++i) {
     (*_sample_stream) << "," << names.at(i);
   }
   (*_sample_stream) << std::endl;
   
 }