Skip to content

Commit

Permalink
Merge branch 'fix-inv-wishart-cholesky-rng' of https://github.com/sta…
Browse files Browse the repository at this point in the history
…n-dev/math into fix-inv-wishart-cholesky-rng
  • Loading branch information
spinkney committed Dec 7, 2023
2 parents 428bd15 + 80168bb commit 42f7a80
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
6 changes: 3 additions & 3 deletions stan/math/prim/prob/inv_wishart_cholesky_rng.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ namespace math {
* from the inverse Wishart distribution with the specified degrees of freedom
* using the specified random number generator.
*
* Axen, Seth D. "Efficiently generating inverse-Wishart matrices and their Cholesky factors."
* arXiv preprint arXiv:2310.15884 (2023).
*
* Axen, Seth D. "Efficiently generating inverse-Wishart matrices and their
* Cholesky factors." arXiv preprint arXiv:2310.15884 (2023).
*
* @tparam RNG Random number generator type
* @param[in] nu scalar degrees of freedom
* @param[in] L_S lower Cholesky factor of the scale matrix
Expand Down
10 changes: 6 additions & 4 deletions test/unit/math/prim/prob/inv_wishart_cholesky_rng_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ TEST(ProbDistributionsInvWishartCholesky, SpecialRNGTest) {
MatrixXd L = MatrixXd::Identity(k, k);
MatrixXd Z = MatrixXd::Zero(k, k);
for (int i = 0; i < N; i++) {
Z += multiply_lower_tri_self_transpose(inv_wishart_cholesky_rng(k + 2, L, rng));
Z += multiply_lower_tri_self_transpose(
inv_wishart_cholesky_rng(k + 2, L, rng));
}
Z /= N;
for (int j = 0; j < k; j++) {
Expand All @@ -113,7 +114,7 @@ TEST(ProbDistributionsInvWishartCholesky, SpecialRNGTest) {
}

TEST(ProbDistributionsInvWishartCholesky, compareToInvWishart) {
// Compare the marginal mean
// Compare the marginal mean

using Eigen::MatrixXd;
using Eigen::VectorXd;
Expand All @@ -132,12 +133,13 @@ TEST(ProbDistributionsInvWishartCholesky, compareToInvWishart) {
MatrixXd Z_mean = sigma / (k + 3);
MatrixXd Z_est = MatrixXd::Zero(k, k);
for (int i = 0; i < N; i++) {
Z_est += multiply_lower_tri_self_transpose(inv_wishart_cholesky_rng(k + 4, L, rng));
Z_est += multiply_lower_tri_self_transpose(
inv_wishart_cholesky_rng(k + 4, L, rng));
}
Z_est /= N;
for (int j = 0; j < k; j++) {
for (int i = 0; i < j; i++) {
EXPECT_NEAR(Z_est(i, j), Z_mean(i, j), tol);
EXPECT_NEAR(Z_est(i, j), Z_mean(i, j), tol);
}
}
}
Expand Down

0 comments on commit 42f7a80

Please sign in to comment.