Stan Math Library  2.6.3
probability, sampling & optimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros
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 
48 
49 namespace stan {
50  namespace math {
51 
52  template <class RNG>
53  inline Eigen::MatrixXd
54  lkj_corr_cholesky_rng(const size_t K,
55  const double eta,
56  RNG& rng) {
57  static const char* function("stan::math::lkj_corr_cholesky_rng");
58 
60 
61  check_positive(function, "Shape parameter", eta);
62 
63  Eigen::ArrayXd CPCs((K * (K - 1)) / 2);
64  double alpha = eta + 0.5 * (K - 1);
65  unsigned int count = 0;
66  for (size_t i = 0; i < (K - 1); i++) {
67  alpha -= 0.5;
68  for (size_t j = i + 1; j < K; j++) {
69  CPCs(count) = 2.0 * stan::math::beta_rng(alpha, alpha, rng) - 1.0;
70  count++;
71  }
72  }
73  return stan::math::read_corr_L(CPCs, K);
74  }
75 
76  }
77 }
78 #endif
double beta_rng(const double alpha, const double beta, RNG &rng)
Definition: beta_rng.hpp:30
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–2015, Stan Development Team.