Skip to content

Commit 8b8057a

Browse files
authored
Merge pull request #3159 from stan-dev/remove-grad_inc_beta
Fold grad_inc_beta into grad_reg_inc_beta
2 parents 0f1ad25 + 96b8a66 commit 8b8057a

File tree

7 files changed

+23
-171
lines changed

7 files changed

+23
-171
lines changed

stan/math/fwd/fun.hpp

-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
#include <stan/math/fwd/fun/fmod.hpp>
4141
#include <stan/math/fwd/fun/gamma_p.hpp>
4242
#include <stan/math/fwd/fun/gamma_q.hpp>
43-
#include <stan/math/fwd/fun/grad_inc_beta.hpp>
4443
#include <stan/math/fwd/fun/hypergeometric_1F0.hpp>
4544
#include <stan/math/fwd/fun/hypergeometric_2F1.hpp>
4645
#include <stan/math/fwd/fun/hypergeometric_pFq.hpp>

stan/math/fwd/fun/grad_inc_beta.hpp

-57
This file was deleted.

stan/math/prim/fun.hpp

-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@
116116
#include <stan/math/prim/fun/gp_periodic_cov.hpp>
117117
#include <stan/math/prim/fun/grad_2F1.hpp>
118118
#include <stan/math/prim/fun/grad_F32.hpp>
119-
#include <stan/math/prim/fun/grad_inc_beta.hpp>
120119
#include <stan/math/prim/fun/grad_pFq.hpp>
121120
#include <stan/math/prim/fun/grad_reg_inc_beta.hpp>
122121
#include <stan/math/prim/fun/grad_reg_inc_gamma.hpp>

stan/math/prim/fun/grad_inc_beta.hpp

-45
This file was deleted.

stan/math/prim/fun/grad_reg_inc_beta.hpp

+23-8
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
#define STAN_MATH_PRIM_FUN_GRAD_REG_INC_BETA_HPP
33

44
#include <stan/math/prim/meta.hpp>
5-
#include <stan/math/prim/fun/beta.hpp>
6-
#include <stan/math/prim/fun/grad_inc_beta.hpp>
75
#include <stan/math/prim/fun/inc_beta.hpp>
6+
#include <stan/math/prim/fun/grad_2F1.hpp>
87
#include <cmath>
98

109
namespace stan {
@@ -16,6 +15,9 @@ namespace math {
1615
* <code>ibeta(a, b, z)</code>, with respect to the arguments
1716
* <code>a</code> and <code>b</code>.
1817
*
18+
* Uses the equivalence to a hypergeometric function. See
19+
* http://dlmf.nist.gov/8.17#ii
20+
*
1921
* @tparam T type of arguments
2022
* @param[out] g1 partial derivative of <code>ibeta(a, b, z)</code>
2123
* with respect to <code>a</code>
@@ -34,12 +36,25 @@ void grad_reg_inc_beta(T& g1, T& g2, const T& a, const T& b, const T& z,
3436
const T& digammaA, const T& digammaB,
3537
const T& digammaSum, const T& betaAB) {
3638
using std::exp;
37-
T dBda = 0;
38-
T dBdb = 0;
39-
grad_inc_beta(dBda, dBdb, a, b, z);
40-
T b1 = beta(a, b) * inc_beta(a, b, z);
41-
g1 = (dBda - b1 * (digammaA - digammaSum)) / betaAB;
42-
g2 = (dBdb - b1 * (digammaB - digammaSum)) / betaAB;
39+
40+
T c1 = log(z);
41+
T c2 = log1m(z);
42+
T c3 = betaAB * inc_beta(a, b, z);
43+
T C = exp(a * c1 + b * c2) / a;
44+
T dF1 = 0;
45+
T dF2 = 0;
46+
T dF3 = 0;
47+
T dFz = 0;
48+
if (value_of_rec(C)) {
49+
std::forward_as_tuple(dF1, dF2, dF3, dFz)
50+
= grad_2F1<true>(a + b, 1.0, a + 1, z);
51+
}
52+
53+
T dBda = (c1 - 1.0 / a) * c3 + C * (dF1 + dF3);
54+
T dBdb = c2 * c3 + C * dF1;
55+
56+
g1 = (dBda - c3 * (digammaA - digammaSum)) / betaAB;
57+
g2 = (dBdb - c3 * (digammaB - digammaSum)) / betaAB;
4358
}
4459

4560
} // namespace math

stan/math/rev/fun.hpp

-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@
7070
#include <stan/math/rev/fun/generalized_inverse.hpp>
7171
#include <stan/math/rev/fun/gp_periodic_cov.hpp>
7272
#include <stan/math/rev/fun/grad.hpp>
73-
#include <stan/math/rev/fun/grad_inc_beta.hpp>
7473
#include <stan/math/rev/fun/hypergeometric_1F0.hpp>
7574
#include <stan/math/rev/fun/hypergeometric_2F1.hpp>
7675
#include <stan/math/rev/fun/hypergeometric_pFq.hpp>

stan/math/rev/fun/grad_inc_beta.hpp

-58
This file was deleted.

0 commit comments

Comments
 (0)