1 #ifndef STAN_MATH_PRIM_SCAL_PROB_BINOMIAL_CDF_HPP 2 #define STAN_MATH_PRIM_SCAL_PROB_BINOMIAL_CDF_HPP 34 template <
typename T_n,
typename T_N,
typename T_prob>
36 const T_prob& theta) {
37 static const char*
function =
"binomial_cdf";
44 T_partials_return P(1.0);
48 check_bounded(
function,
"Probability parameter", theta, 0.0, 1.0);
50 "Population size parameter", N,
51 "Probability parameter", theta);
67 return ops_partials.
build(0.0);
70 for (
size_t i = 0; i <
size; i++) {
77 const T_partials_return n_dbl =
value_of(n_vec[i]);
78 const T_partials_return N_dbl =
value_of(N_vec[i]);
79 const T_partials_return theta_dbl =
value_of(theta_vec[i]);
80 const T_partials_return betafunc =
beta(N_dbl - n_dbl, n_dbl + 1);
81 const T_partials_return Pi
82 =
inc_beta(N_dbl - n_dbl, n_dbl + 1, 1 - theta_dbl);
87 ops_partials.
edge1_.partials_[i]
88 -=
pow(theta_dbl, n_dbl) *
pow(1 - theta_dbl, N_dbl - n_dbl - 1)
94 ops_partials.
edge1_.partials_[i] *= P;
97 return ops_partials.
build(P);
void check_finite(const char *function, const char *name, const T_y &y)
Check if y is finite.
return_type< T_prob >::type binomial_cdf(const T_n &n, const T_N &N, const T_prob &theta)
Returns the CDF for the binomial distribution evaluated at the specified success, population size...
boost::math::tools::promote_args< double, typename partials_type< typename scalar_type< T >::type >::type, typename partials_return_type< T_pack... >::type >::type type
void check_bounded(const char *function, const char *name, const T_y &y, const T_low &low, const T_high &high)
Check if the value is between the low and high values, inclusively.
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...
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.
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.
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)
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.
int size(const std::vector< T > &x)
Return the size of the specified standard vector.
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, Op1 > edge1_