Stan Math Library  2.14.0
reverse mode automatic differentiation
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 
9 
10 namespace stan {
11  namespace math {
12 
13  template <class RNG>
14  inline Eigen::MatrixXd
15  inv_wishart_rng(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
Eigen::MatrixXd wishart_rng(double nu, const Eigen::MatrixXd &S, RNG &rng)
Definition: wishart_rng.hpp:17
Primary template class for the metaprogram to compute the index type of a container.
Definition: index_type.hpp:18
void check_square(const char *function, const char *name, const Eigen::Matrix< T_y, Eigen::Dynamic, Eigen::Dynamic > &y)
Check if the specified matrix is square.
Eigen::MatrixXd inv_wishart_rng(double nu, const Eigen::MatrixXd &S, RNG &rng)
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
void check_greater(const char *function, const char *name, const T_y &y, const T_low &low)
Check if y is strictly greater than low.

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