2
2
#include < gtest/gtest.h>
3
3
4
4
TEST (ProbDistributionsGaussianCopulaCholesky, EqualsMultiNormalCholesky) {
5
+ using stan::math::diag_pre_multiply;
5
6
using stan::math::gaussian_copula_cholesky_lpdf;
6
7
using stan::math::multi_normal_cholesky_lpdf;
7
- using stan::math::diag_pre_multiply;
8
8
9
9
Eigen::VectorXd y (2 );
10
10
y << 1 , 3 ;
@@ -22,25 +22,19 @@ TEST(ProbDistributionsGaussianCopulaCholesky, EqualsMultiNormalCholesky) {
22
22
return stan::math::normal_lcdf (y, mu, sigma);
23
23
};
24
24
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); };
28
26
29
27
// y[0] ~ normal(0.1, 2)
30
28
// 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));
40
31
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);
41
35
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));
44
38
45
39
EXPECT_FLOAT_EQ (log_prob, expected_log_prob);
46
40
}
@@ -62,15 +56,13 @@ TEST(ProbDistributionsGaussianCopulaCholesky, NonNormalMarginals) {
62
56
63
57
// y[0] ~ gamma(2, 1)
64
58
// 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 ));
69
61
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);
74
66
75
67
EXPECT_FLOAT_EQ (log_prob, -16.61005941 );
76
68
}
@@ -92,32 +84,25 @@ TEST(ProbDistributionsGaussianCopulaCholesky, Errors) {
92
84
return stan::math::exponential_lcdf (y, scale);
93
85
};
94
86
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 ));
99
89
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 ));
103
92
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 ; }));
108
96
109
97
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);
113
100
114
101
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);
118
104
119
105
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);
123
108
}
0 commit comments