1 #ifndef STAN_MATH_PRIM_MAT_PROB_MULTI_STUDENT_T_RNG_HPP 2 #define STAN_MATH_PRIM_MAT_PROB_MULTI_STUDENT_T_RNG_HPP 10 #include <boost/random/normal_distribution.hpp> 11 #include <boost/random/gamma_distribution.hpp> 12 #include <boost/random/variate_generator.hpp> 35 template <
typename T_loc,
class RNG>
38 double nu,
const T_loc& mu,
39 const Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic>& S, RNG& rng) {
40 using boost::normal_distribution;
41 using boost::random::gamma_distribution;
42 using boost::variate_generator;
44 static const char*
function =
"multi_student_t_rng";
50 Eigen::LLT<Eigen::MatrixXd> llt_of_S = S.llt();
54 size_t size_mu = mu_vec[0].size();
57 int size_mu_old = size_mu;
58 for (
size_t i = 1; i < N; i++) {
59 int size_mu_new = mu_vec[i].size();
61 "Size of one of the vectors of " 62 "the location variable",
64 "Size of another vector of the " 67 size_mu_old = size_mu_new;
70 for (
size_t i = 0; i < N; i++) {
76 variate_generator<RNG&, normal_distribution<> > std_normal_rng(
77 rng, normal_distribution<>(0, 1));
78 variate_generator<RNG&, gamma_distribution<> >
gamma_rng(
79 rng, gamma_distribution<>(nu / 2.0, 2.0 / nu));
82 for (
size_t n = 0; n < N; ++n) {
83 Eigen::VectorXd z(S.cols());
84 for (
int i = 0; i < S.cols(); i++)
87 output[n] = Eigen::VectorXd(mu_vec[n]) + llt_of_S.matrixL() * z;
void check_finite(const char *function, const char *name, const T_y &y)
Check if y is finite.
fvar< T > sqrt(const fvar< T > &x)
void check_size_match(const char *function, const char *name_i, T_size1 i, const char *name_j, T_size2 j)
Check if the provided sizes match.
StdVectorBuilder allocates type T1 values to be used as intermediate values.
void check_not_nan(const char *function, const char *name, const T_y &y)
Check if y is not NaN.
VectorBuilder< true, double, T_shape, T_inv >::type gamma_rng(const T_shape &alpha, const T_inv &beta, RNG &rng)
Return a gamma random variate for the given shape and inverse scale parameters using the specified ra...
This class provides a low-cost wrapper for situations where you either need an Eigen Vector or RowVec...
void check_positive(const char *function, const char *name, const T_y &y)
Check if y is positive.
StdVectorBuilder< true, Eigen::VectorXd, T_loc >::type multi_student_t_rng(double nu, const T_loc &mu, const Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > &S, RNG &rng)
Return a multivariate student-t random variate with the given degrees of freedom location and covaria...
void check_pos_definite(const char *function, const char *name, const Eigen::Matrix< T_y, -1, -1 > &y)
Check if the specified square, symmetric matrix is positive definite.
void check_symmetric(const char *function, const char *name, const matrix_cl &y)
Check if the matrix_cl is symmetric.
size_t length_mvt(const Eigen::Matrix< T, R, C > &)