@@ -20,228 +20,6 @@ struct poisson_log_likelihood2 {
2020 }
2121};
2222
23- template <typename T1, typename T2>
24- auto in_throw_list (T1&& test_values, T2&& test_arr) {
25- for (auto && x : test_values) {
26- if (x[0 ] == test_arr[0 ] && x[1 ] == test_arr[1 ] && x[2 ] == test_arr[2 ]) {
27- return true ;
28- }
29- }
30- return false ;
31- }
32-
33- struct poisson_log_likelihood_tuple {
34- template <typename Theta, typename Eta>
35- auto operator ()(const Theta& theta, const std::vector<int >& delta_int,
36- Eta&& eta, std::ostream* pstream) const {
37- return stan::math::poisson_log_lpmf (delta_int, theta) + std::get<0 >(eta)
38- + std::get<1 >(eta);
39- }
40- };
41-
42- struct poisson_log_likelihood_tuple_expanded {
43- template <typename Theta, typename Eta, typename Eta1, typename Eta2>
44- auto operator ()(const Theta& theta, const std::vector<int >& delta_int,
45- Eta&& eta, Eta1&& eta1, Eta2&& eta2,
46- std::ostream* pstream) const {
47- return stan::math::poisson_log_lpmf (delta_int, theta) + std::get<0 >(eta)
48- + std::get<1 >(eta) + stan::math::sum (eta1) + stan::math::sum (eta2);
49- }
50- };
51-
52- TEST (laplace, poisson_log_phi_dim_2_tuple_extended) {
53- using stan::math::laplace_marginal;
54- using stan::math::laplace_marginal_tol;
55- using stan::math::to_vector;
56- using stan::math::value_of;
57- using stan::math::var;
58- // logger->current_test_name_ = "poisson_log_phi_dim_2";
59- int dim_phi = 2 ;
60- Eigen::Matrix<double , Eigen::Dynamic, 1 > phi_dbl (dim_phi);
61- phi_dbl << 1.6 , 0.45 ;
62-
63- int dim_theta = 2 ;
64- Eigen::VectorXd theta_0 (dim_theta);
65- theta_0 << 0 , 0 ;
66-
67- int dim_x = 2 ;
68- std::vector<Eigen::VectorXd> x (dim_theta);
69- Eigen::VectorXd x_0{{0.05100797 , 0.16086164 }};
70- Eigen::VectorXd x_1{{-0.59823393 , 0.98701425 }};
71- x[0 ] = x_0;
72- x[1 ] = x_1;
73-
74- Eigen::VectorXd y_dummy;
75-
76- std::vector<int > n_samples = {1 , 1 };
77- std::vector<int > sums = {1 , 0 };
78-
79- constexpr double tolerance = 1e-12 ;
80- constexpr int max_num_steps = 100 ;
81- using stan::is_var_v;
82- using stan::scalar_type_t ;
83- using stan::math::test::laplace_issue;
84- constexpr std::array known_issues{laplace_issue{0 , 0 , 0 }};
85- stan::test::ad_tolerances tols;
86- tols.gradient_grad_ = 1e-1 ;
87- stan::math::test::run_solver_grid (
88- [&](int solver_num, int hessian_block_size, int max_steps_line_search,
89- auto && theta_0) {
90- auto f_ll = [&](auto && eta1, auto && eta2, auto && eta3) {
91- auto eta1_tuple = std::make_tuple (eta1 (0 ), eta1 (1 ));
92- return laplace_marginal_tol<false >(
93- poisson_log_likelihood_tuple_expanded{},
94- std::forward_as_tuple (sums, eta1_tuple, eta2, eta3), theta_0,
95- stan::math::test::squared_kernel_functor{},
96- std::forward_as_tuple (x, std::make_tuple (phi_dbl (0 ), phi_dbl (1 ))),
97- tolerance, max_num_steps, hessian_block_size, solver_num,
98- max_steps_line_search, nullptr );
99- };
100- Eigen::VectorXd test1 (phi_dbl);
101- std::vector<double > test2 = {1.0 , 1.0 };
102- stan::test::expect_ad<true >(tols, f_ll, phi_dbl, test1, test2);
103- },
104- theta_0);
105- }
106-
107- TEST (laplace, poisson_log_phi_dim_2_tuple) {
108- using stan::math::laplace_marginal;
109- using stan::math::laplace_marginal_tol;
110- using stan::math::to_vector;
111- using stan::math::value_of;
112- using stan::math::var;
113- // logger->current_test_name_ = "poisson_log_phi_dim_2";
114- int dim_phi = 2 ;
115- Eigen::Matrix<double , Eigen::Dynamic, 1 > phi_dbl (dim_phi);
116- phi_dbl << 1.6 , 0.45 ;
117-
118- int dim_theta = 2 ;
119- Eigen::VectorXd theta_0 (dim_theta);
120- theta_0 << 0 , 0 ;
121-
122- int dim_x = 2 ;
123- std::vector<Eigen::VectorXd> x (dim_theta);
124- Eigen::VectorXd x_0{{0.05100797 , 0.16086164 }};
125- Eigen::VectorXd x_1{{-0.59823393 , 0.98701425 }};
126- x[0 ] = x_0;
127- x[1 ] = x_1;
128-
129- Eigen::VectorXd y_dummy;
130-
131- std::vector<int > n_samples = {1 , 1 };
132- std::vector<int > sums = {1 , 0 };
133-
134- constexpr double tolerance = 1e-12 ;
135- constexpr int max_num_steps = 100 ;
136- using stan::is_var_v;
137- using stan::scalar_type_t ;
138- using stan::math::test::laplace_issue;
139- constexpr std::array known_issues{laplace_issue{0 , 0 , 0 }};
140- stan::test::ad_tolerances tols;
141- tols.gradient_grad_ = 1e-1 ;
142- stan::math::test::run_solver_grid (
143- [&](int solver_num, int hessian_block_size, int max_steps_line_search,
144- auto && theta_0) {
145- auto f_covar = [&](auto && x_v, auto && alpha, auto && rho) {
146- return laplace_marginal_tol<false >(
147- poisson_log_likelihood2{}, std::forward_as_tuple (sums), theta_0,
148- stan::math::test::squared_kernel_functor{},
149- std::forward_as_tuple (x_v, std::make_tuple (alpha, rho)),
150- tolerance, max_num_steps, hessian_block_size, solver_num,
151- max_steps_line_search, nullptr );
152- };
153- stan::test::expect_ad<true >(tols, f_covar, x, phi_dbl[0 ], phi_dbl[1 ]);
154- },
155- theta_0);
156- stan::math::test::run_solver_grid (
157- [&](int solver_num, int hessian_block_size, int max_steps_line_search,
158- auto && theta_0) {
159- auto f_ll = [&](auto && alpha_rho, auto && eta1, auto && eta2) {
160- return laplace_marginal_tol<false >(
161- poisson_log_likelihood_tuple{},
162- std::forward_as_tuple (sums, std::make_tuple (eta1, eta2)), theta_0,
163- stan::math::test::squared_kernel_functor{},
164- std::forward_as_tuple (
165- x, std::make_tuple (alpha_rho (0 ), alpha_rho (1 ))),
166- tolerance, max_num_steps, hessian_block_size, solver_num,
167- max_steps_line_search, nullptr );
168- };
169- auto test1 = 1.0 ;
170- auto test2 = 1.0 ;
171- stan::test::expect_ad<true >(tols, f_ll, phi_dbl, test1, test2);
172- },
173- theta_0);
174- }
175-
176- struct poisson_log_likelihood_array_tuple {
177- template <typename Theta, typename Eta>
178- auto operator ()(const Theta& theta, const std::vector<int >& delta_int,
179- Eta&& eta, std::ostream* pstream) const {
180- return stan::math::poisson_log_lpmf (delta_int, theta) + std::get<0 >(eta[0 ])
181- + std::get<1 >(eta[0 ]);
182- }
183- };
184-
185- TEST (laplace, poisson_log_phi_dim_2_array_tuple) {
186- using stan::math::laplace_marginal;
187- using stan::math::laplace_marginal_tol;
188- using stan::math::to_vector;
189- using stan::math::value_of;
190- using stan::math::var;
191- // logger->current_test_name_ = "poisson_log_phi_dim_2";
192- int dim_phi = 2 ;
193- Eigen::Matrix<double , Eigen::Dynamic, 1 > phi_dbl (dim_phi);
194- phi_dbl << 1.6 , 0.45 ;
195-
196- int dim_theta = 2 ;
197- Eigen::VectorXd theta_0 (dim_theta);
198- theta_0 << 0 , 0 ;
199-
200- int dim_x = 2 ;
201- std::vector<Eigen::VectorXd> x (dim_theta);
202- Eigen::VectorXd x_0{{0.05100797 , 0.16086164 }};
203- Eigen::VectorXd x_1{{-0.59823393 , 0.98701425 }};
204- x[0 ] = x_0;
205- x[1 ] = x_1;
206-
207- Eigen::VectorXd y_dummy;
208-
209- std::vector<int > n_samples = {1 , 1 };
210- std::vector<int > sums = {1 , 0 };
211-
212- constexpr double tolerance = 1e-12 ;
213- constexpr int max_num_steps = 100 ;
214- using stan::is_var_v;
215- using stan::scalar_type_t ;
216- using stan::math::test::laplace_issue;
217- constexpr std::array known_issues{laplace_issue{0 , 0 , 0 }};
218- stan::test::ad_tolerances tols;
219- tols.gradient_grad_ = 1e-1 ;
220- stan::math::test::run_solver_grid (
221- [&](int solver_num, int hessian_block_size, int max_steps_line_search,
222- auto && theta_0) {
223- auto f_ll = [&](auto && alpha_rho, auto && eta1, auto && eta2) {
224- std::vector<std::tuple<std::decay_t <decltype (eta1)>,
225- std::decay_t <decltype (eta2)>>>
226- eta_tuple;
227- eta_tuple.push_back (std::make_tuple (eta1, eta2));
228- using alpha_scalar = stan::scalar_type_t <decltype (alpha_rho)>;
229- std::vector<std::tuple<alpha_scalar, alpha_scalar>> alpha_tuple;
230- alpha_tuple.push_back (std::make_tuple (alpha_rho (0 ), alpha_rho (1 )));
231- return laplace_marginal_tol<false >(
232- poisson_log_likelihood_array_tuple{},
233- std::forward_as_tuple (sums, eta_tuple), theta_0,
234- stan::math::test::squared_kernel_functor{},
235- std::forward_as_tuple (x, alpha_tuple), tolerance, max_num_steps,
236- hessian_block_size, solver_num, max_steps_line_search, nullptr );
237- };
238- auto test1 = 1.0 ;
239- auto test2 = 1.0 ;
240- stan::test::expect_ad<true >(tols, f_ll, phi_dbl, test1, test2);
241- },
242- theta_0);
243- }
244-
24523TEST (laplace, poisson_log_phi_dim_2) {
24624 using stan::math::laplace_marginal;
24725 using stan::math::laplace_marginal_tol;
0 commit comments