1 #ifndef STAN_MATH_PRIM_MAT_PROB_MULTI_NORMAL_CHOLESKY_LOG_HPP
2 #define STAN_MATH_PRIM_MAT_PROB_MULTI_NORMAL_CHOLESKY_LOG_HPP
22 #include <boost/random/normal_distribution.hpp>
23 #include <boost/random/variate_generator.hpp>
44 template <
bool propto,
45 typename T_y,
typename T_loc,
typename T_covar>
46 typename return_type<T_y, T_loc, T_covar>::type
50 static const char*
function(
"stan::math::multi_normal_cholesky_log");
71 int size_y = y_vec[0].size();
72 int size_mu = mu_vec[0].size();
74 int size_y_old = size_y;
77 int size_y_new = y_vec[i].size();
79 "Size of one of the vectors of "
80 "the random variable", size_y_new,
81 "Size of another vector of the "
82 "random variable", size_y_old);
83 size_y_old = size_y_new;
85 int size_mu_old = size_mu;
88 int size_mu_new = mu_vec[i].size();
90 "Size of one of the vectors of "
91 "the location variable", size_mu_new,
92 "Size of another vector of the "
93 "location variable", size_mu_old);
94 size_mu_old = size_mu_new;
103 "Size of random variable", size_y,
104 "size of location parameter", size_mu);
106 "Size of random variable", size_y,
107 "rows of covariance parameter", L.rows());
109 "Size of random variable", size_y,
110 "columns of covariance parameter", L.cols());
112 for (
size_t i = 0; i < size_vec; i++) {
113 check_finite(
function,
"Location parameter", mu_vec[i]);
124 lp -= L.diagonal().array().log().sum() * size_vec;
127 lp_type sum_lp_vec(0.0);
128 for (
size_t i = 0; i < size_vec; i++) {
129 Eigen::Matrix<typename return_type<T_y, T_loc>::type,
130 Eigen::Dynamic, 1> y_minus_mu(size_y);
131 for (
int j = 0; j < size_y; j++)
132 y_minus_mu(j) = y_vec[i](j)-mu_vec[i](j);
133 Eigen::Matrix<typename return_type<T_y, T_loc, T_covar>::type,
145 lp -= 0.5*sum_lp_vec;
150 template <
typename T_y,
typename T_loc,
typename T_covar>
154 return multi_normal_cholesky_log<false>(y, mu, L);
fvar< T > sum(const std::vector< fvar< T > > &m)
Return the sum of the entries of the specified standard vector.
size_t max_size_mvt(const T1 &x1, const T2 &x2)
bool check_not_nan(const char *function, const char *name, const T_y &y)
Return true if y is not NaN.
Eigen::Matrix< typename boost::math::tools::promote_args< T1, T2 >::type, R, C > subtract(const Eigen::Matrix< T1, R, C > &m1, const Eigen::Matrix< T2, R, C > &m2)
Return the result of subtracting the second specified matrix from the first specified matrix...
Eigen::Matrix< fvar< T >, R1, C1 > multiply(const Eigen::Matrix< fvar< T >, R1, C1 > &m, const fvar< T > &c)
scalar_type_helper< is_vector< T >::value, T >::type type
fvar< T > dot_self(const Eigen::Matrix< fvar< T >, R, C > &v)
Template metaprogram to calculate whether a summand needs to be included in a proportional (log) prob...
boost::math::tools::promote_args< typename scalar_type< T1 >::type, typename scalar_type< T2 >::type, typename scalar_type< T3 >::type, typename scalar_type< T4 >::type, typename scalar_type< T5 >::type, typename scalar_type< T6 >::type >::type type
return_type< T_y, T_loc, T_covar >::type multi_normal_cholesky_log(const T_y &y, const T_loc &mu, const T_covar &L)
The log of the multivariate normal density for the given y, mu, and a Cholesky factor L of the varian...
bool check_size_match(const char *function, const char *name_i, T_size1 i, const char *name_j, T_size2 j)
Return true if the provided sizes match.
const double NEG_LOG_SQRT_TWO_PI
bool check_finite(const char *function, const char *name, const T_y &y)
Return true if y is finite.
Eigen::Matrix< fvar< T >, R1, C1 > mdivide_left_tri_low(const Eigen::Matrix< fvar< T >, R1, C1 > &A, const Eigen::Matrix< fvar< T >, R2, C2 > &b)
size_t length_mvt(const Eigen::Matrix< T, R, C > &)