Stan Math Library  2.20.0
reverse mode automatic differentiation
lkj_corr_cholesky_rng.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_MAT_PROB_LKJ_CORR_CHOLESKY_RNG_HPP
2 #define STAN_MATH_PRIM_MAT_PROB_LKJ_CORR_CHOLESKY_RNG_HPP
3 
8 
9 namespace stan {
10 namespace math {
11 
12 template <class RNG>
13 inline Eigen::MatrixXd lkj_corr_cholesky_rng(size_t K, double eta, RNG& rng) {
14  static const char* function = "lkj_corr_cholesky_rng";
15 
16  check_positive(function, "Shape parameter", eta);
17 
18  Eigen::ArrayXd CPCs((K * (K - 1)) / 2);
19  double alpha = eta + 0.5 * (K - 1);
20  unsigned int count = 0;
21  for (size_t i = 0; i < (K - 1); i++) {
22  alpha -= 0.5;
23  for (size_t j = i + 1; j < K; j++) {
24  CPCs(count) = 2.0 * beta_rng(alpha, alpha, rng) - 1.0;
25  count++;
26  }
27  }
28  return read_corr_L(CPCs, K);
29 }
30 
31 } // namespace math
32 } // namespace stan
33 #endif
VectorBuilder< true, double, T_shape1, T_shape2 >::type beta_rng(const T_shape1 &alpha, const T_shape2 &beta, RNG &rng)
Return a Beta random variate with the supplied success and failure parameters using the given random ...
Definition: beta_rng.hpp:34
Eigen::MatrixXd lkj_corr_cholesky_rng(size_t K, double eta, RNG &rng)
void check_positive(const char *function, const char *name, const T_y &y)
Check if y is positive.
Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > read_corr_L(const Eigen::Array< T, Eigen::Dynamic, 1 > &CPCs, size_t K)
Return the Cholesky factor of the correlation matrix of the specified dimensionality corresponding to...
Definition: read_corr_L.hpp:35

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