@@ -91,14 +91,15 @@ TEST(ProbDistributionsInvWishartCholesky, SpecialRNGTest) {
9191  using  stan::math::inv_wishart_cholesky_rng;
9292  using  stan::math::multiply_lower_tri_self_transpose;
9393
94-   boost::random::mt19937 rng (1234U );
94+   boost::random::mt19937 rng (92343U );
9595  int  N = 1e5 ;
9696  double  tol = 0.1 ;
9797  for  (int  k = 1 ; k < 5 ; k++) {
98-     MatrixXd sigma  = MatrixXd::Identity (k, k);
98+     MatrixXd L  = MatrixXd::Identity (k, k);
9999    MatrixXd Z = MatrixXd::Zero (k, k);
100100    for  (int  i = 0 ; i < N; i++) {
101-       Z += stan::math::crossprod (inv_wishart_cholesky_rng (k + 2 , sigma, rng));
101+       Z += multiply_lower_tri_self_transpose (
102+           inv_wishart_cholesky_rng (k + 2 , L, rng));
102103    }
103104    Z /= N;
104105    for  (int  j = 0 ; j < k; j++) {
@@ -111,3 +112,35 @@ TEST(ProbDistributionsInvWishartCholesky, SpecialRNGTest) {
111112    }
112113  }
113114}
115+ 
116+ TEST (ProbDistributionsInvWishartCholesky, compareToInvWishart) {
117+   //  Compare the marginal mean
118+ 
119+   using  Eigen::MatrixXd;
120+   using  Eigen::VectorXd;
121+   using  stan::math::inv_wishart_cholesky_rng;
122+   using  stan::math::inv_wishart_rng;
123+   using  stan::math::multiply_lower_tri_self_transpose;
124+   using  stan::math::qr_thin_Q;
125+ 
126+   boost::random::mt19937 rng (92343U );
127+   int  N = 1e5 ;
128+   double  tol = 0.05 ;
129+   for  (int  k = 1 ; k < 5 ; k++) {
130+     MatrixXd L = qr_thin_Q (MatrixXd::Random (k, k)).transpose ();
131+     L.diagonal () = stan::math::abs (L.diagonal ());
132+     MatrixXd sigma = multiply_lower_tri_self_transpose (L);
133+     MatrixXd Z_mean = sigma / (k + 3 );
134+     MatrixXd Z_est = MatrixXd::Zero (k, k);
135+     for  (int  i = 0 ; i < N; i++) {
136+       Z_est += multiply_lower_tri_self_transpose (
137+           inv_wishart_cholesky_rng (k + 4 , L, rng));
138+     }
139+     Z_est /= N;
140+     for  (int  j = 0 ; j < k; j++) {
141+       for  (int  i = 0 ; i < j; i++) {
142+         EXPECT_NEAR (Z_est (i, j), Z_mean (i, j), tol);
143+       }
144+     }
145+   }
146+ }
0 commit comments