1#ifndef STAN_MATH_PRIM_PROB_BINOMIAL_CDF_HPP
2#define STAN_MATH_PRIM_PROB_BINOMIAL_CDF_HPP
35template <
typename T_n,
typename T_N,
typename T_prob>
37 const T_prob& theta) {
44 static constexpr const char* function =
"binomial_cdf";
46 "Population size parameter", N,
47 "Probability parameter", theta);
51 T_theta_ref theta_ref = theta;
61 T_partials_return P(1.0);
67 size_t max_size_seq_view =
max_size(n, N, theta);
72 if (n_vec.val(i) < 0) {
73 return ops_partials.build(0.0);
77 for (
size_t i = 0; i < max_size_seq_view; i++) {
78 const T_partials_return n_dbl = n_vec.val(i);
79 const T_partials_return N_dbl = N_vec.val(i);
87 const T_partials_return theta_dbl = theta_vec.val(i);
88 const T_partials_return Pi
89 =
inc_beta(N_dbl - n_dbl, n_dbl + 1, 1 - theta_dbl);
94 const T_partials_return denom =
beta(N_dbl - n_dbl, n_dbl + 1) * Pi;
95 partials<0>(ops_partials)[i] -=
pow(theta_dbl, n_dbl)
96 *
pow(1 - theta_dbl, N_dbl - n_dbl - 1)
103 partials<0>(ops_partials)[i] *= P;
107 return ops_partials.build(P);
scalar_seq_view provides a uniform sequence-like wrapper around either a scalar or a sequence of scal...
return_type_t< T_prob > 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,...
typename return_type< Ts... >::type return_type_t
Convenience type for the return type of the specified template parameters.
int64_t size(const T &m)
Returns the size (number of the elements) of a matrix_cl or var_value<matrix_cl<T>>.
void check_nonnegative(const char *function, const char *name, const T_y &y)
Check if y is non-negative.
bool size_zero(const T &x)
Returns 1 if input is of length 0, returns 0 otherwise.
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.
auto pow(const T1 &x1, const T2 &x2)
T value_of(const fvar< T > &v)
Return the value of the specified variable.
void check_consistent_sizes(const char *)
Trivial no input case, this function is a no-op.
fvar< T > inc_beta(const fvar< T > &a, const fvar< T > &b, const fvar< T > &x)
int64_t max_size(const T1 &x1, const Ts &... xs)
Calculate the size of the largest input.
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.
auto make_partials_propagator(Ops &&... ops)
Construct an partials_propagator.
typename ref_type_if< true, T >::type ref_type_t
typename partials_return_type< Args... >::type partials_return_t
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
Extends std::true_type when instantiated with zero or more template parameters, all of which extend t...