1#ifndef STAN_MATH_PRIM_PROB_BINOMIAL_LCDF_HPP
2#define STAN_MATH_PRIM_PROB_BINOMIAL_LCDF_HPP
37template <
typename T_n,
typename T_N,
typename T_prob>
39 const T_prob& theta) {
47 static constexpr const char* function =
"binomial_lcdf";
49 "Population size parameter", N,
50 "Probability parameter", theta);
54 T_theta_ref theta_ref = theta;
64 T_partials_return P(0.0);
70 size_t max_size_seq_view =
max_size(n, N, theta);
76 if (n_vec.val(i) < 0) {
81 for (
size_t i = 0; i < max_size_seq_view; i++) {
82 const T_partials_return n_dbl = n_vec.val(i);
83 const T_partials_return N_dbl = N_vec.val(i);
91 const T_partials_return theta_dbl = theta_vec.val(i);
92 const T_partials_return Pi
93 =
inc_beta(N_dbl - n_dbl, n_dbl + 1, 1 - theta_dbl);
98 const T_partials_return denom =
beta(N_dbl - n_dbl, n_dbl + 1) * Pi;
99 partials<0>(ops_partials)[i] -=
pow(theta_dbl, n_dbl)
100 *
pow(1 - theta_dbl, N_dbl - n_dbl - 1)
104 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_lcdf(const T_n &n, const T_N &N, const T_prob &theta)
Returns the log CDF for the binomial distribution evaluated at the specified success,...
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.
fvar< T > log(const fvar< T > &x)
static constexpr double NEGATIVE_INFTY
Negative infinity.
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...