1 #ifndef STAN_MATH_PRIM_MAT_PROB_GAUSSIAN_DLM_OBS_RNG_HPP 2 #define STAN_MATH_PRIM_MAT_PROB_GAUSSIAN_DLM_OBS_RNG_HPP 13 #include <boost/random/normal_distribution.hpp> 14 #include <boost/random/variate_generator.hpp> 36 const Eigen::VectorXd &mu,
const Eigen::LDLT<Eigen::MatrixXd> &S_ldlt,
38 using boost::normal_distribution;
39 using boost::variate_generator;
41 variate_generator<RNG &, normal_distribution<>> std_normal_rng(
42 rng, normal_distribution<>(0, 1));
44 Eigen::VectorXd stddev = S_ldlt.vectorD().array().sqrt().matrix();
45 size_t M = S_ldlt.vectorD().size();
47 for (
int i = 0; i < M; i++)
48 z(i) = stddev(i) * std_normal_rng();
51 = mu + (S_ldlt.transpositionsP().transpose() * (S_ldlt.matrixL() * z));
74 const Eigen::VectorXd &mu,
const Eigen::LLT<Eigen::MatrixXd> &S_llt,
76 using boost::normal_distribution;
77 using boost::variate_generator;
79 variate_generator<RNG &, normal_distribution<>> std_normal_rng(
80 rng, normal_distribution<>(0, 1));
82 size_t M = S_llt.matrixL().rows();
84 for (
int i = 0; i < M; i++)
85 z(i) = std_normal_rng();
87 Eigen::VectorXd Y = mu + S_llt.matrixL() * z;
127 const Eigen::MatrixXd &G,
128 const Eigen::MatrixXd &V,
129 const Eigen::MatrixXd &W,
130 const Eigen::VectorXd &m0,
131 const Eigen::MatrixXd &C0,
132 const int T, RNG &rng) {
133 static const char *
function =
"gaussian_dlm_obs_rng";
159 Eigen::LDLT<Eigen::MatrixXd> V_ldlt = V.ldlt();
161 Eigen::LDLT<Eigen::MatrixXd> W_ldlt = W.ldlt();
164 Eigen::LLT<Eigen::MatrixXd> C0_llt = C0.llt();
167 Eigen::MatrixXd y(r, T);
168 Eigen::VectorXd theta_t
170 for (
int t = 0; t < T; ++t) {
172 Eigen::VectorXd(G * theta_t), W_ldlt, rng);
174 Eigen::VectorXd(F.transpose() * theta_t), V_ldlt, rng);
180 inline Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic>
182 const Eigen::VectorXd &V,
const Eigen::MatrixXd &W,
183 const Eigen::VectorXd &m0,
const Eigen::MatrixXd &C0,
184 const int T, RNG &rng) {
void check_finite(const char *function, const char *name, const T_y &y)
Check if y is finite.
Eigen::MatrixXd gaussian_dlm_obs_rng(const Eigen::MatrixXd &F, const Eigen::MatrixXd &G, const Eigen::MatrixXd &V, const Eigen::MatrixXd &W, const Eigen::VectorXd &m0, const Eigen::MatrixXd &C0, const int T, RNG &rng)
Simulate random draw from Gaussian dynamic linear model (GDLM).
void check_square(const char *function, const char *name, const matrix_cl &y)
Check if the matrix_cl is square.
Eigen::VectorXd multi_normal_definite_rng(const Eigen::VectorXd &mu, const Eigen::LLT< Eigen::MatrixXd > &S_llt, RNG &rng)
Return a multivariate normal random variate with the given location and covariance using the specifie...
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.
void check_pos_semidefinite(const char *function, const char *name, const Eigen::Matrix< T_y, Eigen::Dynamic, Eigen::Dynamic > &y)
Check if the specified matrix is positive definite.
Eigen::VectorXd multi_normal_semidefinite_rng(const Eigen::VectorXd &mu, const Eigen::LDLT< Eigen::MatrixXd > &S_ldlt, RNG &rng)
Return a multivariate normal random variate with the given location and covariance using the specifie...
void check_positive(const char *function, const char *name, const T_y &y)
Check if y is positive.
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.