1 #ifndef STAN_MATH_PRIM_SCAL_PROB_BETA_CDF_HPP 2 #define STAN_MATH_PRIM_SCAL_PROB_BETA_CDF_HPP 34 template <
typename T_y,
typename T_scale_succ,
typename T_scale_fail>
36 const T_y& y,
const T_scale_succ& alpha,
const T_scale_fail&
beta) {
44 static const char*
function =
"beta_cdf";
46 T_partials_return P(1.0);
52 "First shape parameter", alpha,
53 "Second shape parameter", beta);
69 return ops_partials.
build(0.0);
73 T_partials_return, T_scale_succ, T_scale_fail>
74 digamma_alpha_vec(
max_size(alpha, beta));
77 T_partials_return, T_scale_succ, T_scale_fail>
78 digamma_beta_vec(
max_size(alpha, beta));
81 T_partials_return, T_scale_succ, T_scale_fail>
82 digamma_sum_vec(
max_size(alpha, beta));
85 for (
size_t n = 0; n < N; n++) {
86 const T_partials_return alpha_dbl =
value_of(alpha_vec[n]);
87 const T_partials_return beta_dbl =
value_of(beta_vec[n]);
89 digamma_alpha_vec[n] =
digamma(alpha_dbl);
90 digamma_beta_vec[n] =
digamma(beta_dbl);
91 digamma_sum_vec[n] =
digamma(alpha_dbl + beta_dbl);
95 for (
size_t n = 0; n < N; n++) {
101 const T_partials_return y_dbl =
value_of(y_vec[n]);
102 const T_partials_return alpha_dbl =
value_of(alpha_vec[n]);
103 const T_partials_return beta_dbl =
value_of(beta_vec[n]);
105 const T_partials_return Pn =
inc_beta(alpha_dbl, beta_dbl, y_dbl);
110 ops_partials.
edge1_.partials_[n]
114 ops_partials.
edge2_.partials_[n]
115 +=
inc_beta_dda(alpha_dbl, beta_dbl, y_dbl, digamma_alpha_vec[n],
119 ops_partials.
edge3_.partials_[n]
120 +=
inc_beta_ddb(alpha_dbl, beta_dbl, y_dbl, digamma_beta_vec[n],
127 ops_partials.
edge1_.partials_[n] *= P;
131 ops_partials.
edge2_.partials_[n] *= P;
135 ops_partials.
edge3_.partials_[n] *= P;
138 return ops_partials.
build(P);
void check_less_or_equal(const char *function, const char *name, const T_y &y, const T_high &high)
Check if y is less or equal to high.
boost::math::tools::promote_args< double, typename partials_type< typename scalar_type< T >::type >::type, typename partials_return_type< T_pack... >::type >::type type
T value_of(const fvar< T > &v)
Return the value of the specified variable.
T inc_beta_dda(T a, T b, T z, T digamma_a, T digamma_ab)
Returns the partial derivative of the regularized incomplete beta function, I_{z}(a, b) with respect to a.
Extends std::true_type when instantiated with zero or more template parameters, all of which extend t...
scalar_seq_view provides a uniform sequence-like wrapper around either a scalar or a sequence of scal...
This template builds partial derivatives with respect to a set of operands.
size_t length(const std::vector< T > &x)
Returns the length of the provided std::vector.
bool size_zero(T &x)
Returns 1 if input is of length 0, returns 0 otherwise.
T inc_beta_ddb(T a, T b, T z, T digamma_b, T digamma_ab)
Returns the partial derivative of the regularized incomplete beta function, I_{z}(a, b) with respect to b.
T inc_beta_ddz(T a, T b, T z)
Returns the partial derivative of the regularized incomplete beta function, I_{z}(a, b) with respect to z.
void check_nonnegative(const char *function, const char *name, const T_y &y)
Check if y is non-negative.
fvar< T > inc_beta(const fvar< T > &a, const fvar< T > &b, const fvar< T > &x)
fvar< T > beta(const fvar< T > &x1, const fvar< T > &x2)
Return fvar with the beta function applied to the specified arguments and its gradient.
void check_positive_finite(const char *function, const char *name, const T_y &y)
Check if y is positive and finite.
boost::math::tools::promote_args< double, typename scalar_type< T >::type, typename return_type< Types_pack... >::type >::type type
void check_not_nan(const char *function, const char *name, const T_y &y)
Check if y is not NaN.
return_type< T_y, T_scale_succ, T_scale_fail >::type beta_cdf(const T_y &y, const T_scale_succ &alpha, const T_scale_fail &beta)
Calculates the beta cumulative distribution function for the given variate and scale variables...
size_t max_size(const T1 &x1, const T2 &x2)
T_return_type build(double value)
Build the node to be stored on the autodiff graph.
VectorBuilder allocates type T1 values to be used as intermediate values.
internal::ops_partials_edge< double, Op2 > edge2_
void check_consistent_sizes(const char *function, const char *name1, const T1 &x1, const char *name2, const T2 &x2)
Check if the dimension of x1 is consistent with x2.
internal::ops_partials_edge< double, Op3 > edge3_
internal::ops_partials_edge< double, Op1 > edge1_
fvar< T > digamma(const fvar< T > &x)
Return the derivative of the log gamma function at the specified argument.