-
-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve numerical stability of binomial_logit, add tests
- Loading branch information
Showing
2 changed files
with
31 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#include <stan/math/mix.hpp> | ||
#include <test/unit/math/test_ad.hpp> | ||
|
||
TEST(mathMixScalFun, binomial_logit_lpmf) { | ||
auto f = [](const auto n, const auto N) { | ||
return [=](const auto& alpha) { | ||
return stan::math::binomial_logit_lpmf(n, N, alpha); | ||
}; | ||
}; | ||
|
||
Eigen::VectorXd alpha = Eigen::VectorXd::Random(3); | ||
std::vector<int> n_arr{1, 4, 5}; | ||
std::vector<int> N_arr{10, 45, 25}; | ||
|
||
stan::test::expect_ad(f(5, 25), 2.11); | ||
stan::test::expect_ad(f(5, 25), alpha); | ||
stan::test::expect_ad(f(n_arr, 25), alpha); | ||
stan::test::expect_ad(f(n_arr, N_arr), alpha); | ||
stan::test::expect_ad(f(n_arr, 10), 2.11); | ||
stan::test::expect_ad(f(n_arr, N_arr), 2.11); | ||
stan::test::expect_ad(f(5, N_arr), 2.11); | ||
} |