add beta_neg_binomial_cdf#3120
add beta_neg_binomial_cdf#3120lingium merged 3 commits intostan-dev:developfrom lingium:feature/issue-3119-beta-neg-binomial-cdf
Conversation
Jenkins Console Log Machine informationNo LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 20.04.3 LTS Release: 20.04 Codename: focalCPU: G++: Clang: |
SteveBronder
left a comment
There was a problem hiding this comment.
One big Q but everything else looks good
| 1.0); | ||
| auto C = lgamma(r_plus_n + 1.0) + lbeta(a_plus_r, b_plus_n + 1.0) | ||
| - lgamma(r_dbl) - lbeta(alpha_dbl, beta_dbl) - lgamma(n_dbl + 2.0); | ||
| auto ccdf = stan::math::exp(C) * F; |
There was a problem hiding this comment.
How is this for large values of C? Would it be better to do this calculation on the log scale and then exp the end result? i.e. stan::math::exp(C + log(F)). Or can F be <= 0?
There was a problem hiding this comment.
You're right, stan::math::exp(C + log(F)) is indeed a better way. Will change it.
| auto partial_lccdf = digamma(r_plus_n + 1.0) | ||
| + (digamma_r_alpha - digamma_n_r_alpha_beta) | ||
| + (dF[2] + dF[4]) / F - digamma(r_dbl); | ||
| partials<0>(ops_partials)[i] += partial_lccdf * chain_rule_term; |
There was a problem hiding this comment.
imo I think it's find to just have one line for this
There was a problem hiding this comment.
Same for the other partial accumulations
There was a problem hiding this comment.
Will move them in one line
Jenkins Console Log Machine informationNo LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 20.04.3 LTS Release: 20.04 Codename: focalCPU: G++: Clang: |
Summary
With this PR the cdf of beta negative binomial distribution are added.
See issue #3119
Expressions involved (almost the same as #3114 , just add the chain rule from log ccdf to cdf):
where$C(r,\alpha,\beta)$ is ccdf, we denote ${}_3F_2({1,r+y +1,\beta +y +1}; {y +2,r+\alpha +\beta +y +1};1)$ as ${}_3F_2(...)$
Then the partial derivatives w.r.t log ccdf:
where
By chain rule,
Therefore, the the partial derivatives w.r.t log cdf:
Then the function adjust for the formula for the derivative of a product since
cdf([a, a, a]) == cdf(a) * cdf(a) * cdf(a).Tests
Test is written follow the guide.
Side Effects
No.
Release notes
beta_neg_binomial_cdf is available if merged.
Checklist
Copyright holder: (fill in copyright holder information)
The copyright holder is typically you or your assignee, such as a university or company. By submitting this pull request, the copyright holder is agreeing to the license the submitted work under the following licenses:
- Code: BSD 3-clause (https://opensource.org/licenses/BSD-3-Clause)
- Documentation: CC-BY 4.0 (https://creativecommons.org/licenses/by/4.0/)
the basic tests are passing
./runTests.py test/unit)make test-headers)make test-math-dependencies)make doxygen)make cpplint)the code is written in idiomatic C++ and changes are documented in the doxygen
the new changes are tested