1#ifndef STAN_MATH_PRIM_PROB_LKJ_COV_LPDF_HPP
2#define STAN_MATH_PRIM_PROB_LKJ_COV_LPDF_HPP
18template <
bool propto,
typename T_y,
typename T_loc,
typename T_scale,
19 typename T_shape, require_eigen_matrix_dynamic_t<T_y>* =
nullptr,
20 require_all_eigen_col_vector_t<T_loc, T_scale>* =
nullptr>
25 static constexpr const char* function =
"lkj_cov_lpdf";
27 "columns of scale parameter", sigma.rows());
30 "rows of location parameter", mu.rows());
31 const auto& y_ref =
to_ref(y);
32 const auto& mu_ref =
to_ref(mu);
33 const auto& sigma_ref =
to_ref(sigma);
41 const unsigned int K = y.rows();
42 const Eigen::Array<value_type_t<T_y>, Eigen::Dynamic, 1> sds
43 = y_ref.diagonal().array().sqrt();
44 for (
unsigned int k = 0; k < K; k++) {
45 lp += lognormal_lpdf<propto>(sds(k), mu_ref(k), sigma_ref(k));
49 lp += lkj_corr_lpdf<propto>(y_ref, eta);
52 Eigen::DiagonalMatrix<value_type_t<T_y>, Eigen::Dynamic> D(K);
53 D.diagonal() = sds.inverse();
54 lp += lkj_corr_lpdf<propto>(D * y_ref * D, eta);
63template <
bool propto,
typename T_y,
typename T_loc,
typename T_scale,
70 static constexpr const char* function =
"lkj_cov_lpdf";
74 const auto& y_ref =
to_ref(y);
79 const unsigned int K = y.rows();
80 const Eigen::Array<value_type_t<T_y>, Eigen::Dynamic, 1> sds
81 = y_ref.diagonal().array().sqrt();
82 for (
unsigned int k = 0; k < K; k++) {
83 lp += lognormal_lpdf<propto>(sds(k), mu, sigma);
87 lp += lkj_corr_lpdf<propto>(y_ref, eta);
90 Eigen::DiagonalMatrix<value_type_t<T_y>, Eigen::Dynamic> D(K);
91 D.diagonal() = sds.inverse();
92 lp += lkj_corr_lpdf<propto>(D * y_ref * D, eta);
99template <
typename T_y,
typename T_loc,
typename T_scale,
typename T_shape>
101 const T_y& y,
const T_loc& mu,
const T_scale& sigma,
const T_shape& eta) {
102 return lkj_cov_lpdf<false>(y, mu, sigma, eta);
require_t< is_eigen_matrix_dynamic< std::decay_t< T > > > require_eigen_matrix_dynamic_t
Require type satisfies is_eigen_matrix_dynamic.
require_all_t< is_stan_scalar< std::decay_t< Types > >... > require_all_stan_scalar_t
Require all of the types satisfy is_stan_scalar.
typename return_type< Ts... >::type return_type_t
Convenience type for the return type of the specified template parameters.
void check_square(const char *function, const char *name, const T_y &y)
Check if the specified matrix is square.
return_type_t< T_y, T_loc, T_scale, T_shape > lkj_cov_lpdf(const T_y &y, const T_loc &mu, const T_scale &sigma, const T_shape &eta)
ref_type_t< T && > to_ref(T &&a)
This evaluates expensive Eigen expressions.
void check_finite(const char *function, const char *name, const T_y &y)
Return true if all values in y are finite.
void check_positive(const char *function, const char *name, const T_y &y)
Check if y is positive.
void check_size_match(const char *function, const char *name_i, T_size1 i, const char *name_j, T_size2 j)
Check if the provided sizes match.
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...