Stan Math Library  2.11.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 
46 
47 namespace stan {
48  namespace math {
49 
50  template <class RNG>
51  inline Eigen::MatrixXd
52  lkj_corr_cholesky_rng(const size_t K,
53  const double eta,
54  RNG& rng) {
55  static const char* function("stan::math::lkj_corr_cholesky_rng");
56 
58 
59  check_positive(function, "Shape parameter", eta);
60 
61  Eigen::ArrayXd CPCs((K * (K - 1)) / 2);
62  double alpha = eta + 0.5 * (K - 1);
63  unsigned int count = 0;
64  for (size_t i = 0; i < (K - 1); i++) {
65  alpha -= 0.5;
66  for (size_t j = i + 1; j < K; j++) {
67  CPCs(count) = 2.0 * stan::math::beta_rng(alpha, alpha, rng) - 1.0;
68  count++;
69  }
70  }
71  return stan::math::read_corr_L(CPCs, K);
72  }
73 
74  }
75 }
76 #endif
double beta_rng(const double alpha, const double beta, RNG &rng)
Definition: beta_rng.hpp:29
bool check_positive(const char *function, const char *name, const T_y &y)
Return true if y is positive.
Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > read_corr_L(const Eigen::Array< T, Eigen::Dynamic, 1 > &CPCs, const size_t K)
Return the Cholesky factor of the correlation matrix of the specified dimensionality corresponding to...
Definition: read_corr_L.hpp:41
Eigen::MatrixXd lkj_corr_cholesky_rng(const size_t K, const double eta, RNG &rng)

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