22#include < gtest/gtest.h>
33
44TEST (ProbDistributionsGaussianCopulaCholesky, EqualsMultiNormalCholesky) {
5+ using stan::math::diag_pre_multiply;
56 using stan::math::gaussian_copula_cholesky_lpdf;
67 using stan::math::multi_normal_cholesky_lpdf;
7- using stan::math::diag_pre_multiply;
88
99 Eigen::VectorXd y (2 );
1010 y << 1 , 3 ;
@@ -22,25 +22,19 @@ TEST(ProbDistributionsGaussianCopulaCholesky, EqualsMultiNormalCholesky) {
2222 return stan::math::normal_lcdf (y, mu, sigma);
2323 };
2424
25- auto std_norm_lcdf = [](auto && y) {
26- return stan::math::std_normal_lcdf (y);
27- };
25+ auto std_norm_lcdf = [](auto && y) { return stan::math::std_normal_lcdf (y); };
2826
2927 // y[0] ~ normal(0.1, 2)
3028 // y[1] ~ normal(0, 1)
31- auto lcdf_functors = std::make_tuple (
32- std::make_tuple (norm_lcdf, mu[0 ], sd[0 ]),
33- std::make_tuple (std_norm_lcdf)
34- );
35-
36- double log_prob =
37- stan::math::normal_lpdf (y[0 ], 0.1 , 2 ) +
38- stan::math::std_normal_lpdf (y[1 ]) +
39- gaussian_copula_cholesky_lpdf (y, lcdf_functors, chol);
29+ auto lcdf_functors = std::make_tuple (std::make_tuple (norm_lcdf, mu[0 ], sd[0 ]),
30+ std::make_tuple (std_norm_lcdf));
4031
32+ double log_prob = stan::math::normal_lpdf (y[0 ], 0.1 , 2 )
33+ + stan::math::std_normal_lpdf (y[1 ])
34+ + gaussian_copula_cholesky_lpdf (y, lcdf_functors, chol);
4135
42- double expected_log_prob = multi_normal_cholesky_lpdf (
43- y, mu, diag_pre_multiply (sd, chol));
36+ double expected_log_prob
37+ = multi_normal_cholesky_lpdf ( y, mu, diag_pre_multiply (sd, chol));
4438
4539 EXPECT_FLOAT_EQ (log_prob, expected_log_prob);
4640}
@@ -62,15 +56,13 @@ TEST(ProbDistributionsGaussianCopulaCholesky, NonNormalMarginals) {
6256
6357 // y[0] ~ gamma(2, 1)
6458 // y[1] ~ exponential(2)
65- auto lcdf_functors = std::make_tuple (
66- std::make_tuple (gamma_lcdf, 2.0 , 1.0 ),
67- std::make_tuple (exp_lcdf, 2.0 )
68- );
59+ auto lcdf_functors = std::make_tuple (std::make_tuple (gamma_lcdf, 2.0 , 1.0 ),
60+ std::make_tuple (exp_lcdf, 2.0 ));
6961
70- double log_prob =
71- stan::math::gamma_lpdf (y[0 ], 2.0 , 1.0 ) +
72- stan::math::exponential_lpdf (y[1 ], 2.0 ) +
73- stan::math::gaussian_copula_cholesky_lpdf (y, lcdf_functors, chol);
62+ double log_prob
63+ = stan::math::gamma_lpdf (y[0 ], 2.0 , 1.0 )
64+ + stan::math::exponential_lpdf (y[1 ], 2.0 )
65+ + stan::math::gaussian_copula_cholesky_lpdf (y, lcdf_functors, chol);
7466
7567 EXPECT_FLOAT_EQ (log_prob, -16.61005941 );
7668}
@@ -92,32 +84,25 @@ TEST(ProbDistributionsGaussianCopulaCholesky, Errors) {
9284 return stan::math::exponential_lcdf (y, scale);
9385 };
9486
95- auto lcdf_functors = std::make_tuple (
96- std::make_tuple (gamma_lcdf, 2.0 , 1.0 ),
97- std::make_tuple (exp_lcdf, 2.0 )
98- );
87+ auto lcdf_functors = std::make_tuple (std::make_tuple (gamma_lcdf, 2.0 , 1.0 ),
88+ std::make_tuple (exp_lcdf, 2.0 ));
9989
100- auto small_lcdf_functors = std::make_tuple (
101- std::make_tuple (gamma_lcdf, 2.0 , 1.0 )
102- );
90+ auto small_lcdf_functors
91+ = std::make_tuple (std::make_tuple (gamma_lcdf, 2.0 , 1.0 ));
10392
104- auto invalid_lcdf_functors = std::make_tuple (
105- std::make_tuple (gamma_lcdf, 2.0 , 1.0 ),
106- std::make_tuple ([](auto && y){ return y * 10 ; })
107- );
93+ auto invalid_lcdf_functors
94+ = std::make_tuple (std::make_tuple (gamma_lcdf, 2.0 , 1.0 ),
95+ std::make_tuple ([](auto && y) { return y * 10 ; }));
10896
10997 EXPECT_THROW (
110- stan::math::gaussian_copula_cholesky_lpdf (y, small_lcdf_functors, chol),
111- std::invalid_argument
112- );
98+ stan::math::gaussian_copula_cholesky_lpdf (y, small_lcdf_functors, chol),
99+ std::invalid_argument);
113100
114101 EXPECT_THROW (
115- stan::math::gaussian_copula_cholesky_lpdf (small_y, lcdf_functors, chol),
116- std::invalid_argument
117- );
102+ stan::math::gaussian_copula_cholesky_lpdf (small_y, lcdf_functors, chol),
103+ std::invalid_argument);
118104
119105 EXPECT_THROW (
120- stan::math::gaussian_copula_cholesky_lpdf (y, invalid_lcdf_functors, chol),
121- std::domain_error
122- );
106+ stan::math::gaussian_copula_cholesky_lpdf (y, invalid_lcdf_functors, chol),
107+ std::domain_error);
123108}
0 commit comments