Stan  2.14.0
probability, sampling & optimization
log_prob_propto.hpp
Go to the documentation of this file.
1 #ifndef STAN_MODEL_LOG_PROB_PROPTO_HPP
2 #define STAN_MODEL_LOG_PROB_PROPTO_HPP
3 
4 #include <stan/math/rev/mat.hpp>
5 #include <iostream>
6 #include <vector>
7 
8 namespace stan {
9  namespace model {
10 
32  template <bool jacobian_adjust_transform, class M>
33  double log_prob_propto(const M& model,
34  std::vector<double>& params_r,
35  std::vector<int>& params_i,
36  std::ostream* msgs = 0) {
37  using stan::math::var;
38  using std::vector;
39  vector<var> ad_params_r;
40  ad_params_r.reserve(model.num_params_r());
41  for (size_t i = 0; i < model.num_params_r(); ++i)
42  ad_params_r.push_back(params_r[i]);
43  try {
44  double lp
45  = model.template log_prob<true, jacobian_adjust_transform>
46  (ad_params_r, params_i, msgs).val();
47  stan::math::recover_memory();
48  return lp;
49  } catch (std::exception &ex) {
50  stan::math::recover_memory();
51  throw;
52  }
53  }
54 
75  template <bool jacobian_adjust_transform, class M>
76  double log_prob_propto(const M& model,
77  Eigen::VectorXd& params_r,
78  std::ostream* msgs = 0) {
79  using stan::math::var;
80  using std::vector;
81  vector<int> params_i(0);
82 
83  double lp;
84  try {
85  vector<var> ad_params_r;
86  ad_params_r.reserve(model.num_params_r());
87  for (size_t i = 0; i < model.num_params_r(); ++i)
88  ad_params_r.push_back(params_r(i));
89  lp
90  = model
91  .template log_prob<true,
92  jacobian_adjust_transform>(ad_params_r, params_i,
93  msgs)
94  .val();
95  } catch (std::exception &ex) {
96  stan::math::recover_memory();
97  throw;
98  }
99  stan::math::recover_memory();
100  return lp;
101  }
102 
103  }
104 }
105 #endif
Probability, optimization and sampling library.
double log_prob_propto(const M &model, std::vector< double > &params_r, std::vector< int > &params_i, std::ostream *msgs=0)
Helper function to calculate log probability for double scalars up to a proportion.

     [ Stan Home Page ] © 2011–2016, Stan Development Team.