1 #ifndef STAN_MATH_PRIM_SCAL_PROB_BETA_PROPORTION_LCCDF_HPP 2 #define STAN_MATH_PRIM_SCAL_PROB_BETA_PROPORTION_LCCDF_HPP 41 template <
typename T_y,
typename T_loc,
typename T_prec>
43 const T_y& y,
const T_loc& mu,
const T_prec& kappa) {
47 static const char*
function =
"beta_proportion_lccdf";
52 T_partials_return ccdf_log(0.0);
61 mu,
"Precision parameter", kappa);
76 digamma_mukappa(
max_size(mu, kappa));
79 digamma_kappa_mukappa(
max_size(mu, kappa));
82 digamma_kappa(
length(kappa));
85 for (
size_t i = 0; i <
max_size(mu, kappa); i++) {
86 const T_partials_return mukappa_dbl
88 const T_partials_return kappa_mukappa_dbl
89 =
value_of(kappa_vec[i]) - mukappa_dbl;
91 digamma_mukappa[i] =
digamma(mukappa_dbl);
92 digamma_kappa_mukappa[i] =
digamma(kappa_mukappa_dbl);
95 for (
size_t i = 0; i <
length(kappa); i++) {
100 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 mu_dbl =
value_of(mu_vec[n]);
103 const T_partials_return kappa_dbl =
value_of(kappa_vec[n]);
104 const T_partials_return mukappa_dbl = mu_dbl * kappa_dbl;
105 const T_partials_return kappa_mukappa_dbl = kappa_dbl - mukappa_dbl;
106 const T_partials_return betafunc_dbl =
beta(mukappa_dbl, kappa_mukappa_dbl);
107 const T_partials_return Pn
108 = 1 -
inc_beta(mukappa_dbl, kappa_mukappa_dbl, y_dbl);
113 ops_partials.
edge1_.partials_[n] -=
pow(1 - y_dbl, kappa_mukappa_dbl - 1)
114 *
pow(y_dbl, mukappa_dbl - 1)
117 T_partials_return g1 = 0;
118 T_partials_return g2 = 0;
122 digamma_mukappa[n], digamma_kappa_mukappa[n],
123 digamma_kappa[n], betafunc_dbl);
126 ops_partials.
edge2_.partials_[n] -= kappa_dbl * (g1 - g2) / Pn;
128 ops_partials.
edge3_.partials_[n]
129 -= (g1 * mu_dbl + g2 * (1 - mu_dbl)) / Pn;
131 return ops_partials.
build(ccdf_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.
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.
return_type< T_y, T_loc, T_prec >::type beta_proportion_lccdf(const T_y &y, const T_loc &mu, const T_prec &kappa)
Returns the beta log complementary cumulative distribution function for specified probability...
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)
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_positive(const char *function, const char *name, const T_y &y)
Check if y is positive.
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.