Stan Math Library  2.14.0
reverse mode automatic differentiation
multi_normal_cholesky_rng.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_MAT_PROB_MULTI_NORMAL_CHOLESKY_RNG_HPP
2 #define STAN_MATH_PRIM_MAT_PROB_MULTI_NORMAL_CHOLESKY_RNG_HPP
3 
4 #include <boost/random/normal_distribution.hpp>
5 #include <boost/random/variate_generator.hpp>
20 
23 
24 namespace stan {
25  namespace math {
26  template <class RNG>
27  inline Eigen::VectorXd
29  const Eigen::Matrix<double, Eigen::Dynamic, 1>& mu,
30  const Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic>& S,
31  RNG& rng) {
32  using boost::variate_generator;
33  using boost::normal_distribution;
34 
35  static const char* function("multi_normal_cholesky_rng");
36  check_finite(function, "Location parameter", mu);
37 
38  variate_generator<RNG&, normal_distribution<> >
39  std_normal_rng(rng, normal_distribution<>(0, 1));
40 
41  Eigen::VectorXd z(S.cols());
42  for (int i = 0; i < S.cols(); i++)
43  z(i) = std_normal_rng();
44 
45  return mu + S * z;
46  }
47  }
48 }
49 #endif
void check_finite(const char *function, const char *name, const T_y &y)
Check if y is finite.
Eigen::VectorXd multi_normal_cholesky_rng(const Eigen::Matrix< double, Eigen::Dynamic, 1 > &mu, const Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > &S, RNG &rng)

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