Automatic Differentiation
 
Loading...
Searching...
No Matches
lkj_corr_cholesky_rng.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_PROB_LKJ_CORR_CHOLESKY_RNG_HPP
2#define STAN_MATH_PRIM_PROB_LKJ_CORR_CHOLESKY_RNG_HPP
3
8
9namespace stan {
10namespace math {
11
12template <class RNG>
13inline Eigen::MatrixXd lkj_corr_cholesky_rng(size_t K, double eta, RNG& rng) {
14 static constexpr const char* function = "lkj_corr_cholesky_rng";
15 check_positive(function, "Shape parameter", eta);
16
17 Eigen::ArrayXd CPCs((K * (K - 1)) / 2);
18 double alpha = eta + 0.5 * (K - 1);
19 unsigned int count = 0;
20 for (size_t i = 0; i < (K - 1); i++) {
21 alpha -= 0.5;
22 for (size_t j = i + 1; j < K; j++) {
23 CPCs(count) = 2.0 * beta_rng(alpha, alpha, rng) - 1.0;
24 count++;
25 }
26 }
27 return read_corr_L(CPCs, K);
28}
29
30} // namespace math
31} // namespace stan
32#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:36
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< value_type_t< T >, Eigen::Dynamic, Eigen::Dynamic > read_corr_L(const T &CPCs, size_t K)
Return the Cholesky factor of the correlation matrix of the specified dimensionality corresponding to...
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...