Skip to content

Commit

Permalink
Failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
martinmodrak committed Jan 16, 2020
1 parent 45dce15 commit cfad0f7
Show file tree
Hide file tree
Showing 3 changed files with 231 additions and 0 deletions.
29 changes: 29 additions & 0 deletions test/unit/math/prim/prob/neg_binomial_2_log_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,3 +207,32 @@ TEST(ProbNegBinomial2, log_matches_lpmf) {
(stan::math::neg_binomial_2_lpmf<double, double, double>(y, mu, phi)),
(stan::math::neg_binomial_2_log<double, double, double>(y, mu, phi)));
}

TEST(ProbDistributionsNegBinomial2Log,
neg_binomial_2_log_grid_test) {
std::vector<double> mu_log_to_test =
{-101,-27, -3, -1, -0.132, 0, 4, 10, 87 };
std::vector<double> phi_to_test = {2e-5,0.36,1, 2.3e5, 1.8e10, 6e16 };
std::vector<int> n_to_test = {0, 1, 10, 39, 101, 3048, 150054 };

// TODO(martinmdorak) Only weak tolerance for this quick fix
auto tolerance = [](double x) { return std::max(fabs(x * 1e-8), 1e-8); };

for(double mu_log : mu_log_to_test) {
for(double phi : phi_to_test) {
for(int n : n_to_test) {
double val_log = stan::math::neg_binomial_2_log_lpmf(n, mu_log, phi);
EXPECT_LE(val_log, 0) << "neg_binomial_2_log_lpmf yields " <<
val_log << " which si greater than 0 for n = " << n <<
", mu_log = " << mu_log << ", phi = " << phi << ".";
double val_orig =
stan::math::neg_binomial_2_lpmf(n, std::exp(mu_log), phi);
EXPECT_NEAR(val_log, val_orig, tolerance(val_orig)) <<
"neg_binomial_2_log_lpmf yields different result (" << val_log <<
") than neg_binomial_2_lpmf (" << val_orig << ") for n = " << n <<
", mu_log = " << mu_log << ", phi = " << phi << ".";
}
}
}

}
13 changes: 13 additions & 0 deletions test/unit/math/prim/prob/neg_binomial_2_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,19 @@ TEST(ProbDistributionsNegBinomial, extreme_values) {
}
}

TEST(ProbDistributionsNegBinomial2, vectorAroundCutoff) {
int y = 10;
double mu = 9.36;
std::vector<double> phi;
phi.push_back(1);
phi.push_back(1e15);
double vector_value = stan::math::neg_binomial_2_lpmf(y, mu, phi);
double scalar_value = stan::math::neg_binomial_2_lpmf(y, mu, phi[0])
+ stan::math::neg_binomial_2_lpmf(y, mu, phi[1]);

EXPECT_FLOAT_EQ(vector_value, scalar_value);
}

TEST(ProbDistributionsNegativeBinomial2Log, distributionCheck) {
check_counts_real_real(NegativeBinomial2LogTestRig());
}
Loading

0 comments on commit cfad0f7

Please sign in to comment.