1 #ifndef STAN_MATH_PRIM_MAT_PROB_LKJ_COV_LPDF_HPP 2 #define STAN_MATH_PRIM_MAT_PROB_LKJ_COV_LPDF_HPP 17 template <
bool propto,
typename T_y,
typename T_loc,
typename T_scale,
19 typename boost::math::tools::promote_args<T_y, T_loc, T_scale, T_shape>::type
20 lkj_cov_lpdf(
const Eigen::Matrix<T_y, Eigen::Dynamic, Eigen::Dynamic>& y,
21 const Eigen::Matrix<T_loc, Eigen::Dynamic, 1>& mu,
22 const Eigen::Matrix<T_scale, Eigen::Dynamic, 1>& sigma,
24 static const char*
function =
"lkj_cov_lpdf";
26 using boost::math::tools::promote_args;
28 typename promote_args<T_y, T_loc, T_scale, T_shape>::type lp(0.0);
30 "columns of scale parameter", sigma.rows());
33 "rows of location parameter", mu.rows());
37 for (
int m = 0; m < y.rows(); ++m)
38 for (
int n = 0; n < y.cols(); ++n)
41 const unsigned int K = y.rows();
42 const Eigen::Array<T_y, Eigen::Dynamic, 1> sds = y.diagonal().array().sqrt();
43 for (
unsigned int k = 0; k < K; k++) {
44 lp += lognormal_lpdf<propto>(sds(k), mu(k), sigma(k));
49 lp += lkj_corr_lpdf<propto, T_y, T_shape>(y, eta);
52 Eigen::DiagonalMatrix<T_y, Eigen::Dynamic> D(K);
53 D.diagonal() = sds.inverse();
54 lp += lkj_corr_lpdf<propto, T_y, T_shape>(D * y * D, eta);
58 template <
typename T_y,
typename T_loc,
typename T_scale,
typename T_shape>
59 inline typename boost::math::tools::promote_args<T_y, T_loc, T_scale,
61 lkj_cov_lpdf(
const Eigen::Matrix<T_y, Eigen::Dynamic, Eigen::Dynamic>& y,
62 const Eigen::Matrix<T_loc, Eigen::Dynamic, 1>& mu,
63 const Eigen::Matrix<T_scale, Eigen::Dynamic, 1>& sigma,
65 return lkj_cov_lpdf<false>(y, mu, sigma, eta);
70 template <
bool propto,
typename T_y,
typename T_loc,
typename T_scale,
72 typename boost::math::tools::promote_args<T_y, T_loc, T_scale, T_shape>::type
73 lkj_cov_lpdf(
const Eigen::Matrix<T_y, Eigen::Dynamic, Eigen::Dynamic>& y,
74 const T_loc& mu,
const T_scale& sigma,
const T_shape& eta) {
75 static const char*
function =
"lkj_cov_lpdf";
77 using boost::math::tools::promote_args;
79 typename promote_args<T_y, T_loc, T_scale, T_shape>::type lp(0.0);
84 const unsigned int K = y.rows();
85 const Eigen::Array<T_y, Eigen::Dynamic, 1> sds = y.diagonal().array().sqrt();
86 for (
unsigned int k = 0; k < K; k++) {
87 lp += lognormal_lpdf<propto>(sds(k), mu, sigma);
92 lp += lkj_corr_lpdf<propto>(y, eta);
95 Eigen::DiagonalMatrix<T_y, Eigen::Dynamic> D(K);
96 D.diagonal() = sds.inverse();
97 lp += lkj_corr_lpdf<propto, T_y, T_shape>(D * y * D, eta);
101 template <
typename T_y,
typename T_loc,
typename T_scale,
typename T_shape>
102 inline typename boost::math::tools::promote_args<T_y, T_loc, T_scale,
104 lkj_cov_lpdf(
const Eigen::Matrix<T_y, Eigen::Dynamic, Eigen::Dynamic>& y,
105 const T_loc& mu,
const T_scale& sigma,
const T_shape& eta) {
106 return lkj_cov_lpdf<false>(y, mu, sigma, eta);
Metaprogram structure to determine the base scalar type of a template argument.
void check_finite(const char *function, const char *name, const T_y &y)
Check if y is finite.
boost::math::tools::promote_args< T_y, T_loc, T_scale, T_shape >::type lkj_cov_lpdf(const Eigen::Matrix< T_y, Eigen::Dynamic, Eigen::Dynamic > &y, const Eigen::Matrix< T_loc, Eigen::Dynamic, 1 > &mu, const Eigen::Matrix< T_scale, Eigen::Dynamic, 1 > &sigma, const T_shape &eta)
Extends std::true_type when instantiated with zero or more template parameters, all of which extend t...
void check_square(const char *function, const char *name, const matrix_cl &y)
Check if the matrix_cl is square.
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.
void check_positive(const char *function, const char *name, const T_y &y)
Check if y is positive.