| Stan Math Library 2.11.0 reverse mode automatic differentiation

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

multi_normal_rng.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_MAT_PROB_MULTI_NORMAL_RNG_HPP
2 #define STAN_MATH_PRIM_MAT_PROB_MULTI_NORMAL_RNG_HPP
3
4 #include <boost/random/normal_distribution.hpp>
5 #include <boost/random/variate_generator.hpp>
6 #include <stan/math/prim/mat/err/check_ldlt_factor.hpp>
7 #include <stan/math/prim/scal/err/check_size_match.hpp>
8 #include <stan/math/prim/mat/err/check_symmetric.hpp>
9 #include <stan/math/prim/scal/err/check_finite.hpp>
10 #include <stan/math/prim/scal/err/check_not_nan.hpp>
11 #include <stan/math/prim/scal/err/check_positive.hpp>
12 #include <stan/math/prim/mat/fun/trace_inv_quad_form_ldlt.hpp>
13 #include <stan/math/prim/mat/fun/log_determinant_ldlt.hpp>
14
15 #include <stan/math/prim/scal/fun/constants.hpp>
16 #include <stan/math/prim/scal/meta/include_summand.hpp>
17
18 namespace stan {
19
20 namespace math {
21
22 template <class RNG>
23 inline Eigen::VectorXd
24 multi_normal_rng(
25 const Eigen::Matrix<double, Eigen::Dynamic, 1>& mu,
26 const Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic>& S,
27 RNG& rng
28 ) {
29 using boost::variate_generator;
30 using boost::normal_distribution;
31
32 static const char* function("stan::math::multi_normal_rng");
33
34 using stan::math::check_finite;
35 using stan::math::check_positive;
36 using stan::math::check_symmetric;
37
38 check_positive(function, "Covariance matrix rows", S.rows());
39 check_symmetric(function, "Covariance matrix", S);
40 check_finite(function, "Location parameter", mu);
41
42 variate_generator<RNG&, normal_distribution<> >
43 std_normal_rng(rng, normal_distribution<>(0, 1));
44
45 Eigen::VectorXd z(S.cols());
46 for (int i = 0; i < S.cols(); i++)
47 z(i) = std_normal_rng();
48
49 return mu + S.llt().matrixL() * z;
50 }
51 }
52 }
53
54 #endif
check_not_nan.hpp
check_size_match.hpp
check_positive.hpp
stan
Definition: log_sum_exp.hpp:8
trace_inv_quad_form_ldlt.hpp
check_symmetric.hpp
include_summand.hpp
check_ldlt_factor.hpp
stan::math::check_positive
bool check_positive(const char *function, const char *name, const T_y &y)
Return true if y is positive.
Definition: check_positive.hpp:68
stan::math::check_finite
bool check_finite(const char *function, const char *name, const T_y &y)
Return true if y is finite.
Definition: check_finite.hpp:62
constants.hpp
check_finite.hpp
stan::math::multi_normal_rng
Eigen::VectorXd multi_normal_rng(const Eigen::Matrix< double, Eigen::Dynamic, 1 > &mu, const Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > &S, RNG &rng)
Definition: multi_normal_rng.hpp:24
stan::math::check_symmetric
bool check_symmetric(const char *function, const char *name, const Eigen::Matrix< T_y, Eigen::Dynamic, Eigen::Dynamic > &y)
Return true if the specified matrix is symmetric.
Definition: check_symmetric.hpp:37
log_determinant_ldlt.hpp

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