Stan Math Library: stan/math/prim/mat/prob/wishart_rng.hpp Source File

| Stan Math Library 2.10.0 reverse mode automatic differentiation

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

wishart_rng.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_MAT_PROB_WISHART_RNG_HPP
2 #define STAN_MATH_PRIM_MAT_PROB_WISHART_RNG_HPP
3
4 #include <stan/math/prim/scal/err/check_size_match.hpp>
5 #include <stan/math/prim/mat/err/check_ldlt_factor.hpp>
6 #include <stan/math/prim/mat/err/check_square.hpp>
7 #include <stan/math/prim/scal/err/check_greater.hpp>
8 #include <stan/math/prim/scal/fun/lmgamma.hpp>
9 #include <stan/math/prim/mat/fun/crossprod.hpp>
10 #include <stan/math/prim/mat/fun/columns_dot_product.hpp>
11 #include <stan/math/prim/mat/fun/trace.hpp>
12 #include <stan/math/prim/mat/fun/log_determinant_ldlt.hpp>
13 #include <stan/math/prim/mat/fun/mdivide_left_ldlt.hpp>
14 #include <stan/math/prim/mat/fun/dot_product.hpp>
15 #include <stan/math/prim/mat/fun/mdivide_left_tri_low.hpp>
16 #include <stan/math/prim/mat/fun/multiply_lower_tri_self_transpose.hpp>
17 #include <stan/math/prim/mat/meta/index_type.hpp>
18 #include <stan/math/prim/scal/fun/constants.hpp>
19 #include <stan/math/prim/scal/prob/normal_rng.hpp>
20 #include <stan/math/prim/scal/prob/chi_square_rng.hpp>
21 #include <stan/math/prim/scal/meta/include_summand.hpp>
22
23 namespace stan {
24
25 namespace math {
26
27 template <class RNG>
28 inline Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic>
29 wishart_rng(const double nu,
30 const Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic>& S,
31 RNG& rng) {
32 using Eigen::MatrixXd;
33 using stan::math::index_type;
34 using stan::math::check_positive;
35 using stan::math::check_size_match;
36 using stan::math::check_square;
37
38 static const char* function("stan::math::wishart_rng");
39
40 typename index_type<MatrixXd>::type k = S.rows();
41
42 check_positive(function, "degrees of freedom", nu);
43 check_square(function, "scale parameter", S);
44
45 MatrixXd B = MatrixXd::Zero(k, k);
46
47 for (int j = 0; j < k; ++j) {
48 for (int i = 0; i < j; ++i)
49 B(i, j) = normal_rng(0, 1, rng);
50 B(j, j) = std::sqrt(chi_square_rng(nu - j, rng));
51 }
52
53 return stan::math::crossprod(B * S.llt().matrixU());
54 }
55
56
57 }
58
59 }
60 #endif
stan::math::chi_square_rng
double chi_square_rng(const double nu, RNG &rng)
Definition: chi_square_rng.hpp:24
multiply_lower_tri_self_transpose.hpp
stan::math::sqrt
fvar< T > sqrt(const fvar< T > &x)
Definition: sqrt.hpp:15
check_size_match.hpp
stan
Definition: log_sum_exp.hpp:8
crossprod.hpp
normal_rng.hpp
trace.hpp
include_summand.hpp
check_greater.hpp
check_ldlt_factor.hpp
columns_dot_product.hpp
stan::math::index_type
Primary template class for the metaprogram to compute the index type of a container.
Definition: index_type.hpp:19
stan::math::wishart_rng
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > wishart_rng(const double nu, const Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > &S, RNG &rng)
Definition: wishart_rng.hpp:29
index_type.hpp
stan::math::crossprod
Eigen::Matrix< fvar< T >, C, C > crossprod(const Eigen::Matrix< fvar< T >, R, C > &m)
Definition: crossprod.hpp:17
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_size_match
bool check_size_match(const char *function, const char *name_i, T_size1 i, const char *name_j, T_size2 j)
Return true if the provided sizes match.
Definition: check_size_match.hpp:30
dot_product.hpp
chi_square_rng.hpp
constants.hpp
lmgamma.hpp
mdivide_left_ldlt.hpp
stan::math::check_square
bool check_square(const char *function, const char *name, const Eigen::Matrix< T_y, Eigen::Dynamic, Eigen::Dynamic > &y)
Return true if the specified matrix is square.
Definition: check_square.hpp:28
mdivide_left_tri_low.hpp
stan::math::normal_rng
double normal_rng(const double mu, const double sigma, RNG &rng)
Definition: normal_rng.hpp:19
log_determinant_ldlt.hpp
check_square.hpp

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