| Stan Math Library 2.12.0 reverse mode automatic differentiation

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

inv_wishart_rng.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_MAT_PROB_INV_WISHART_RNG_HPP
2 #define STAN_MATH_PRIM_MAT_PROB_INV_WISHART_RNG_HPP
3
4 #include <stan/math/prim/mat/err/check_square.hpp>
5 #include <stan/math/prim/mat/fun/inverse_spd.hpp>
6 #include <stan/math/prim/mat/meta/index_type.hpp>
7 #include <stan/math/prim/mat/prob/wishart_rng.hpp>
8 #include <stan/math/prim/scal/err/check_greater.hpp>
9
10 namespace stan {
11 namespace math {
12
13 template <class RNG>
14 inline Eigen::MatrixXd
15 inv_wishart_rng(const double nu, const Eigen::MatrixXd& S, RNG& rng) {
16 static const char* function("inv_wishart_rng");
17
18 using Eigen::MatrixXd;
19 typename index_type<MatrixXd>::type k = S.rows();
20
21 check_greater(function, "degrees of freedom > dims - 1", nu, k - 1);
22 check_square(function, "scale parameter", S);
23
24 MatrixXd S_inv = MatrixXd::Identity(k, k);
25 S_inv = S.ldlt().solve(S_inv);
26 MatrixXd asym = inverse_spd(wishart_rng(nu, S_inv, rng));
27 return 0.5 * (asym.transpose() + asym); // ensure symmetry
28 }
29
30 }
31 }
32 #endif
stan::math::wishart_rng
Eigen::MatrixXd wishart_rng(double nu, const Eigen::MatrixXd &S, RNG &rng)
Definition: wishart_rng.hpp:17
stan
Definition: log_sum_exp.hpp:8
wishart_rng.hpp
check_greater.hpp
stan::math::index_type
Primary template class for the metaprogram to compute the index type of a container.
Definition: index_type.hpp:18
index_type.hpp
stan::math::inv_wishart_rng
Eigen::MatrixXd inv_wishart_rng(const double nu, const Eigen::MatrixXd &S, RNG &rng)
Definition: inv_wishart_rng.hpp:15
stan::math::inverse_spd
Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > inverse_spd(const Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > &m)
Returns the inverse of the specified symmetric, pos/neg-definite matrix.
Definition: inverse_spd.hpp:20
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
inverse_spd.hpp
stan::math::check_greater
bool check_greater(const char *function, const char *name, const T_y &y, const T_low &low)
Return true if y is strictly greater than low.
Definition: check_greater.hpp:84
check_square.hpp

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