1 #ifndef STAN_MATH_PRIM_MAT_PROB_LKJ_COV_LPDF_HPP 2 #define STAN_MATH_PRIM_MAT_PROB_LKJ_COV_LPDF_HPP 18 template <
bool propto,
19 typename T_y,
typename T_loc,
typename T_scale,
typename T_shape>
21 boost::math::tools::promote_args<T_y, T_loc, T_scale, T_shape>::type
22 lkj_cov_lpdf(
const Eigen::Matrix<T_y, Eigen::Dynamic, Eigen::Dynamic>& y,
23 const Eigen::Matrix<T_loc, Eigen::Dynamic, 1>& mu,
24 const Eigen::Matrix<T_scale, Eigen::Dynamic, 1>& sigma,
26 static const char*
function(
"lkj_cov_lpdf");
28 using boost::math::tools::promote_args;
30 typename promote_args<T_y, T_loc, T_scale, T_shape>::type lp(0.0);
32 "Rows of location parameter", mu.rows(),
33 "columns of scale parameter", sigma.rows());
36 "Rows of random variable", y.rows(),
37 "rows of location parameter", mu.rows());
41 for (
int m = 0; m < y.rows(); ++m)
42 for (
int n = 0; n < y.cols(); ++n)
45 const unsigned int K = y.rows();
46 const Eigen::Array<T_y, Eigen::Dynamic, 1> sds
47 = y.diagonal().array().sqrt();
48 for (
unsigned int k = 0; k < K; k++) {
49 lp += lognormal_lpdf<propto>(sds(k), mu(k), sigma(k));
54 lp += lkj_corr_lpdf<propto, T_y, T_shape>(y, eta);
57 Eigen::DiagonalMatrix<T_y, Eigen::Dynamic> D(K);
58 D.diagonal() = sds.inverse();
59 lp += lkj_corr_lpdf<propto, T_y, T_shape>(D * y * D, eta);
63 template <
typename T_y,
typename T_loc,
typename T_scale,
typename T_shape>
66 boost::math::tools::promote_args<T_y, T_loc, T_scale, T_shape>::type
67 lkj_cov_lpdf(
const Eigen::Matrix<T_y, Eigen::Dynamic, Eigen::Dynamic>& y,
68 const Eigen::Matrix<T_loc, Eigen::Dynamic, 1>& mu,
69 const Eigen::Matrix<T_scale, Eigen::Dynamic, 1>& sigma,
71 return lkj_cov_lpdf<false>(y, mu, sigma, eta);
76 template <
bool propto,
77 typename T_y,
typename T_loc,
typename T_scale,
typename T_shape>
79 boost::math::tools::promote_args<T_y, T_loc, T_scale, T_shape>::type
80 lkj_cov_lpdf(
const Eigen::Matrix<T_y, Eigen::Dynamic, Eigen::Dynamic>& y,
84 static const char*
function(
"lkj_cov_lpdf");
86 using boost::math::tools::promote_args;
88 typename promote_args<T_y, T_loc, T_scale, T_shape>::type lp(0.0);
93 const unsigned int K = y.rows();
94 const Eigen::Array<T_y, Eigen::Dynamic, 1> sds
95 = y.diagonal().array().sqrt();
96 for (
unsigned int k = 0; k < K; k++) {
97 lp += lognormal_lpdf<propto>(sds(k), mu, sigma);
102 lp += lkj_corr_lpdf<propto>(y, eta);
105 Eigen::DiagonalMatrix<T_y, Eigen::Dynamic> D(K);
106 D.diagonal() = sds.inverse();
107 lp += lkj_corr_lpdf<propto, T_y, T_shape>(D * y * D, eta);
111 template <
typename T_y,
typename T_loc,
typename T_scale,
typename T_shape>
113 typename boost::math::tools::promote_args
114 <T_y, T_loc, T_scale, T_shape>::type
115 lkj_cov_lpdf(
const Eigen::Matrix<T_y, Eigen::Dynamic, Eigen::Dynamic>& y,
117 const T_scale& sigma,
118 const T_shape& eta) {
119 return lkj_cov_lpdf<false>(y, mu, sigma, eta);
Metaprogramming struct to detect whether a given type is constant in the mathematical sense (not the ...
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)
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_square(const char *function, const char *name, const Eigen::Matrix< T_y, Eigen::Dynamic, Eigen::Dynamic > &y)
Check if the specified matrix is square.
void check_positive(const char *function, const char *name, const T_y &y)
Check if y is positive.