1 #ifndef STAN_MATH_PRIM_SCAL_PROB_BINOMIAL_LPMF_HPP 2 #define STAN_MATH_PRIM_SCAL_PROB_BINOMIAL_LPMF_HPP 35 template <
bool propto,
typename T_n,
typename T_N,
typename T_prob>
37 const T_prob& theta) {
41 static const char*
function =
"binomial_lpmf";
46 T_partials_return logp = 0;
50 check_bounded(
function,
"Probability parameter", theta, 0.0, 1.0);
52 "Population size parameter", N,
53 "Probability parameter", theta);
66 for (
size_t i = 0; i <
size; ++i)
71 for (
size_t i = 0; i <
length(theta); ++i)
74 for (
size_t i = 0; i <
size; ++i)
76 + (N_vec[i] - n_vec[i]) * log1m_theta[i];
79 T_partials_return temp1 = 0;
80 T_partials_return temp2 = 0;
81 for (
size_t i = 0; i <
size; ++i) {
83 temp2 += N_vec[i] - n_vec[i];
86 ops_partials.
edge1_.partials_[0]
88 - temp2 / (1.0 -
value_of(theta_vec[0]));
92 for (
size_t i = 0; i <
size; ++i)
93 ops_partials.
edge1_.partials_[i]
95 - (N_vec[i] - n_vec[i]) / (1.0 -
value_of(theta_vec[i]));
99 return ops_partials.
build(logp);
102 template <
typename T_n,
typename T_N,
typename T_prob>
105 const T_prob& theta) {
106 return binomial_lpmf<false>(n, N, theta);
void check_finite(const char *function, const char *name, const T_y &y)
Check if y is finite.
boost::math::tools::promote_args< double, typename partials_type< typename scalar_type< T >::type >::type, typename partials_return_type< T_pack... >::type >::type type
fvar< T > binomial_coefficient_log(const fvar< T > &x1, const fvar< T > &x2)
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...
return_type< T_prob >::type binomial_lpmf(const T_n &n, const T_N &N, const T_prob &theta)
Returns the log PMF for the binomial distribution evaluated at the specified success, population size, and chance of success.
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.
Template metaprogram to calculate whether a summand needs to be included in a proportional (log) prob...
void check_nonnegative(const char *function, const char *name, const T_y &y)
Check if y is non-negative.
boost::math::tools::promote_args< double, typename scalar_type< T >::type, typename return_type< Types_pack... >::type >::type type
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.
fvar< T > multiply_log(const fvar< T > &x1, const fvar< T > &x2)
VectorBuilder allocates type T1 values to be used as intermediate values.
int size(const std::vector< T > &x)
Return the size of the specified standard vector.
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.
fvar< T > log1m(const fvar< T > &x)
internal::ops_partials_edge< double, Op1 > edge1_