Stan Math Library  2.12.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("lkj_corr_cholesky_rng");
56 
57  check_positive(function, "Shape parameter", eta);
58 
59  Eigen::ArrayXd CPCs((K * (K - 1)) / 2);
60  double alpha = eta + 0.5 * (K - 1);
61  unsigned int count = 0;
62  for (size_t i = 0; i < (K - 1); i++) {
63  alpha -= 0.5;
64  for (size_t j = i + 1; j < K; j++) {
65  CPCs(count) = 2.0 * beta_rng(alpha, alpha, rng) - 1.0;
66  count++;
67  }
68  }
69  return read_corr_L(CPCs, K);
70  }
71 
72  }
73 }
74 #endif
double beta_rng(const double alpha, const double beta, RNG &rng)
Definition: beta_rng.hpp:28
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:37
Eigen::MatrixXd lkj_corr_cholesky_rng(const size_t K, const double eta, RNG &rng)

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