1 #ifndef STAN_MATH_PRIM_MAT_PROB_MULTI_STUDENT_T_LOG_HPP
2 #define STAN_MATH_PRIM_MAT_PROB_MULTI_STUDENT_T_LOG_HPP
4 #include <boost/math/special_functions/gamma.hpp>
5 #include <boost/math/special_functions/fpclassify.hpp>
6 #include <boost/random/variate_generator.hpp>
34 template <
bool propto,
35 typename T_y,
typename T_dof,
typename T_loc,
typename T_scale>
36 typename return_type<T_y, T_dof, T_loc, T_scale>::type
40 const T_scale& Sigma) {
41 static const char*
function(
"stan::math::multi_student_t");
77 int size_y = y_vec[0].size();
78 int size_mu = mu_vec[0].size();
80 int size_y_old = size_y;
83 int size_y_new = y_vec[i].size();
85 "Size of one of the vectors of the random variable",
87 "Size of another vector of the random variable",
89 size_y_old = size_y_new;
91 int size_mu_old = size_mu;
94 int size_mu_new = mu_vec[i].size();
96 "Size of one of the vectors "
97 "of the location variable",
99 "Size of another vector of "
100 "the location variable",
102 size_mu_old = size_mu_new;
112 "Size of random variable", size_y,
113 "size of location parameter", size_mu);
115 "Size of random variable", size_y,
116 "rows of scale parameter", Sigma.rows());
118 "Size of random variable", size_y,
119 "columns of scale parameter", Sigma.cols());
121 for (
size_t i = 0; i < size_vec; i++) {
122 check_finite(
function,
"Location parameter", mu_vec[i]);
135 lp +=
lgamma(0.5 * (nu + size_y)) * size_vec;
136 lp -=
lgamma(0.5 * nu) * size_vec;
137 lp -= (0.5 * size_y) *
log(nu) * size_vec;
141 lp -= (0.5 * size_y) *
LOG_PI * size_vec;
154 lp_type sum_lp_vec(0.0);
155 for (
size_t i = 0; i < size_vec; i++) {
156 Eigen::Matrix<typename return_type<T_y, T_loc>::type, Dynamic, 1>
158 for (
int j = 0; j < size_y; j++)
159 y_minus_mu(j) = y_vec[i](j)-mu_vec[i](j);
163 lp -= 0.5 * (nu + size_y) * sum_lp_vec;
168 template <
typename T_y,
typename T_dof,
typename T_loc,
typename T_scale>
172 const T_scale& Sigma) {
173 return multi_student_t_log<false>(y, nu, mu, Sigma);
int isinf(const stan::math::var &a)
Checks if the given number is infinite.
fvar< T > lgamma(const fvar< T > &x)
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...
fvar< T > log(const fvar< T > &x)
Eigen::Matrix< fvar< T >, R1, C1 > multiply(const Eigen::Matrix< fvar< T >, R1, C1 > &m, const fvar< T > &c)
bool check_symmetric(const char *function, const char *name, const Eigen::Matrix< T_y, Dynamic, Dynamic > &y)
Return true if the specified matrix is symmetric.
scalar_type_helper< is_vector< T >::value, T >::type type
boost::enable_if_c<!stan::is_var< T1 >::value &&!stan::is_var< T2 >::value, typename boost::math::tools::promote_args< T1, T2 >::type >::type trace_inv_quad_form_ldlt(const stan::math::LDLT_factor< T1, R2, C2 > &A, const Eigen::Matrix< T2, R3, C3 > &B)
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
bool isinf(const stan::math::var &v)
Checks if the given number is infinite.
return_type< T_y, T_dof, T_loc, T_scale >::type multi_student_t_log(const T_y &y, const T_dof &nu, const T_loc &mu, const T_scale &Sigma)
Return the log of the multivariate Student t distribution at the specified arguments.
bool check_positive(const char *function, const char *name, const T_y &y)
Return true if y is positive.
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.
size_t length_mvt(const T &)
fvar< T > dot_product(const Eigen::Matrix< fvar< T >, R1, C1 > &v1, const Eigen::Matrix< fvar< T >, R2, C2 > &v2)
return_type< T_y, T_loc, T_covar >::type multi_normal_log(const T_y &y, const T_loc &mu, const T_covar &Sigma)
bool check_finite(const char *function, const char *name, const T_y &y)
Return true if y is finite.
fvar< T > log1p(const fvar< T > &x)
T log_determinant_ldlt(stan::math::LDLT_factor< T, R, C > &A)
bool check_ldlt_factor(const char *function, const char *name, stan::math::LDLT_factor< T, R, C > &A)
Return true if the argument is a valid stan::math::LDLT_factor.