1 #ifndef __STAN__PROB__DISTRIBUTIONS__MULTI_STUDENT_T_HPP__
2 #define __STAN__PROB__DISTRIBUTIONS__MULTI_STUDENT_T_HPP__
23 template <
bool propto,
24 typename T_y,
typename T_dof,
typename T_loc,
typename T_scale,
26 typename boost::math::tools::promote_args<T_y,T_dof,T_loc,T_scale>::type
29 const Eigen::Matrix<T_loc,Eigen::Dynamic,1>& mu,
31 Eigen::Matrix<T_scale,
32 Eigen::Dynamic,Eigen::Dynamic>& Sigma,
34 static const char*
function =
"stan::prob::multi_student_t(%1%)";
41 using boost::math::tools::promote_args;
43 typename promote_args<T_y,T_dof,T_loc,T_scale>::type lp(0.0);
50 if (!
check_finite(
function, mu,
"Location parameter", &lp, Policy()))
52 if (!
check_not_nan(
function, y,
"Random variable", &lp, Policy()))
54 if (!
check_symmetric(
function, Sigma,
"Scale parameter", &lp, Policy()))
59 "Degrees of freedom parameter", &lp,
63 "Degrees of freedom parameter", &lp,
72 Eigen::LLT< Eigen::Matrix<T_scale,Eigen::Dynamic,Eigen::Dynamic> > LLT = Sigma.llt();
73 if (LLT.info() != Eigen::Success) {
74 lp = stan::math::policies::raise_domain_error<T_scale>(
function,
75 "Sigma is not positive definite (%1%)",
79 Eigen::Matrix<T_scale,Eigen::Dynamic,Eigen::Dynamic> L = LLT.matrixL();
84 lp +=
lgamma(0.5 * (nu + d));
86 lp -= (0.5 * d) *
log(nu);
90 lp -= (0.5 * d) * LOG_PI;
100 lp -= L.diagonal().array().log().sum();
106 Eigen::Matrix<typename promote_args<T_y,T_loc>::type,
109 Eigen::Matrix<typename promote_args<T_scale,T_y,T_loc>::type,
111 1> half = L = mdivide_left_tri<Eigen::Lower>(L, y_minus_mu);
119 template <
bool propto,
120 typename T_y,
typename T_dof,
typename T_loc,
typename T_scale>
122 typename boost::math::tools::promote_args<T_y,T_dof,T_loc,T_scale>::type
125 const Eigen::Matrix<T_loc,Eigen::Dynamic,1>& mu,
127 Eigen::Matrix<T_scale,
128 Eigen::Dynamic,Eigen::Dynamic>& Sigma) {
129 return multi_student_t_log<propto>(y,nu,mu,Sigma,
133 template <
typename T_y,
typename T_dof,
typename T_loc,
typename T_scale,
136 typename boost::math::tools::promote_args<T_y,T_dof,T_loc,T_scale>::type
139 const Eigen::Matrix<T_loc,Eigen::Dynamic,1>& mu,
141 Eigen::Matrix<T_scale,
142 Eigen::Dynamic,Eigen::Dynamic>& Sigma,
144 return multi_student_t_log<false>(y,nu,mu,Sigma,Policy());
149 template <
typename T_y,
typename T_dof,
typename T_loc,
typename T_scale>
151 typename boost::math::tools::promote_args<T_y,T_dof,T_loc,T_scale>::type
154 const Eigen::Matrix<T_loc,Eigen::Dynamic,1>& mu,
156 Eigen::Matrix<T_scale,
157 Eigen::Dynamic,Eigen::Dynamic>& Sigma) {
158 return multi_student_t_log<false>(y,nu,mu,Sigma,
var dot_self(const Eigen::Matrix< var, R, C > &v)
Returns the dot product of a vector with itself.
var lgamma(const stan::agrad::var &a)
The log gamma function for variables (C99).
var log(const var &a)
Return the natural log of the specified variable (cmath).
bool check_symmetric(const char *function, const Eigen::Matrix< T_y, Eigen::Dynamic, Eigen::Dynamic > &y, const char *name, T_result *result, const Policy &)
Return true if the specified matrix is symmetric.
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.
bool check_not_nan(const char *function, const T_y &y, const char *name, T_result *result, const Policy &)
Checks if the variable y is nan.
double dot_self(const Eigen::Matrix< double, R, C > &v)
Returns the dot product of the specified vector with itself.
Eigen::Matrix< typename boost::math::tools::promote_args< T1, T2 >::type, R1, C2 > mdivide_left_tri(const Eigen::Matrix< T1, R1, C1 > &A, const Eigen::Matrix< T2, R2, C2 > &b)
Returns the solution of the system Ax=b when A is triangular.
Eigen::Matrix< double, R, C > multiply(const Eigen::Matrix< double, R, C > &m, double c)
Return specified matrix multiplied by specified scalar.
bool check_positive(const char *function, const T_y &y, const char *name, T_result *result, const Policy &)
bool check_finite(const char *function, const T_y &y, const char *name, T_result *result, const Policy &)
Checks if the variable y is finite.
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_loc, T_scale >::type multi_student_t_log(const Eigen::Matrix< T_y, Eigen::Dynamic, 1 > &y, const T_dof &nu, const Eigen::Matrix< T_loc, Eigen::Dynamic, 1 > &mu, const Eigen::Matrix< T_scale, Eigen::Dynamic, Eigen::Dynamic > &Sigma, const Policy &)
Return the log of the multivariate Student t distribution at the specified arguments.
boost::math::tools::promote_args< T_y, T_loc, T_covar >::type multi_normal_log(const Eigen::Matrix< T_y, Eigen::Dynamic, 1 > &y, const Eigen::Matrix< T_loc, Eigen::Dynamic, 1 > &mu, const Eigen::Matrix< T_covar, Eigen::Dynamic, Eigen::Dynamic > &Sigma, const Policy &)
The log of the multivariate normal density for the given y, mu, and variance matrix.
Probability, optimization and sampling library.
int isinf(const stan::agrad::var &a)
Checks if the given number is infinite.
Template metaprogram to calculate whether a summand needs to be included in a proportional (log) prob...