1 #ifndef __STAN__PROB__DISTRIBUTIONS__MULTIVARIATE__CONTINUOUS__WISHART_HPP__
2 #define __STAN__PROB__DISTRIBUTIONS__MULTIVARIATE__CONTINUOUS__WISHART_HPP__
10 #include <boost/concept_check.hpp>
46 template <
bool propto,
47 typename T_y,
typename T_dof,
typename T_scale,
49 typename boost::math::tools::promote_args<T_y,T_dof,T_scale>::type
50 wishart_log(
const Eigen::Matrix<T_y,Eigen::Dynamic,Eigen::Dynamic>& W,
52 const Eigen::Matrix<T_scale,Eigen::Dynamic,Eigen::Dynamic>& S,
54 static const char*
function =
"stan::prob::wishart_log(%1%)";
58 using boost::math::tools::promote_args;
61 typename promote_args<T_y,T_dof,T_scale>::type lp(0.0);
63 "Degrees of freedom parameter", &lp, Policy()))
73 Eigen::LLT< Eigen::Matrix<T_y,Eigen::Dynamic,Eigen::Dynamic> > LLT_W = W.llt();
74 if (LLT_W.info() != Eigen::Success) {
75 lp = stan::math::policies::raise_domain_error<T_y>(
function,
76 "W is not positive definite (%1%)",
80 Eigen::LLT< Eigen::Matrix<T_scale,Eigen::Dynamic,Eigen::Dynamic> > LLT_S = S.llt();
81 if (LLT_S.info() != Eigen::Success) {
82 lp = stan::math::policies::raise_domain_error<T_scale>(
function,
83 "S is not positive definite (%1%)",
88 Eigen::Matrix<T_y,Eigen::Dynamic,Eigen::Dynamic> L_W = LLT_W.matrixL();
89 Eigen::Matrix<T_scale,Eigen::Dynamic,Eigen::Dynamic> L_S = LLT_S.matrixL();
96 lp += nu * k * NEG_LOG_TWO_OVER_TWO;
102 lp -= nu * L_S.diagonal().array().log().sum();
106 Eigen::Matrix<T_scale,Eigen::Dynamic,1> S_inv_vec = Eigen::Map<
107 const Eigen::Matrix<T_scale,Eigen::Dynamic,Eigen::Dynamic> >(
108 &L_S(0), L_S.size(), 1);
109 Eigen::Matrix<T_y,Eigen::Dynamic,1> W_vec = Eigen::Map<
110 const Eigen::Matrix<T_y,Eigen::Dynamic,Eigen::Dynamic> >(
116 lp += (nu - k - 1.0) * L_W.diagonal().array().log().sum();
120 template <
bool propto,
121 typename T_y,
typename T_dof,
typename T_scale>
123 typename boost::math::tools::promote_args<T_y,T_dof,T_scale>::type
124 wishart_log(
const Eigen::Matrix<T_y,Eigen::Dynamic,Eigen::Dynamic>& W,
126 const Eigen::Matrix<T_scale,Eigen::Dynamic,Eigen::Dynamic>& S) {
131 template <
typename T_y,
typename T_dof,
typename T_scale,
134 typename boost::math::tools::promote_args<T_y,T_dof,T_scale>::type
135 wishart_log(
const Eigen::Matrix<T_y,Eigen::Dynamic,Eigen::Dynamic>& W,
137 const Eigen::Matrix<T_scale,Eigen::Dynamic,Eigen::Dynamic>& S,
139 return wishart_log<false>(W,nu,S,Policy());
143 template <
typename T_y,
typename T_dof,
typename T_scale>
145 typename boost::math::tools::promote_args<T_y,T_dof,T_scale>::type
146 wishart_log(
const Eigen::Matrix<T_y,Eigen::Dynamic,Eigen::Dynamic>& W,
148 const Eigen::Matrix<T_scale,Eigen::Dynamic,Eigen::Dynamic>& S) {
internal::traits< Derived >::Index size_type
var dot_product(const Eigen::Matrix< var, R1, C1 > &v1, const Eigen::Matrix< var, R2, C2 > &v2)
Returns the dot product.
matrix_v crossprod(const matrix_v &M)
Returns the result of pre-multiplying a matrix by its own transpose.
Eigen::Matrix< typename boost::math::tools::promote_args< T1, T2 >::type, R1, C2 > mdivide_left_tri_low(const Eigen::Matrix< T1, R1, C1 > &A, const Eigen::Matrix< T2, R2, C2 > &b)
boost::math::tools::promote_args< T >::type lmgamma(unsigned int k, T x)
Return the natural logarithm of the multivariate gamma function with the speciifed dimensions and arg...
bool check_greater_or_equal(const char *function, const T_y &y, const T_low &low, const char *name, T_result *result, const Policy &)
matrix_d crossprod(const matrix_d &M)
Returns the result of pre-multiplying a matrix by its own transpose.
double dot_product(const Eigen::Matrix< double, R1, C1 > &v1, const Eigen::Matrix< double, R2, C2 > &v2)
Returns the dot product of the specified vectors.
boost::math::policies::policy default_policy
Default error-handling policy from Boost.
bool check_size_match(const char *function, T_size1 i, T_size2 j, T_result *result, const Policy &)
boost::math::tools::promote_args< T_y, T_dof, T_scale >::type wishart_log(const Eigen::Matrix< T_y, Eigen::Dynamic, Eigen::Dynamic > &W, const T_dof &nu, const Eigen::Matrix< T_scale, Eigen::Dynamic, Eigen::Dynamic > &S, const Policy &)
The log of the Wishart density for the given W, degrees of freedom, and scale matrix.
Probability, optimization and sampling library.
Template metaprogram to calculate whether a summand needs to be included in a proportional (log) prob...