1 #ifndef STAN__PROB__DISTRIBUTIONS__MULTIVARIATE__CONTINUOUS__MULTI_NORMAL_PREC_HPP
2 #define STAN__PROB__DISTRIBUTIONS__MULTIVARIATE__CONTINUOUS__MULTI_NORMAL_PREC_HPP
31 template <
bool propto,
32 typename T_y,
typename T_loc,
typename T_covar>
33 typename boost::math::tools::promote_args<typename scalar_type<T_y>::type,
typename scalar_type<T_loc>::type, T_covar>::type
36 const Eigen::Matrix<T_covar,Eigen::Dynamic,Eigen::Dynamic>& Sigma) {
37 static const char*
function =
"stan::prob::multi_normal_prec_log(%1%)";
38 typedef typename boost::math::tools::promote_args<typename scalar_type<T_y>::type,
typename scalar_type<T_loc>::type, T_covar>::type lp_type;
53 Sigma.rows(),
"Rows of precision parameter",
54 Sigma.cols(),
"columns of precision parameter",
56 check_positive(
function, Sigma.rows(),
"Precision matrix rows", &lp);
59 LDLT_factor<T_covar,Eigen::Dynamic,Eigen::Dynamic> ldlt_Sigma(Sigma);
61 "LDLT_Factor of precision parameter",&lp);
73 int size_y = y_vec[0].size();
74 int size_mu = mu_vec[0].size();
76 int size_y_old = size_y;
79 int size_y_new = y_vec[i].size();
81 size_y_new,
"Size of one of the vectors of the random variable",
82 size_y_old,
"Size of another vector of the random variable",
84 size_y_old = size_y_new;
86 int size_mu_old = size_mu;
89 int size_mu_new = mu_vec[i].size();
91 size_mu_new,
"Size of one of the vectors of the location variable",
92 size_mu_old,
"Size of another vector of the location variable",
94 size_mu_old = size_mu_new;
103 size_y,
"Size of random variable",
104 size_mu,
"size of location parameter",
107 size_y,
"Size of random variable",
108 Sigma.rows(),
"rows of covariance parameter",
111 size_y,
"Size of random variable",
112 Sigma.cols(),
"columns of covariance parameter",
115 for (
size_t i = 0; i < size_vec; i++) {
116 check_finite(
function, mu_vec[i],
"Location parameter", &lp);
127 lp += NEG_LOG_SQRT_TWO_PI * size_y * size_vec;
130 lp_type sum_lp_vec(0.0);
131 for (
size_t i = 0; i < size_vec; i++) {
133 boost::math::tools::promote_args<typename scalar_type<T_y>::type,
typename scalar_type<T_loc>::type>::type,
134 Dynamic, 1> y_minus_mu(size_y);
135 for (
int j = 0; j < size_y; j++)
136 y_minus_mu(j) = y_vec[i](j)-mu_vec[i](j);
139 lp -= 0.5*sum_lp_vec;
144 template <
typename T_y,
typename T_loc,
typename T_covar>
146 typename boost::math::tools::promote_args<typename scalar_type<T_y>::type,
typename scalar_type<T_loc>::type, T_covar>::type
149 const Eigen::Matrix<T_covar,Eigen::Dynamic,Eigen::Dynamic>& Sigma) {
150 return multi_normal_prec_log<false>(y,mu,Sigma);
size_t max_size_mvt(const T1 &x1, const T2 &x2)
boost::math::tools::promote_args< typename scalar_type< T_y >::type, typename scalar_type< T_loc >::type, T_covar >::type multi_normal_prec_log(const T_y &y, const T_loc &mu, const Eigen::Matrix< T_covar, Eigen::Dynamic, Eigen::Dynamic > &Sigma)
bool check_size_match(const char *function, T_size1 i, const char *name_i, T_size2 j, const char *name_j, T_result *result)
bool check_finite(const char *function, const T_y &y, const char *name, T_result *result)
Checks if the variable y is finite.
scalar_type_helper< is_vector< T >::value, T >::type type
stan::agrad::fvar< T > trace_quad_form(const Eigen::Matrix< stan::agrad::fvar< T >, RA, CA > &A, const Eigen::Matrix< stan::agrad::fvar< T >, RB, CB > &B)
bool check_symmetric(const char *function, const Eigen::Matrix< T_y, Eigen::Dynamic, Eigen::Dynamic > &y, const char *name, T_result *result)
Return true if the specified matrix is symmetric.
bool check_ldlt_factor(const char *function, stan::math::LDLT_factor< T, R, C > &A, const char *name, T_result *result)
Return true if the underlying matrix is positive definite.
Template metaprogram to calculate whether a summand needs to be included in a proportional (log) prob...
double trace_quad_form(const Eigen::Matrix< double, RA, CA > &A, const Eigen::Matrix< double, RB, CB > &B)
Compute trace(B^T A B).
size_t length_mvt(const T &)
bool check_positive(const char *function, const T_y &y, const char *name, T_result *result)
double sum(std::vector< double > &x)
bool check_not_nan(const char *function, const T_y &y, const char *name, T_result *result)
Checks if the variable y is nan.
var log_determinant_ldlt(stan::math::LDLT_factor< var, R, C > &A)
T log_determinant_ldlt(stan::math::LDLT_factor< T, R, C > &A)