diff --git a/test/prob/beta_neg_binomial/beta_neg_binomial_ccdf_log_test.hpp b/test/prob/beta_neg_binomial/beta_neg_binomial_ccdf_log_test.hpp new file mode 100644 index 00000000000..4871ca77eeb --- /dev/null +++ b/test/prob/beta_neg_binomial/beta_neg_binomial_ccdf_log_test.hpp @@ -0,0 +1,96 @@ +// Arguments: Ints, Doubles, Doubles, Doubles +#include +#include +#include + +using stan::math::var; +using std::numeric_limits; +using std::vector; + +class AgradCcdfLogBetaNegBinomial : public AgradCcdfLogTest { + public: + void valid_values(vector>& parameters, + vector& ccdf_log) { + vector param(4); + + param[0] = 0; // n + param[1] = 1.0; // r + param[2] = 5.0; // alpha + param[3] = 1.0; // beta + parameters.push_back(param); + ccdf_log.push_back(std::log(1.0 - 0.833333333333333)); // expected ccdf_log + } + + void invalid_values(vector& index, vector& value) { + // n + + // r + index.push_back(1U); + value.push_back(0.0); + + index.push_back(1U); + value.push_back(-1.0); + + index.push_back(1U); + value.push_back(std::numeric_limits::infinity()); + + // alpha + index.push_back(2U); + value.push_back(0.0); + + index.push_back(2U); + value.push_back(-1.0); + + index.push_back(2U); + value.push_back(std::numeric_limits::infinity()); + + // beta + index.push_back(3U); + value.push_back(0.0); + + index.push_back(3U); + value.push_back(-1.0); + + index.push_back(3U); + value.push_back(std::numeric_limits::infinity()); + } + + // BOUND INCLUDED IN ORDER FOR TEST TO PASS WITH CURRENT FRAMEWORK + bool has_lower_bound() { return false; } + + bool has_upper_bound() { return false; } + + template + stan::return_type_t ccdf_log(const T_n& n, + const T_r& r, + const T_size1& alpha, + const T_size2& beta, + const T4&, const T5&) { + return stan::math::beta_neg_binomial_lccdf(n, r, alpha, beta); + } + + template + stan::return_type_t ccdf_log_function( + const T_n& n, const T_r& r, const T_size1& alpha, const T_size2& beta, + const T4&, const T5&) { + using stan::math::lbeta; + using stan::math::lgamma; + using stan::math::log1m; + using stan::math::log_sum_exp; + using std::vector; + + vector> lpmf_values; + + for (int i = 0; i <= n; i++) { + auto lpmf = lbeta(i + r, alpha + beta) - lbeta(r, alpha) + + lgamma(i + beta) - lgamma(i + 1) - lgamma(beta); + lpmf_values.push_back(lpmf); + } + + auto log_cdf = log_sum_exp(lpmf_values); + + return log1m(exp(log_cdf)); + } +};