1 #ifndef STAN_MATH_PRIM_MAT_PROB_MULTI_NORMAL_CHOLESKY_RNG_HPP 2 #define STAN_MATH_PRIM_MAT_PROB_MULTI_NORMAL_CHOLESKY_RNG_HPP 7 #include <boost/random/normal_distribution.hpp> 8 #include <boost/random/variate_generator.hpp> 29 template <
typename T_loc,
class RNG>
33 const Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic>& L, RNG& rng) {
34 using boost::normal_distribution;
35 using boost::variate_generator;
37 static const char*
function =
"multi_normal_cholesky_rng";
39 size_t size_mu = mu_vec[0].size();
42 int size_mu_old = size_mu;
43 for (
size_t i = 1; i < N; i++) {
44 int size_mu_new = mu_vec[i].size();
46 "Size of one of the vectors of " 47 "the location variable",
49 "Size of another vector of the " 52 size_mu_old = size_mu_new;
55 for (
size_t i = 0; i < N; i++) {
61 variate_generator<RNG&, normal_distribution<> > std_normal_rng(
62 rng, normal_distribution<>(0, 1));
64 for (
size_t n = 0; n < N; ++n) {
65 Eigen::VectorXd z(L.cols());
66 for (
int i = 0; i < L.cols(); i++)
67 z(i) = std_normal_rng();
69 output[n] = Eigen::VectorXd(mu_vec[n]) + L * z;
void check_finite(const char *function, const char *name, const T_y &y)
Check if y is finite.
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< true, Eigen::VectorXd, T_loc >::type multi_normal_cholesky_rng(const T_loc &mu, const Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > &L, RNG &rng)
Return a multivariate normal random variate with the given location and Cholesky factorization of the...
StdVectorBuilder allocates type T1 values to be used as intermediate values.
This class provides a low-cost wrapper for situations where you either need an Eigen Vector or RowVec...
size_t length_mvt(const Eigen::Matrix< T, R, C > &)