1#ifndef STAN_MATH_PRIM_PROB_LKJ_CORR_LPDF_HPP
2#define STAN_MATH_PRIM_PROB_LKJ_CORR_LPDF_HPP
15template <
typename T_shape>
17 const unsigned int& K) {
20 const int Km1 = K - 1;
24 Eigen::VectorXd denominator(Km1 / 2);
25 for (
int k = 1; k <= denominator.rows(); k++) {
26 denominator(k - 1) =
lgamma(2.0 * k);
31 - Km1 *
lgamma(0.5 * (K + 1));
35 - Km1 *
lgamma(
static_cast<double>(K));
39 for (
int k = 1; k <= Km1; k++) {
48template <
bool propto,
typename T_y,
typename T_shape>
50 static constexpr const char* function =
"lkj_corr_lpdf";
53 const auto& y_ref =
to_ref(y);
57 const unsigned int K = y.rows();
75 lp += (eta - 1.0) * sum_values;
79template <
typename T_y,
typename T_shape>
82 return lkj_corr_lpdf<false>(y, eta);
auto constant(const T a, int rows, int cols)
Matrix of repeated values in kernel generator expressions.
typename value_type< T >::type value_type_t
Helper function for accessing underlying type.
typename return_type< Ts... >::type return_type_t
Convenience type for the return type of the specified template parameters.
void check_corr_matrix(const char *function, const char *name, const Mat &y)
Throw an exception if the specified matrix is not a valid correlation matrix.
fvar< T > log(const fvar< T > &x)
static constexpr double LOG_TWO
The natural logarithm of 2, .
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.
static constexpr double LOG_PI
The natural logarithm of , .
fvar< T > lgamma(const fvar< T > &x)
Return the natural logarithm of the gamma function applied to the specified argument.
auto sum(const std::vector< T > &m)
Return the sum of the entries of the specified standard vector.
void check_positive(const char *function, const char *name, const T_y &y)
Check if y is positive.
return_type_t< T_y, T_shape > lkj_corr_lpdf(const T_y &y, const T_shape &eta)
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.