1 #ifndef STAN_MATH_PRIM_SCAL_PROB_BETA_LCDF_HPP 2 #define STAN_MATH_PRIM_SCAL_PROB_BETA_LCDF_HPP 39 template <
typename T_y,
typename T_scale_succ,
typename T_scale_fail>
41 const T_y& y,
const T_scale_succ& alpha,
const T_scale_fail&
beta) {
49 static const char*
function =
"beta_lcdf";
51 T_partials_return cdf_log(0.0);
59 "First shape parameter", alpha,
60 "Second shape parameter", beta);
75 T_partials_return, T_scale_succ, T_scale_fail>
76 digamma_alpha_vec(
max_size(alpha, beta));
79 T_partials_return, T_scale_succ, T_scale_fail>
80 digamma_beta_vec(
max_size(alpha, beta));
83 T_partials_return, T_scale_succ, T_scale_fail>
84 digamma_sum_vec(
max_size(alpha, beta));
87 for (
size_t i = 0; i <
max_size(alpha, beta); i++) {
88 const T_partials_return alpha_dbl =
value_of(alpha_vec[i]);
89 const T_partials_return beta_dbl =
value_of(beta_vec[i]);
91 digamma_alpha_vec[i] =
digamma(alpha_dbl);
92 digamma_beta_vec[i] =
digamma(beta_dbl);
93 digamma_sum_vec[i] =
digamma(alpha_dbl + beta_dbl);
97 for (
size_t n = 0; n < N; n++) {
98 const T_partials_return y_dbl =
value_of(y_vec[n]);
99 const T_partials_return alpha_dbl =
value_of(alpha_vec[n]);
100 const T_partials_return beta_dbl =
value_of(beta_vec[n]);
101 const T_partials_return betafunc_dbl
103 const T_partials_return Pn =
inc_beta(alpha_dbl, beta_dbl, y_dbl);
108 ops_partials.
edge1_.partials_[n] +=
pow(1 - y_dbl, beta_dbl - 1)
109 *
pow(y_dbl, alpha_dbl - 1)
112 T_partials_return g1 = 0;
113 T_partials_return g2 = 0;
117 digamma_alpha_vec[n], digamma_beta_vec[n],
118 digamma_sum_vec[n], betafunc_dbl);
121 ops_partials.
edge2_.partials_[n] += g1 / Pn;
123 ops_partials.
edge3_.partials_[n] += g2 / Pn;
126 return ops_partials.
build(cdf_log);
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.
Extends std::true_type when instantiated with zero or more template parameters, all of which extend t...
fvar< T > log(const fvar< T > &x)
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.
bool size_zero(T &x)
Returns 1 if input is of length 0, returns 0 otherwise.
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.
void grad_reg_inc_beta(T &g1, T &g2, const T &a, const T &b, const T &z, const T &digammaA, const T &digammaB, const T &digammaSum, const T &betaAB)
Computes the gradients of the regularized incomplete beta function.
boost::math::tools::promote_args< double, typename scalar_type< T >::type, typename return_type< Types_pack... >::type >::type type
fvar< T > exp(const fvar< T > &x)
void check_not_nan(const char *function, const char *name, const T_y &y)
Check if y is not NaN.
size_t max_size(const T1 &x1, const T2 &x2)
return_type< T_y, T_scale_succ, T_scale_fail >::type beta_lcdf(const T_y &y, const T_scale_succ &alpha, const T_scale_fail &beta)
Returns the beta log cumulative distribution function for the given probability, success, and failure parameters.
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_
fvar< T > pow(const fvar< T > &x1, const fvar< T > &x2)
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.