1#ifndef STAN_MATH_PRIM_PROB_LKJ_CORR_CHOLESKY_LPDF_HPP
2#define STAN_MATH_PRIM_PROB_LKJ_CORR_CHOLESKY_LPDF_HPP
17template <
bool propto,
typename T_covar,
typename T_shape>
21 static constexpr const char* function =
"lkj_corr_cholesky_lpdf";
24 const auto& L_ref =
to_ref(L);
27 const unsigned int K = L.rows();
38 const int Km1 = K - 1;
39 Eigen::Matrix<value_type_t<T_covar>, Eigen::Dynamic, 1> log_diagonals
40 =
log(L_ref.diagonal().tail(Km1).array());
41 Eigen::Matrix<lp_ret, Eigen::Dynamic, 1> values(Km1);
42 for (
int k = 0; k < Km1; k++) {
43 values(k) = (Km1 - k - 1) * log_diagonals(k);
49 values +=
multiply(2.0 * eta - 2.0, log_diagonals);
56template <
typename T_covar,
typename T_shape>
58 const T_covar& L,
const T_shape& eta) {
59 return lkj_corr_cholesky_lpdf<false>(L, eta);
typename return_type< Ts... >::type return_type_t
Convenience type for the return type of the specified template parameters.
fvar< T > log(const fvar< T > &x)
auto multiply(const Mat1 &m1, const Mat2 &m2)
Return the product of the specified matrices.
return_type_t< T_covar, T_shape > lkj_corr_cholesky_lpdf(const T_covar &L, const T_shape &eta)
return_type_t< double, T_shape > do_lkj_constant(const T_shape &eta, const unsigned int &K)
ref_type_t< T && > to_ref(T &&a)
This evaluates expensive Eigen expressions.
auto sum(const std::vector< T > &m)
Return the sum of the entries of the specified standard vector.
void check_cholesky_factor(const char *function, const char *name, const Mat &y)
Throw an exception if the specified matrix is not a valid Cholesky factor.
void check_positive(const char *function, const char *name, const T_y &y)
Check if y is positive.
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
Extends std::true_type when instantiated with zero or more template parameters, all of which extend t...
Template metaprogram to calculate whether a summand needs to be included in a proportional (log) prob...
Metaprogram structure to determine the base scalar type of a template argument.