@@ -118,25 +118,23 @@ TEST(ProbDistributionsInvWishartCholesky, compareToInvWishart) {
118118 using Eigen::MatrixXd;
119119 using Eigen::VectorXd;
120120 using stan::math::inv_wishart_cholesky_rng;
121- using stan::math::multi_normal_rng;
122121 using stan::math::inv_wishart_rng;
123- using stan::math::lkj_corr_cholesky_rng;
124- using stan::math::qr_thin_R;
125122 using stan::math::multiply_lower_tri_self_transpose;
123+ using stan::math::qr_thin_Q;
126124
127125 boost::random::mt19937 rng (92343U );
128126 int N = 1e5 ;
129- double tol = 0.1 ;
127+ double tol = 0.05 ;
130128 for (int k = 1 ; k < 5 ; k++) {
131- MatrixXd sigma = inv_wishart_rng (15 , MatrixXd::Identity (k, k), rng);
132- MatrixXd L = stan::math::cholesky_decompose (sigma);
129+ MatrixXd L = qr_thin_Q (MatrixXd::Random (k, k)).transpose ();
130+ L.diagonal () = stan::math::abs (L.diagonal ());
131+ MatrixXd sigma = multiply_lower_tri_self_transpose (L);
133132 MatrixXd Z_mean = sigma / (k + 3 );
134133 MatrixXd Z_est = MatrixXd::Zero (k, k);
135134 for (int i = 0 ; i < N; i++) {
136- Z_est += inv_wishart_cholesky_rng (k + 4 , L, rng);
135+ Z_est += multiply_lower_tri_self_transpose ( inv_wishart_cholesky_rng (k + 4 , L, rng) );
137136 }
138137 Z_est /= N;
139- Z_est = multiply_lower_tri_self_transpose (Z_est);
140138 for (int j = 0 ; j < k; j++) {
141139 for (int i = 0 ; i < j; i++) {
142140 EXPECT_NEAR (Z_est (i, j), Z_mean (i, j), tol);
0 commit comments