@@ -118,25 +118,23 @@ TEST(ProbDistributionsInvWishartCholesky, compareToInvWishart) {
118
118
using Eigen::MatrixXd;
119
119
using Eigen::VectorXd;
120
120
using stan::math::inv_wishart_cholesky_rng;
121
- using stan::math::multi_normal_rng;
122
121
using stan::math::inv_wishart_rng;
123
- using stan::math::lkj_corr_cholesky_rng;
124
- using stan::math::qr_thin_R;
125
122
using stan::math::multiply_lower_tri_self_transpose;
123
+ using stan::math::qr_thin_Q;
126
124
127
125
boost::random::mt19937 rng (92343U );
128
126
int N = 1e5 ;
129
- double tol = 0.1 ;
127
+ double tol = 0.05 ;
130
128
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);
133
132
MatrixXd Z_mean = sigma / (k + 3 );
134
133
MatrixXd Z_est = MatrixXd::Zero (k, k);
135
134
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) );
137
136
}
138
137
Z_est /= N;
139
- Z_est = multiply_lower_tri_self_transpose (Z_est);
140
138
for (int j = 0 ; j < k; j++) {
141
139
for (int i = 0 ; i < j; i++) {
142
140
EXPECT_NEAR (Z_est (i, j), Z_mean (i, j), tol);
0 commit comments